Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HTML attributes actionable #91

Closed
4 tasks done
Tracked by #120
Witiko opened this issue Aug 8, 2021 · 5 comments
Closed
4 tasks done
Tracked by #120

Make HTML attributes actionable #91

Witiko opened this issue Aug 8, 2021 · 5 comments
Assignees
Labels
feature request help wanted lua Related to the Lua interface and implementation plaintex Related to the plain TeX interface and implementation tug 2021 Related to the TUG 2021 conference
Milestone

Comments

@Witiko
Copy link
Owner

Witiko commented Aug 8, 2021

Since version 2.7.0, the Markdown package has supported the headerAttributes Lua option, which makes the Lua parser recognize HTML attributes on headings as a way of typesetting only small parts of markdown documents via the slice Lua option. However, the HTML attributes are currently not actionable, which means that users can't react to them from TeX.

The Markdown package has always supported the hybrid Lua option, which allows users to use LaTeX commands such as \label and \ref inside markdown:

I conclude in Section~\ref{sec:conclusion}.

Conclusion
==========
\label{sec:conclusion}
In this paper, we have discovered that most
grandmas would rather eat dinner with their
grandchildren than get eaten. Begone, wolf!

If the HTML element identifiers were actionable, we could rewrite the above code without the hybrid mode and all its shortcomings. Additionally, if HTML class names were actionable, we could apply setup snippets without switching between markdown and LaTeX:

I conclude in Section <#conclusion>.

Conclusion {#conclusion .some-snippet}
==========
In this paper, we have discovered that most
grandmas would rather eat dinner with their
grandchildren than get eaten. Begone, wolf!

Here are the current TODOs:

  • Produce headerAttributeContextBegin and headerAttributeContextEnd renderers when the headerAttributes Lua option is enabled. The renderers should parenthesize sections. The renderer prototypes should expand to \relax.
  • Produce attribute renderer when the headerAttributes Lua option is enabled. The renderer prototype should expand to \relax in plain TeX and to \label{#1} in LaTeX for ids. Attributes should be applied with deterministic ordering to mitigate the fact that CSS classes are commutative, so the order in which attributes are typed should not matter, but LaTeX code is not commutative, so the order of attribute invocation does matter.
  • Add Lua option relativeLinks that enables the use of relative URLs in autolinks. In LaTeX, the link renderer prototype should expand to \ref{#3'} for relative URL autolinks that only consist of a URL fragment and to \hyperref[#3']{#1} for labeled links that only consist of a URL fragment, where #3' denotes #3 without the leading character of the fragment. Document this addition at Stack Exchange.
  • Ping @drehak and mention the jgm/pandoc issue when the renderers are final, so that support for Pandoc's element attributes can be added.

Future development should add syntax extensions such as Pandoc's link_attributes, fenced_divs, bracketed_spans, inline_code_attributes, fenced_code_attributes for specifying HTML attributes on elements other than headings.

@Witiko Witiko added feature request help wanted lua Related to the Lua interface and implementation plaintex Related to the plain TeX interface and implementation tug 2021 Related to the TUG 2021 conference labels Aug 8, 2021
@Witiko Witiko added this to the 2.11.0 milestone Aug 8, 2021
@Witiko Witiko modified the milestones: 2.11.0, 2.12.0 Oct 1, 2021
@Witiko Witiko modified the milestones: 2.12.0, 2.13.0 Dec 7, 2021
@Witiko Witiko modified the milestones: 2.13.0, 2.14.0 Dec 30, 2021
@Witiko
Copy link
Owner Author

Witiko commented Jan 25, 2022 via email

@Witiko
Copy link
Owner Author

Witiko commented Jan 25, 2022 via email

Witiko added a commit that referenced this issue Feb 12, 2022
@Witiko
Copy link
Owner Author

Witiko commented Feb 14, 2022

As uncovered by e8078b0, we must take special care to ensure that we produce the same number of headerAttributeContextBegin and headerAttributeContextEnd renderers when we use the slice Lua option. Then, at the beginning of a slice, we should apply all attributes that are in effect at that point of the document. At the end of a slice, we should close all attribute contexts even if the attributes would otherwise continue to be in effect. At the end of a document, we should only close attribute contexts if the end of the document is part of the slice.

Witiko added a commit that referenced this issue Feb 22, 2022
@Witiko
Copy link
Owner Author

Witiko commented Feb 22, 2022

@writersglen Starting with cad83f6, header attributes are actionable. Headings with an identifier such as # Heading {#an-identifier} will cause \label{an-identifier} to be issued in LaTeX. This will allow us to reference sections from Markdown when the second part of this issue -- support for URL fragments -- has been implemented

@Witiko Witiko self-assigned this Feb 23, 2022
@Witiko
Copy link
Owner Author

Witiko commented Feb 23, 2022

@drehak This feature adds new renderers to the Markdown package:

  • \markdownRendererHeaderAttributeContextBegin – The beginning of a context surrounding a section with attributes
  • \markdownRendererHeaderAttributeContextEnd – The end of a context surrounding a section with attributes
  • \markdownRendererAttributeIdentifier – An HTML id="IDENTIFIER" attribute, which equals {#IDENTIFIER} in markdown
  • \markdownRendererAttributeClassName – An HTML class="... CLASS ..." attribute, which equals {.CLASS} in markdown
  • \markdownRendererAttributeKeyValue – An HTML attribute other than id and `class

To give an example, here is a markdown document:

I conclude in Section <#conclusion>.

Conclusion {#conclusion .some-snippet key=value}
==========
In this paper, we have discovered that most grandmas would rather eat dinner with their
grandchildren than get eaten. Begone, wolf!

Here is the output of the Markdown package when the headerAttributes and relativeReferences Lua options are enabled:

\markdownDocumentBegin
I conclude in Section
\markdownRendererLink{\markdownRendererHash conclusion}{\markdownRendererHash conclusion}{#conclusion}{}.%
\markdownRendererInterblockSeparator
\markdownRendererHeaderAttributeContextBegin
\markdownRendererAttributeIdentifier{conclusion}
\markdownRendererAttributeClassName{some-snippet}
\markdownRendererAttributeKeyValue{key}{value}
\markdownRendererHeadingOne{Conclusion}
In this paper, we have discovered that most grandmas would rather eat dinner with their
grandchildren than get eaten. Begone, wolf!
\markdownRendererHeaderAttributeContextEnd
\markdownDocumentEnd

With respect to #25, this means that we now have a mechanism to pass heading attributes from Pandoc to Markdown. No luck for elements other than headings yet, but the plan is only to add new types of attribute contexts, the attribute renderers themselves will be shared between different types of elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request help wanted lua Related to the Lua interface and implementation plaintex Related to the plain TeX interface and implementation tug 2021 Related to the TUG 2021 conference
Projects
None yet
Development

No branches or pull requests

1 participant