use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.
the class JekyllIncludeFileSample method commonMark.
static String commonMark(String markdown, Map<String, String> included) {
MutableDataHolder options = new MutableDataSet();
options.set(Parser.EXTENSIONS, Arrays.asList(AutolinkExtension.create(), JekyllTagExtension.create()));
// change soft break to hard break
options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(markdown);
// see if document has includes
if (document instanceof Document) {
Document doc = (Document) document;
if (doc.contains(JekyllTagExtension.TAG_LIST)) {
List<JekyllTag> tagList = JekyllTagExtension.TAG_LIST.getFrom(doc);
Map<String, String> includeHtmlMap = new HashMap<String, String>();
for (JekyllTag tag : tagList) {
String includeFile = tag.getParameters().toString();
if (tag.getTag().equals("include") && !includeFile.isEmpty() && !includeHtmlMap.containsKey(includeFile)) {
// see if it exists
if (included.containsKey(includeFile)) {
// have the file
String text = included.get(includeFile);
if (includeFile.endsWith(".md")) {
Node includeDoc = parser.parse(text);
String includeHtml = renderer.render(includeDoc);
includeHtmlMap.put(includeFile, includeHtml);
if (includeDoc instanceof Document) {
// copy any definition of reference elements from included file to our document
parser.transferReferences(doc, (Document) includeDoc);
}
} else {
includeHtmlMap.put(includeFile, text);
}
}
}
if (!includeHtmlMap.isEmpty()) {
doc.set(JekyllTagExtension.INCLUDED_HTML, includeHtmlMap);
}
}
}
}
final String html = renderer.render(document);
return html;
}
use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.
the class NodeRendererSample method commonMark.
static String commonMark(String markdown) {
MutableDataHolder options = new MutableDataSet();
options.set(Parser.EXTENSIONS, Arrays.asList(AutolinkExtension.create(), SampleExtension.create()));
// change soft break to hard break
options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
options.set(HtmlRenderer.ESCAPE_HTML, true);
Parser parser = Parser.builder(options).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
final String html = renderer.render(document);
return html;
}
use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.
the class PegdownOptions2 method main.
public static void main(String[] args) {
final MutableDataHolder OPTIONS = PegdownOptionsAdapter.flexmarkOptions(Extensions.ALL - (headerLinks ? 0 : Extensions.ANCHORLINKS) - (hardwrap ? 0 : Extensions.HARDWRAPS) + (allowHtml ? 0 : Extensions.SUPPRESS_ALL_HTML)).toMutable();
final Parser PARSER = Parser.builder(OPTIONS).build();
final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
String input = "[[test page]]" + "";
Node node = PARSER.parse(input);
System.out.println(RENDERER.render(node));
}
use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.
the class AttributeProviderSample method commonMark.
static String commonMark(String markdown) {
MutableDataHolder options = new MutableDataSet();
options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { AutolinkExtension.create(), SampleExtension.create() }));
// change soft break to hard break
options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
Parser parser = Parser.builder(options).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
final String html = renderer.render(document);
return html;
}
use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.
the class AttributeProviderSample2 method commonMark.
static String commonMark(String markdown) {
MutableDataHolder options = new MutableDataSet();
options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { SampleExtension.create() }));
// change soft break to hard break
options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
Parser parser = Parser.builder(options).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
final String html = renderer.render(document);
return html;
}
Aggregations