Search in sources :

Example 1 with Node

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);
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Example 2 with Node

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);
    }
}
Also used : Node(com.vladsch.flexmark.ast.Node)

Example 3 with Node

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;
}
Also used : JSPWikiLink(org.apache.wiki.markdown.nodes.JSPWikiLink) Node(com.vladsch.flexmark.ast.Node)

Example 4 with Node

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;
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Example 5 with Node

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);
        }
    }
}
Also used : DefinitionList(com.vladsch.flexmark.ext.definition.DefinitionList) DefinitionItem(com.vladsch.flexmark.ext.definition.DefinitionItem) Node(com.vladsch.flexmark.ast.Node)

Aggregations

Node (com.vladsch.flexmark.ast.Node)87 Parser (com.vladsch.flexmark.parser.Parser)29 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)21 Test (org.junit.Test)19 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)14 DataHolder (com.vladsch.flexmark.util.options.DataHolder)11 List (java.util.List)8 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)6 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)5 Text (com.vladsch.flexmark.ast.Text)3 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)3 Extension (com.vladsch.flexmark.Extension)2 Block (com.vladsch.flexmark.ast.Block)2 CustomNode (com.vladsch.flexmark.ast.CustomNode)2 Document (com.vladsch.flexmark.ast.Document)2 Heading (com.vladsch.flexmark.ast.Heading)2 DocxRenderer (com.vladsch.flexmark.docx.converter.internal.DocxRenderer)2 MacroClose (com.vladsch.flexmark.ext.xwiki.macros.MacroClose)2 AstCollectingVisitor (com.vladsch.flexmark.test.AstCollectingVisitor)2 Attributes (com.vladsch.flexmark.util.html.Attributes)2