com.vladsch.flexmark.ast.Text Java Examples

The following examples show how to use com.vladsch.flexmark.ast.Text. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TwitterNodePostProcessor.java    From MarkdownView with Apache License 2.0 6 votes vote down vote up
@Override
public void process(NodeTracker state, Node node) {
    if (node instanceof Link) {
        Node previous = node.getPrevious();

        if (previous instanceof Text) {
            final BasedSequence chars = previous.getChars();

            //Se o nó anterior termina com '#' e é seguido pelo Link
            if (chars.endsWith("#") && chars.isContinuedBy(node.getChars())) {
                //Remove o caractere '#' do nó anterior.
                previous.setChars(chars.subSequence(0, chars.length() - 1));
                Twitter videoLink = new Twitter((Link) node);
                videoLink.takeChildren(node);
                node.unlink();
                previous.insertAfter(videoLink);
                state.nodeRemoved(node);
                state.nodeAddedWithChildren(videoLink);
            }
        }
    }
}
 
Example #2
Source File: VideoLinkNodePostProcessor.java    From MarkdownView with Apache License 2.0 6 votes vote down vote up
@Override
public void process(NodeTracker state, Node node) {
    if (node instanceof Link) {
        Node previous = node.getPrevious();

        if (previous instanceof Text) {
            final BasedSequence chars = previous.getChars();

            //Se o nó anterior termina com '@' e é seguido pelo Link
            if (chars.endsWith("@") && chars.isContinuedBy(node.getChars())) {
                //Remove o caractere '@' do nó anterior.
                previous.setChars(chars.subSequence(0, chars.length() - 1));
                VideoLink videoLink = new VideoLink((Link) node);
                videoLink.takeChildren(node);
                node.unlink();
                previous.insertAfter(videoLink);
                state.nodeRemoved(node);
                state.nodeAddedWithChildren(videoLink);
            }
        }
    }
}
 
Example #3
Source File: SmartFormat.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Collects the text of a single paragraph.
 *
 * Replaces:
 *   - tabs with spaces
 *   - newlines with spaces (may occur in Code nodes)
 *   - soft line breaks with spaces
 *   - hard line breaks with special marker characters
 *   - spaces and tabs in special nodes, that should not formatted, with marker characters
 */
private void collectFormattableText(StringBuilder buf, Node node) {
	for (Node n = node.getFirstChild(); n != null; n = n.getNext()) {
		if (n instanceof Text) {
			buf.append(n.getChars().toString().replace('\t', ' ').replace('\n', ' '));
		} else if (n instanceof DelimitedNode) {
			// italic, bold and code
			buf.append(((DelimitedNode) n).getOpeningMarker());
			collectFormattableText(buf, n);
			buf.append(((DelimitedNode) n).getClosingMarker());
		} else if (n instanceof SoftLineBreak) {
			buf.append(' ');
		} else if (n instanceof HardLineBreak) {
			buf.append(' ').append(n.getChars().startsWith("\\")
				? HARD_LINE_BREAK_BACKSLASH : HARD_LINE_BREAK_SPACES).append(' ');
		} else {
			// other text that should be not wrapped or formatted
			buf.append(protectWhitespace(n.getChars().toString()));
		}
	}
}
 
Example #4
Source File: MarkDownDocumentInterpreter.java    From camunda-bpm-swagger with Apache License 2.0 4 votes vote down vote up
void nodeToString(final Node node, final StringBuffer sb, final Boolean ignoreHtmlBlocks) {
  if (node != null) {
    switch (node.getClass().getSimpleName()) {
    case "Text":
      sb.append(node.getChars());
      break;
    case "Code":
      sb.append("`");
      nodeToString(node.getFirstChildAny(Text.class), sb, ignoreHtmlBlocks);
      sb.append("`");
      break;
    case "Paragraph":
      for (final Node childNode : node.getChildren()) {
        nodeToString(childNode, sb, ignoreHtmlBlocks);
      }
      break;
    case "SoftLineBreak":
      sb.append(" ");
      break;
    case "HtmlBlock":
      if (!ignoreHtmlBlocks) {
        sb.append(htmlInterpreter.getText((HtmlBlock) node));
        sb.append("\n");
      }
      break;
    case "LinkRef":
    case "Link":
      nodeToString(node.getFirstChildAny(Text.class), sb, ignoreHtmlBlocks);
      break;
    case "BulletList":
      sb.append(node.getChars().toString());
      break;
    case "StrongEmphasis":
    case "Emphasis":
      nodeToString(node.getFirstChildAny(Text.class), sb, ignoreHtmlBlocks);
      break;
    case "HtmlInline":
      if (node.getChars().toString().equals("<br/>") || node.getChars().toString().equals("</br>")) {
        sb.append("\n");
      }
      else {
        log.debug("unknown htmlInline element: (" + node.getChars().toString() + ")");

      }
      break;
    default:
      log.debug("class " + node.getClass().getSimpleName() + " not known: (" + node.getChars().toString() + ")");
    }
  }
}