use of org.tautua.markdownpapers.ast.Node in project ceylon by eclipse.
the class Markdown method getNext.
static Node getNext(Node node) {
Node parent = node.jjtGetParent();
int ii = getIndexInParent(node);
return ii < parent.jjtGetNumChildren() - 1 ? parent.jjtGetChild(ii + 1) : null;
}
use of org.tautua.markdownpapers.ast.Node in project ceylon by eclipse.
the class Markdown method extractBetween.
private static Document extractBetween(SectionsMarkdownVisitor v, Node parent, Header header1, Header header2) {
/*Node parent1 = header1 != null ? header1.jjtGetParent() : null;
Node parent2 = header2 != null ? header2.jjtGetParent() : null;
/*if (parent1 != null
&& parent2 != null
&& parent1 != parent2) {
throw new RuntimeException();
}* /
Node parent = parent1 != null ? parent1 : parent2;*/
Document doc = new Document(Parser.JJTDOCUMENT);
final int numChildren = parent.jjtGetNumChildren();
final int start = header1 != null ? Markdown.getIndexInParent(header1) + 1 : 0;
final int end = header2 != null ? Markdown.getIndexInParent(header2) - 1 : numChildren - 1;
for (int nodeIndex = start; nodeIndex <= end; nodeIndex++) {
Node child = parent.jjtGetChild(nodeIndex);
child.jjtSetParent(doc);
doc.jjtAddChild(child, nodeIndex - start);
}
// to each document
for (ResourceDefinition rd : v.resourceDefinitions) {
ResourceDefinition copy = copy(rd);
copy.jjtSetParent(doc);
doc.jjtAddChild(copy, doc.jjtGetNumChildren());
}
return doc;
}
use of org.tautua.markdownpapers.ast.Node in project ceylon by eclipse.
the class PlaintextMarkdownVisitor method visit.
@Override
public void visit(Header node) {
final Node parent = node.jjtGetParent();
for (int ii = 0; ii < parent.jjtGetNumChildren(); ii++) {
if (parent.jjtGetChild(ii) == node) {
if (ii == 0) {
continue;
}
}
}
switch(node.getLevel()) {
case 1:
case 2:
out.setIndent(0);
break;
case 3:
out.setIndent(3);
break;
case 4:
out.setIndent(5);
break;
case 5:
out.setIndent(6);
break;
case 6:
default:
out.setIndent(7);
break;
}
if (!(node.jjtGetParent() instanceof Document && Markdown.getIndexInParent(node) == 0)) {
out.newline();
}
switch(node.getLevel()) {
case 1:
int col = out.getColumn();
this.headerLevel = node.getLevel();
node.childrenAccept(this);
this.headerLevel = -1;
int num = out.getColumn() - col;
out.newline();
for (int ii = 0; ii < num; ii++) {
out.append("=");
}
out.newline();
out.setIndent(8);
break;
case 2:
case 3:
case 4:
case 5:
case 6:
default:
this.headerLevel = node.getLevel();
node.childrenAccept(this);
this.headerLevel = -1;
out.newline();
out.setIndent(8);
break;
}
out.newline();
}
use of org.tautua.markdownpapers.ast.Node in project ceylon by eclipse.
the class DocBookMarkdownVisitor method visit.
public void visit(Paragraph node) {
Node parent = node.jjtGetParent();
if (parent instanceof Item) {
if (!((Item) parent).isLoose()) {
visitChildrenAndAppendSeparator(node, EOL);
return;
}
}
append("<para>");
visitChildrenAndAppendSeparator(node, EOL);
append("</para>");
append(EOL);
}
use of org.tautua.markdownpapers.ast.Node in project ceylon by eclipse.
the class Markdown method extractSections.
/**
* Nasty method for extracting doc sections from a markdown document.
* <ol>
* <li>The most prominent heading(s) are identified
* <li>The document is split into a list of sections corresponding to the
* tree following headings of that level. If the document didn't begin
* with a heading of that level, the first Section in the result list will
* have a null heading.
* </ol>
* @param document
* @return
*/
public static List<Section> extractSections(Document document) {
SectionsMarkdownVisitor v = new SectionsMarkdownVisitor();
document.accept(v);
List<Section> result = new ArrayList<>();
for (int levelIndex = 1; levelIndex <= 6; levelIndex++) {
List<Header> sections = v.sections.get(levelIndex);
if (sections != null) {
Node parent;
{
Header header = sections.get(0);
parent = header.jjtGetParent();
Document doc = extractBetween(v, parent, null, header);
result.add(new Section(null, doc));
}
for (int sectionIndex = 0; sectionIndex < sections.size(); sectionIndex++) {
Header header = sections.get(sectionIndex);
Header next = sectionIndex < sections.size() - 1 ? sections.get(sectionIndex + 1) : null;
Document doc = extractBetween(v, parent, header, next);
result.add(new Section(header, doc));
}
break;
}
}
return result;
}
Aggregations