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

feat: Support mark (highlight) extension #67

Merged
merged 3 commits into from
Sep 27, 2023

Conversation

Omikhleia
Copy link
Contributor

The extension is disabled by default.
When enabled, ==marked== is expanded to a span with class "mark", for parity with upcoming Pandoc, and also Djot's {=marked=}.

Closes #65

The extension is disabled by default.
When enabled, `==marked==` is expanded to a span with class "mark",
for parity with upcoming Pandoc, and also Djot's `{=marked=}`.
@Witiko
Copy link
Collaborator

Witiko commented May 15, 2023

Thanks for the implementation, seems straightforward. Will be porting this to witiko/markdown in Witiko#303, so I am leaving this open in case I discover some edge cases that would best be fixed.

for parity with [...] Djot's {=marked=}.

Only ==marked== is supported, though? Do you have any ambition to implement Djot's syntax as well, or are you just name-dropping Djot? 😃

@Omikhleia
Copy link
Contributor Author

Omikhleia commented May 15, 2023

Only ==marked== is supported, though? Do you have any ambition to implement Djot's syntax as well, or are you just name-dropping Djot?

Sorry if it sounded name-dropping, it wasn't my intention 🐱
My Markdown for SILE collection of packages now supports both Markdown (based on the lunamark reader) and Djot (based on the djot.lua reader).
Since the SILE rendering part uses several common functions as an attempt to reuse as much code as possible (after all, they have a whole lot in common), that's just how I actually got aware of the == support recently added to Pandoc... I hadn't noticed it before. I refactored my code to add support simultaneously for both markup languages in my implementation (Omikhleia/markdown.sile#70)... and then proceeded to propose a "backport" as a PR here for the lunamark side of things. That's all ;-)

lunamark/reader/markdown.lua Outdated Show resolved Hide resolved
<<<
Some ==highlighted text==.
>>>
<p>Some <span class="mark">highlighted text</span>.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In HTML5, there is a <mark> element. The HTML5 writer should likely produce <mark> rather than <span class="mark">. No need to test that, but we should likely add a new function mark() to writers rather than reuse the span() function even if the output will still be <span class="mark"> in the HTML writer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time I checked, Pandoc just expands a span here, so I went for the simplest choice.
Of course we can possibly support outputting a <mark> in the HTML5 writer - either as suggested with a mark() function in writers, or possibly in the HTML5 writer itself, interpretating that span (avoiding yet another writer method for so small a thing).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My distro didn't have a recent enough Pandoc for me to check, but Pandoc tests suggest that Pandoc also produces the <mark> element. Regardless, it seems clear to me that we should produce semantic HTML5 markup like <mark> whenever possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not part of the Pandoc AST https://hackage.haskell.org/package/pandoc-types-1.23/docs/Text-Pandoc-Definition.html#t:Inline

And indeed ==mark== processed with -f markdown+mark -t json gives

{"pandoc-api-version":[1,23,1],"meta":{},"blocks":[{"t":"Para","c":[{"t":"Span","c":[["",["mark"],[]],[{"t":"Str","c":"mark"}]]}]}]}

If I correctly read the code, the Pandoc Markdown reader indeed uses a span here:
https://github.com/jgm/pandoc/blob/edbea270f5ed0cae23cfe977b9621045256e7dfc/src/Text/Pandoc/Readers/Markdown.hs#L1726

Wondering where it does the mapping then! But it might thus likely be somewhere in Writers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless, done in 96c05c8

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Witiko Witiko merged commit 55bfb1f into jgm:master Sep 27, 2023
2 checks passed
@Omikhleia Omikhleia deleted the feat-mark-extension branch February 26, 2024 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support hightlighting (Pandoc's new mark extension)
2 participants