本文整理汇总了Java中org.pegdown.ast.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.pegdown.ast包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
TableNode tableNode = (TableNode) node;
List<TableColumnNode> tableNodeColumns = tableNode.getColumns();
PdfPTable table = new PdfPTable(tableNodeColumns.size());
for (PdfPTableEvent tableEvent : tableEvents) {
table.setTableEvent(tableEvent);
}
context.pushTable(new TableInfos(table, tableNodeColumns));
context.processChildren(level, node);
context.popTable();
KeyValues kvs = context.iTextContext().keyValues();
Float spacingBefore = kvs.<Float>getNullable(TABLE_SPACING_BEFORE).or(5f);
Float spacingAfter = kvs.<Float>getNullable(TABLE_SPACING_AFTER).or(5f);
table.setSpacingBefore(spacingBefore);
table.setSpacingAfter(spacingAfter);
applyAttributes(context, table);
context.append(table);
}
示例2: f
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public boolean f(TextNode p, Node parent, int index ) {
if( index != 0 ) return false;
if( "note:".equalsIgnoreCase(p.getText()) ) {
element = "note"; // SET ELEMENT TAG
return true;
}
if( "warning:".equalsIgnoreCase(p.getText()) ) {
element = "warning"; // SET ELEMENT TAG
return true;
}
if( "info:".equalsIgnoreCase(p.getText()) ) {
element = "info"; // SET ELEMENT TAG
return true;
}
if( "tip:".equalsIgnoreCase(p.getText()) ) {
element = "tip"; // SET ELEMENT TAG
return true;
}
return false;
}
示例3: findByClass
import org.pegdown.ast.Node; //导入依赖的package包/类
protected <T extends Node, R extends Node> boolean findByClass(T node, final Class<R> clazz, final FindPredicate<R> predicate ) {
boolean result = false;
final java.util.List<Node> children = node.getChildren();
for (int index = 0 ; index < children.size() ; ++index) {
final Node child = children.get(index);
if( clazz.isInstance(child) && predicate.f(clazz.cast(child), node, index)) {
result = true;
} else {
result = findByClass( child, clazz, predicate);
}
if( result ) break;
}
return result;
}
示例4: visit
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void visit(final ExpImageNode ein) {
// We always have a URL, relative or not
final ArrayList<String> alt = new ArrayList<String>();
boolean found = findByClass(ein, TextNode.class, new FindPredicate<TextNode>() {
@Override
public boolean f(TextNode node, Node parent, int index) {
alt.add(node.getText());
return true;
}
});
if (!found) {
throw new IllegalStateException("The alt name should be mandatory in Markdown for images: " + ein.url);
}
String titlePart = isNotBlank(ein.title) ? format("|title=\"%s\"", ein.title) : "";
_buffer.append( format( "!%s|alt=\"%s\"%s!", ein.url, alt.get(0), titlePart));
}
示例5: visit
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void visit(TableHeaderNode tableHeaderNode) {
TableRowNode trn = (TableRowNode)tableHeaderNode.getChildren().get(0);
visit(trn);
// create the header divider
boolean first = true;
for (Node col : trn.getChildren()) {
if (first) {
first = false;
}
else {
currentStringBuilder.append("|");
}
currentStringBuilder.append("-----");
}
currentStringBuilder.append("\n");
}
示例6: createNode
import org.pegdown.ast.Node; //导入依赖的package包/类
/**
* Creates a new node at level (level=0 is the root)
* @param level
* @return
*/
private generated.Node createNode(int level) {
// every time we encounter a header we also need to flush the contents of
// currentStringBuilder into a richContent
if (level > 0) {
flushStringBuilderToCurrentNode();
}
// first, adjust the stack so we get a suitable parent node
while (!stack.isEmpty() && (level <= stack.peek().getLevel())) {
stack.pop();
}
// then create a new node and make it a child of the currentNode()...
generated.Node newNode = new generated.Node();
if (level > 0) {
getCurrentNode().getArrowlinkOrCloudOrEdge().add(newNode);
}
// finally push the newNode onto the stack.
stack.push(new MmNodeWrapper(newNode, level));
return newNode;
}
示例7: lookupChild
import org.pegdown.ast.Node; //导入依赖的package包/类
public static Node lookupChild(Node node, Class<? extends Node>... childClasses) {
Node child = node;
for (Class<? extends Node> childClass : childClasses) {
if(child==null)
return null;
List<Node> children = child.getChildren();
if(children==null || children.isEmpty())
return null;
child = children.get(0);
if (!childClass.isInstance(child))
return null;
}
return child;
}
示例8: query
import org.pegdown.ast.Node; //导入依赖的package包/类
public Optional<TreeNavigation> query(TreeNavigation nav) {
int len = nav.numberOfAncestors();
if (len <= 1)
return Optional.absent();
List<Node> ancestors = nav.ancestorsStack();
Node n = ancestors.get(len - 1);
Node p = ancestors.get(len - 2);
Node s = null;
for (Node sibling : p.getChildren()) {
if (sibling == n) {
if (s == null) {
return Optional.absent();
}
List<Node> nodes = Lists.newArrayList(ancestors.subList(0, len - 2));
nodes.add(s);
return Optional.of(new TreeNavigation(nodes));
}
s = sibling;
}
return Optional.absent();
}
示例9: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
List<Element> subs = context.collectChildren(level, node);
Paragraph p = new Paragraph();
for (Element sub : subs) {
p.add(discardNewline(sub));
}
KeyValues kvs = context.iTextContext().keyValues();
Float spacingBefore = kvs.<Float>getNullable(PARAGRAPH_SPACING_BEFORE).or(5f);
Float spacingAfter = kvs.<Float>getNullable(PARAGRAPH_SPACING_AFTER).or(5f);
p.setSpacingBefore(spacingBefore);
p.setSpacingAfter(spacingAfter);
applyAttributes(context, p);
context.append(p);
}
示例10: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
RefLinkNode refLink = (RefLinkNode) node;
@SuppressWarnings("unchecked")
TextNode text = (TextNode) lookupChild(refLink.referenceKey, TextNode.class);
if (text == null) {
log.warn("Unknown reference link structure... {}", refLink);
context.processChildren(level, node);
return;
}
References.Ref ref = context.references().lookup(text.getText());
if (ref != null) {
Node altNode = refLink.getChildren().get(0);
context.process(level, new ExpLinkNode(ref.title(), ref.url(), altNode));
return;
}
log.warn("Reference not found for link {}", text.getText());
}
示例11: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
VerbatimNode vNode = (VerbatimNode) node;
SourceCode code = convertToSourceCode(vNode);
Attributes attributes = context.peekAttributes(level);
applyAttributes(code, attributes);
ITextContext iTextContext = context.iTextContext();
List<Element> elements = iTextContext.emitButCollectElements(code);
for (Element element : elements) {
ITextUtils.applyAttributes(element, attributes);
context.append(element);
}
}
示例12: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(int level, Node node, InvocationContext context) {
TreeNavigation nav = context.treeNavigation();
boolean isHeaderRow = nav.ancestorTreeMatches(TableRowNode.class, TableHeaderNode.class);
List<Element> elements = context.collectChildren(level, node);
TableInfos tableInfos = context.peekTable();
PdfPTable table = tableInfos.getTable();
int col = 0;
for (Element element : elements) {
PdfPCell cell = (PdfPCell) element;
cell.setHorizontalAlignment(tableInfos.columnAlignment(col));
table.addCell(cell);
col += cell.getColspan();
}
table.completeRow();
if (isHeaderRow) {
int headerRows = table.getHeaderRows();
table.setHeaderRows(headerRows + 1);
}
}
示例13: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(int level, Node node, InvocationContext context) {
TreeNavigation nav = context.treeNavigation();
boolean isHeaderCell = nav.ancestorTreeMatches(TableCellNode.class, TableRowNode.class, TableHeaderNode.class);
CellStyler cellStyler = context.peekCellStyler();
context.pushFont(cellStyler.cellFont());
List<Element> elements = context.collectChildren(level, node);
context.popFont();
Phrase phrase = new Phrase();
phrase.addAll(elements);
int colspan = ((TableCellNode) node).getColSpan();
PdfPCell cell = isHeaderCell ? headerCell(phrase) : new PdfPCell(phrase);
cell.setColspan(colspan);
cellStyler.applyStyle(cell);
context.append(cell);
}
示例14: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
RefImageNode refImage = (RefImageNode) node;
@SuppressWarnings("unchecked")
TextNode text = (TextNode) lookupChild(refImage.referenceKey, TextNode.class);
if (text == null) {
log.warn("Unknown reference image structure... {}", refImage);
context.processChildren(level, node);
return;
}
References.Ref ref = context.references().lookup(text.getText());
if (ref != null) {
Node altNode = refImage.getChildren().get(0);
context.process(level, new ExpImageNode(ref.title(), ref.url(), altNode));
return;
}
log.warn("Reference not found for image {}", text.getText());
}
示例15: process
import org.pegdown.ast.Node; //导入依赖的package包/类
@Override
public void process(int level, Node node, InvocationContext context) {
List<Element> subs = context.collectChildren(level, node);
com.itextpdf.text.List orderedList = new com.itextpdf.text.List(com.itextpdf.text.List.ORDERED);
for (Element sub : subs) {
if (!orderedList.add(sub)) {
// wrap it
ListItem listItem = new ListItem();
listItem.add(sub);
orderedList.add(listItem);
}
}
KeyValues kvs = context.iTextContext().keyValues();
Float spacingBefore = kvs.<Float>getNullable(ORDERED_LIST_SPACING_BEFORE).or(5f);
Float spacingAfter = kvs.<Float>getNullable(ORDERED_LIST_SPACING_AFTER).or(5f);
Paragraph p = new Paragraph();
p.add(orderedList);
p.setSpacingBefore(spacingBefore);
p.setSpacingAfter(spacingAfter);
context.append(p);
}