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);
}
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;
}
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>");
}
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());
}
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();
}
Aggregations