use of com.vladsch.flexmark.ast.Node in project summer-mis by cn-cerc.
the class MarkdownDoc method mdToHtml.
/**
* @param inputText
* 传入的md字符串
* @return 返回经转化后的html
*/
public String mdToHtml(String inputText) {
MutableDataSet options = new MutableDataSet();
// 使用github的markdown扩展语法
options.setFrom(ParserEmulationProfile.GITHUB_DOC);
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(inputText);
return renderer.render(document);
}
use of com.vladsch.flexmark.ast.Node in project jspwiki by apache.
the class NodePostProcessorStateCommonOperations method addContent.
static void addContent(final NodeTracker state, final Node node, final Node content) {
final Node previous = node.getPrevious() != null ? node.getPrevious() : node.getNext();
if (previous != null) {
previous.insertAfter(content);
node.unlink();
state.nodeRemoved(node);
content.takeChildren(node);
state.nodeAddedWithChildren(content);
} else {
node.getParent().appendChild(content);
}
}
use of com.vladsch.flexmark.ast.Node in project jspwiki by apache.
the class JSPWikiLinkNodePostProcessor method replaceLinkWithJSPWikiLink.
JSPWikiLink replaceLinkWithJSPWikiLink(final NodeTracker state, final Node node) {
JSPWikiLink link = new JSPWikiLink((Link) node);
Node previous = node.getPrevious();
Node parent = node.getParent();
link.takeChildren(node);
node.unlink();
if (previous != null) {
previous.insertAfter(link);
} else {
parent.appendChild(link);
}
state.nodeRemoved(node);
state.nodeAddedWithChildren(link);
return link;
}
use of com.vladsch.flexmark.ast.Node in project commons by terran4j.
the class DocPageBuilder method md2Html.
public String md2Html(String content) throws Exception {
MutableDataSet options = new MutableDataSet();
options.setFrom(ParserEmulationProfile.GITHUB_DOC);
//
options.set(//
Parser.EXTENSIONS, Arrays.asList(TablesExtension.create()));
// References compatibility
options.set(Parser.REFERENCES_KEEP, KeepType.LAST);
// Set GFM table parsing options
//
options.set(TablesExtension.COLUMN_SPANS, false).set(TablesExtension.MIN_HEADER_ROWS, //
1).set(TablesExtension.MAX_HEADER_ROWS, //
1).set(TablesExtension.APPEND_MISSING_COLUMNS, //
true).set(TablesExtension.DISCARD_EXTRA_COLUMNS, //
true).set(TablesExtension.WITH_CAPTION, //
false).set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true);
// Setup List Options for GitHub profile which is kramdown for documents
options.setFrom(ParserEmulationProfile.GITHUB_DOC);
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
// You can re-use parser and renderer instances
Node document = parser.parse(content);
String html = renderer.render(document);
return html;
}
use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.
the class DefinitionListBlockPreProcessor method preProcess.
@Override
public void preProcess(ParserState state, Block block) {
Boolean blankLinesInAST = state.getProperties().get(BLANK_LINES_IN_AST);
if (block instanceof DefinitionList) {
// need to propagate loose/tight
final DefinitionList definitionList = (DefinitionList) block;
boolean isTight = definitionList.isTight();
if (options.autoLoose && isTight) {
for (Node child : definitionList.getChildren()) {
if (child instanceof DefinitionItem) {
if (((DefinitionItem) child).isLoose()) {
isTight = false;
if (!blankLinesInAST)
break;
}
if (blankLinesInAST) {
// transfer its trailing blank lines to uppermost level
child.moveTrailingBlankLines();
}
}
}
definitionList.setTight(isTight);
}
}
}
Aggregations