use of com.vladsch.flexmark.util.ast.Node in project zeppelin by apache.
the class FlexmarkParser method render.
@Override
public String render(String markdownText) {
Node document = parser.parse(markdownText);
String html = renderer.render(document);
return wrapWithMarkdownClassDiv(html);
}
use of com.vladsch.flexmark.util.ast.Node in project gerrit by GerritCodeReview.
the class MarkdownFormatter method markdownToDocHtml.
public byte[] markdownToDocHtml(String md, String charEnc) throws UnsupportedEncodingException {
Node root = parseMarkdown(md);
HtmlRenderer renderer = HtmlRenderer.builder(markDownOptions()).build();
String title = findTitle(root);
StringBuilder html = new StringBuilder();
html.append("<html>");
html.append("<head>");
if (!Strings.isNullOrEmpty(title)) {
html.append("<title>").append(title).append("</title>");
}
html.append("<style type=\"text/css\">\n");
if (css != null) {
html.append(css);
} else {
html.append(readCSS());
}
html.append("\n</style>");
html.append("</head>");
html.append("<body>\n");
html.append(renderer.render(root));
html.append("\n</body></html>");
return html.toString().getBytes(charEnc);
}
use of com.vladsch.flexmark.util.ast.Node in project gerrit by GerritCodeReview.
the class MarkdownFormatter method findTitle.
private String findTitle(Node root) {
if (root instanceof Heading) {
Heading h = (Heading) root;
if (h.getLevel() == 1 && h.hasChildren()) {
TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
return collectingVisitor.collectAndGetText(h);
}
}
if (root instanceof Block && root.hasChildren()) {
Node child = root.getFirstChild();
while (child != null) {
String title = findTitle(child);
if (title != null) {
return title;
}
child = child.getNext();
}
}
return null;
}
use of com.vladsch.flexmark.util.ast.Node in project gerrit by GerritCodeReview.
the class MarkdownFormatter method parseMarkdown.
private Node parseMarkdown(String md) {
Parser parser = Parser.builder(markDownOptions()).build();
Node document = parser.parse(md);
return document;
}
use of com.vladsch.flexmark.util.ast.Node in project zeppelin by apache.
the class UMLBlockQuoteParser method tryContinue.
@Override
public BlockContinue tryContinue(ParserState state) {
if (hadClose) {
return BlockContinue.none();
}
final int index = state.getIndex();
BasedSequence line = state.getLineWithEOL();
final Matcher matcher = YUML_BLOCK_END.matcher(line.subSequence(index));
if (!matcher.matches()) {
return BlockContinue.atIndex(index);
} else {
// if have open gitlab block quote last child then let them handle it
Node lastChild = block.getLastChild();
if (lastChild instanceof UMLBlockQuote) {
final BlockParser parser = state.getActiveBlockParser((Block) lastChild);
if (parser instanceof UMLBlockQuoteParser && !((UMLBlockQuoteParser) parser).hadClose) {
// let the child handle it
return BlockContinue.atIndex(index);
}
}
hadClose = true;
block.setClosingMarker(state.getLine().subSequence(index, index + 3));
block.setClosingTrailing(state.getLineWithEOL().subSequence(matcher.start(1), matcher.end(1)));
return BlockContinue.atIndex(state.getLineEndIndex());
}
}
Aggregations