vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.29k stars 272 forks source link

Parse div block syntax #327

Closed ghost closed 3 years ago

ghost commented 5 years ago

Pandoc now has a DIV syntax for content blocks. For example:

::: homepage
![logo](images/logo.svg){width=120px height=120px} \

::: content
# Title
## Subtitle

[Contact](mailto:person@domain.com)
:::

:::

Using the latest version of Pandoc, the above produces:

<div class="homepage">
<p><img src="images/logo.svg" alt="logo" width="120" height="120" /><br />
</p>
<div class="content">
<h1>Title</h1>
<h2>Subtitle</h2>
<p><a href="mailto:person@domain.com">Contact</a></p>
</div>
</div>

This would be great to see in FlexMark as well.

vsch commented 5 years ago

@DaveJarvis, I will add it to the to do list but at the moment no PanDoc specific profile or extensions are implemented so it may take a while to add this extension along with other PanDoc specific ones.

ghost commented 3 years ago

Should anybody need this functionality, attached are a few classes that may help.

Here's a short example usage:

final var extensions = new ArrayList<Extension>();
extensions.add( FencedDivExtension.create() );

final IParse parser = Parser.builder().extensions( extensions ).build();
final IRender renderer = HtmlRenderer.builder().extensions( extensions ).build();

This solution works for nested fenced div elements, although it may be suboptimal because the opening and closing div elements are written separately, without knowledge of each other. If a Markdown document is missing the closing ::: then the resulting HTML document will be missing a closing div.

If you have questions, you may be best off asking on StackOverflow.

XenoAmess commented 1 year ago

@DaveJarvis please add a pr...

ghost commented 1 year ago

@XenoAmess, a PR probably won't happen. If I were to make a flexmark extension at all, it'd be for parsing citations and cross-references, not for fenced DIVs. Here's the latest source code for fenced DIVs as is integrated into my text editor:

https://github.com/DaveJarvis/KeenWrite/tree/main/src/main/java/com/keenwrite/processors/markdown/extensions/fences