| 8 | 8 | import com.keenwrite.processors.markdown.extensions.r.RInlineExtension; |
| 9 | 9 | import com.vladsch.flexmark.ext.definition.DefinitionExtension; |
| 10 | | import com.vladsch.flexmark.ext.gfm.strikethrough.*; |
| 10 | import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension; |
| 11 | 11 | import com.vladsch.flexmark.ext.superscript.SuperscriptExtension; |
| 12 | 12 | import com.vladsch.flexmark.ext.tables.TablesExtension; |
| 13 | 13 | import com.vladsch.flexmark.html.HtmlRenderer; |
| 14 | 14 | import com.vladsch.flexmark.parser.Parser; |
| 15 | 15 | import com.vladsch.flexmark.util.ast.IParse; |
| 16 | 16 | import com.vladsch.flexmark.util.ast.IRender; |
| 17 | 17 | import com.vladsch.flexmark.util.ast.Node; |
| 18 | 18 | import com.vladsch.flexmark.util.data.MutableDataSet; |
| 19 | 19 | import com.vladsch.flexmark.util.misc.Extension; |
| 20 | import org.jsoup.Jsoup; |
| 21 | import org.jsoup.nodes.Document.OutputSettings.Syntax; |
| 20 | 22 | |
| 21 | 23 | import java.util.ArrayList; |
| ... |
| 79 | 81 | @Override |
| 80 | 82 | public String apply( final String markdown ) { |
| 81 | | return toHtml( parse( markdown ) ); |
| 83 | return toXhtml( toHtml( parse( markdown ) ) ); |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | /** |
| 85 | 87 | * Returns the AST in the form of a node for the given Markdown document. This |
| 86 | | * can be used, for example, to determine if a hyperlink exists inside of a |
| 88 | * can be used, for example, to determine if a hyperlink exists inside a |
| 87 | 89 | * paragraph. |
| 88 | 90 | * |
| ... |
| 102 | 104 | public String toHtml( final Node node ) { |
| 103 | 105 | return getRenderer().render( node ); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Ensures that subsequent processing will receive a well-formed document. |
| 110 | * That is, an XHTML document. |
| 111 | * |
| 112 | * @param html Document to transform (may contain unbalanced HTML tags). |
| 113 | * @return A well-formed (balanced) equivalent HTML document. |
| 114 | */ |
| 115 | private String toXhtml( final String html ) { |
| 116 | final var document = Jsoup.parse( html ); |
| 117 | document.outputSettings().syntax( Syntax.xml ); |
| 118 | return document.html(); |
| 104 | 119 | } |
| 105 | 120 | |