use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class HtmlBlockParser method closeBlock.
@Override
public void closeBlock(ParserState state) {
block.setContent(content);
content = null;
// split out inner comments
if (!(block instanceof HtmlCommentBlock) && parseInnerHtmlComments) {
// need to break it up into non-comments and comments
int lastIndex = 0;
BasedSequence chars = block.getContentChars();
if (chars.eolLength() > 0)
chars = chars.midSequence(0, -1);
// RegEx for HTML can go into an infinite loop, we do manual search to avoid this
// Matcher matcher = state.getParsing().HTML_COMMENT.matcher(chars);
// while (matcher.find()) {
// int index = matcher.start();
// if (lastIndex < index) {
// HtmlInnerBlock html = new HtmlInnerBlock(chars.subSequence(lastIndex, index));
// block.appendChild(html);
// }
//
// lastIndex = matcher.end();
// HtmlInnerBlockComment htmlComment = new HtmlInnerBlockComment(chars.subSequence(index, lastIndex));
// block.appendChild(htmlComment);
// }
int length = chars.length();
while (lastIndex < length) {
// find the opening HTML comment
int index = chars.indexOf(HTML_COMMENT_OPEN, lastIndex);
if (index < 0)
break;
// now lets find -->
int end = chars.indexOf(HTML_COMMENT_CLOSE, index + HTML_COMMENT_OPEN.length());
// if unterminated, ignore
if (end < 0)
break;
if (lastIndex < index) {
HtmlInnerBlock html = new HtmlInnerBlock(chars.subSequence(lastIndex, index));
block.appendChild(html);
}
lastIndex = end + HTML_COMMENT_CLOSE.length();
HtmlInnerBlockComment htmlComment = new HtmlInnerBlockComment(chars.subSequence(index, lastIndex));
block.appendChild(htmlComment);
}
if (lastIndex > 0) {
if (lastIndex < chars.length()) {
HtmlInnerBlock html = new HtmlInnerBlock(chars.subSequence(lastIndex, chars.length()));
block.appendChild(html);
}
}
}
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class TextCollectingVisitor method visit.
private void visit(HardLineBreak node) {
final BasedSequence chars = node.getChars();
out.append(chars.subSequence(chars.length() - 1, chars.length()));
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class FencedCodeBlock method getAstExtra.
@Override
public void getAstExtra(StringBuilder out) {
BasedSequence content = getContentChars();
int lines = getContentLines().size();
segmentSpanChars(out, openingMarker, "open");
segmentSpanChars(out, info, "info");
segmentSpan(out, content, "content");
out.append(" lines[").append(lines).append("]");
segmentSpanChars(out, closingMarker, "close");
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final Node node, final DocxRendererContext docx) {
BasedSequence chars = node.getChars();
MainDocumentPart mdp = docx.getDocxDocument();
if (node instanceof Block) {
docx.setBlockFormatProvider(new BlockFormatProviderBase<Node>(docx, docx.getDocxRendererOptions().LOOSE_PARAGRAPH_STYLE));
docx.createP();
docx.renderChildren(node);
} else {
docx.text(chars.unescape());
}
}
use of com.vladsch.flexmark.util.sequence.BasedSequence in project flexmark-java by vsch.
the class InlineParserImpl method parseHtmlInline.
/**
* Attempt to parse inline HTML.
*
* @return true if processed characters false otherwise
*/
@Override
public boolean parseHtmlInline() {
BasedSequence m = match(myParsing.HTML_TAG);
if (m != null) {
// separate HTML comment from herd
HtmlInlineBase node;
if (m.startsWith("<!--") && m.endsWith("-->")) {
node = new HtmlInlineComment(m);
} else {
node = new HtmlInline(m);
}
appendNode(node);
return true;
} else {
return false;
}
}
Aggregations