@Override public boolean shouldSplit(Block block, int depth) { boolean shouldSplit = false; if (block instanceof SectionBlock) { SectionBlock section = (SectionBlock) block; Block firstChild = section.getChildren().get(0); shouldSplit = (firstChild instanceof HeaderBlock) && (Arrays.binarySearch(headingLevels, depth) >= 0); } return shouldSplit; } }
/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.Listener#endSection(java.util.Map) */ public void endSection(Map<String, String> parameters) { this.stack.push(new SectionBlock(generateListFromStack(), parameters)); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.FatherBlock#before(org.xwiki.rendering.listener.Listener) */ public void before(Listener listener) { listener.beginSection(getParameters()); }
new ClassBlockMatcher(SectionBlock.class), Block.Axes.ANCESTOR); if (rootSection != null) { HeaderBlock header = rootSection.getHeaderBlock(); if (header != null) { parameters.start = header.getLevel().getAsInt() + 1;
/** * @return the title block of the section. */ public HeaderBlock getHeaderBlock() { HeaderBlock headerBlock = null; List<Block> children = getChildren(); if (children.size() > 0) { Block firstChild = children.get(0); if (firstChild instanceof HeaderBlock) { headerBlock = (HeaderBlock) firstChild; } } return headerBlock; } }
public void beginHeader(int level, WikiParameters params) { int sectionLevel = this.currentSectionLevel.peek(); // Close sections for (; sectionLevel >= level; --sectionLevel) { this.stack.push(new SectionBlock(generateListFromStack())); } // Open sections for (; sectionLevel < level; ++sectionLevel) { this.stack.push(this.marker); } this.currentSectionLevel.set(this.currentSectionLevel.size() - 1, sectionLevel); // Push header this.stack.push(this.marker); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.FatherBlock#after(org.xwiki.rendering.listener.Listener) */ public void after(Listener listener) { listener.endSection(getParameters()); }
/** * Get the content to display (either the entire document content or the content of a specific section). * * @param document the source document * @param parameters the display parameters * @return the content as an XDOM tree */ private XDOM getContent(DocumentModelBridge document, final DocumentDisplayerParameters parameters) { XDOM content = parameters.isContentTranslated() ? getTranslatedContent(document) : document.getXDOM(); if (parameters.getSectionId() != null) { HeaderBlock headerBlock = content.getFirstBlock(new CompositeBlockMatcher(new ClassBlockMatcher(HeaderBlock.class), new BlockMatcher() { @Override public boolean match(Block block) { return ((HeaderBlock) block).getId().equals(parameters.getSectionId()); } }), Block.Axes.DESCENDANT); if (headerBlock == null) { throw new RuntimeException("Cannot find section [" + parameters.getSectionId() + "] in document [" + this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference()) + "]"); } else { content = new XDOM(headerBlock.getSection().getChildren(), content.getMetaData()); } } return content; }
public void endDocument(WikiParameters params) { // Close sections int sectionLevel = this.currentSectionLevel.peek(); for (; sectionLevel > 0; --sectionLevel) { this.stack.push(new SectionBlock(generateListFromStack())); } --this.documentLevel; this.currentSectionLevel.pop(); if (this.documentLevel > 0) { this.stack.push(new GroupBlock(generateListFromStack(), convertParameters(params))); } }