Search in sources :

Example 36 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class TextCollectingVisitorTest method test_strong_emphasis.

@Test
public void test_strong_emphasis() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("Test text **emphasis**");
    TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
    final String text = collectingVisitor.collectAndGetText(document);
    assertEquals("Test text emphasis", text);
}
Also used : Node(com.vladsch.flexmark.ast.Node) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 37 with Node

use of com.vladsch.flexmark.ast.Node in project jspwiki by apache.

the class MarkdownParser method parse.

/**
 * {@inheritDoc}
 */
@Override
public WikiDocument parse() throws IOException {
    Node document = parser.parseReader(m_in);
    MarkdownDocument md = new MarkdownDocument(m_context.getPage(), document);
    md.setContext(m_context);
    return md;
}
Also used : Node(com.vladsch.flexmark.ast.Node)

Example 38 with Node

use of com.vladsch.flexmark.ast.Node in project cytoscape-impl by cytoscape.

the class HelpGenerator method generateArgumentHelp.

private void generateArgumentHelp(String namespace, String command, MessageHandler resultsText) {
    String longDescription = availableCommands.getLongDescription(namespace, command);
    String message = "";
    // System.out.println("generateArgumentHelp");
    if (longDescription != null) {
        // Do we have an HTML string?
        if (longDescription.trim().startsWith("<html>") || longDescription.trim().startsWith("<HTML>")) {
            // Yes.  Strip off the "<html></html>" wrapper
            longDescription = longDescription.trim().substring(6);
            longDescription = longDescription.substring(0, longDescription.length() - 7);
        // System.out.println("longDescription(html) = "+longDescription);
        } else {
            // No, pass it through the markdown converter
            Parser parser = Parser.builder().build();
            Node document = parser.parse(longDescription);
            HtmlRenderer renderer = HtmlRenderer.builder().build();
            longDescription = renderer.render(document);
        // System.out.println("longDescription(markdown) = "+longDescription);
        }
        message += longDescription;
    }
    List<String> argList = availableCommands.getArguments(namespace, command);
    message += "<br/><br/><b>" + namespace + " " + command + "</b> arguments:";
    // resultsText.appendMessage(commandArgs);
    message += "<dl style='list-style-type:none;margin-top:0px;color:blue'>";
    for (String arg : argList) {
        message += "<dt>";
        if (availableCommands.getArgRequired(namespace, command, arg)) {
            message += "<b>" + arg + "</b>";
        } else {
            message += arg;
        }
        message += "=" + getTypeString(namespace, command, arg);
        message += ": ";
        message += "</dt>";
        message += "<dd>";
        message += normalizeArgDescription(availableCommands.getArgDescription(namespace, command, arg), availableCommands.getArgLongDescription(namespace, command, arg));
        message += "</dd>";
    }
    resultsText.appendMessage(message + "</dl>");
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser)

Example 39 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class StrikethroughTest method delimited.

@Test
public void delimited() {
    Node document = PARSER.parse("~~foo~~");
    Strikethrough strikethrough = (Strikethrough) document.getFirstChild().getFirstChild();
    assertEquals("~~", strikethrough.getOpeningMarker().toString());
    assertEquals("~~", strikethrough.getClosingMarker().toString());
}
Also used : Node(com.vladsch.flexmark.ast.Node) Test(org.junit.Test)

Example 40 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class TableBlockParser method parseInlines.

@Override
public void parseInlines(InlineParser inlineParser) {
    Node section = new TableHead();
    block.appendChild(section);
    List<TableCell.Alignment> alignments = parseAlignment(separatorLine);
    int rowNumber = 0;
    int separatorColumns = alignments.size();
    for (BasedSequence rowLine : block.getContentLines()) {
        if (rowNumber == separatorLineNumber) {
            section.setCharsFromContent();
            section = new TableSeparator();
            block.appendChild(section);
        } else if (rowNumber == separatorLineNumber + 1) {
            section.setCharsFromContent();
            section = new TableBody();
            block.appendChild(section);
        }
        List<BasedSequence> cells = split(rowLine);
        TableRow tableRow = new TableRow(rowLine.trimEOL());
        int rowCells = countCells(cells);
        int maxColumns = rowCells;
        if (bodyColumnsTruncatedToHead && maxColumns > separatorColumns)
            maxColumns = separatorColumns;
        if (rowNumber >= separatorLineNumber) {
            if (!bodyColumnsFilledToHead && rowCells < maxColumns)
                maxColumns = rowCells;
            else if (bodyColumnsFilledToHead && maxColumns < separatorColumns)
                maxColumns = separatorColumns;
        }
        int segmentOffset = 0;
        BasedSequence openingMarker = BasedSequence.NULL;
        for (int i = 0; i < maxColumns; i++) {
            BasedSequence cell = i < rowCells ? cells.get(i + segmentOffset) : BasedSequence.NULL;
            if (!isCell(cell)) {
                openingMarker = cell;
                segmentOffset++;
                cell = i < rowCells ? cells.get(i + segmentOffset) : BasedSequence.NULL;
            }
            TableCell.Alignment alignment = i < alignments.size() ? alignments.get(i) : null;
            TableCell tableCell = new TableCell();
            tableCell.setHeader(rowNumber < separatorLineNumber);
            tableCell.setAlignment(alignment);
            tableCell.setOpeningMarker(openingMarker);
            openingMarker = BasedSequence.NULL;
            // if the next one is not a cell then it is our closing marker
            if (i + segmentOffset + 1 < cells.size()) {
                BasedSequence closingMarker = cells.get(i + segmentOffset + 1);
                if (!isCell(closingMarker)) {
                    segmentOffset++;
                    tableCell.setClosingMarker(closingMarker);
                }
            }
            BasedSequence trimmed = cell.trim();
            tableCell.setText(trimmed);
            inlineParser.parse(trimmed, tableCell);
            tableCell.setCharsFromContent();
            tableRow.appendChild(tableCell);
        }
        tableRow.setCharsFromContent();
        section.appendChild(tableRow);
        rowNumber++;
    }
    if (section instanceof TableSeparator) {
        block.appendChild(new TableBody());
    }
    section.setCharsFromContent();
}
Also used : Node(com.vladsch.flexmark.ast.Node) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence)

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