use of org.xwiki.rendering.block.ParagraphBlock in project xwiki-platform by xwiki.
the class DefaultWikiMacroManagerTest method generateWikiMacro.
private DefaultWikiMacro generateWikiMacro(WikiMacroVisibility visibility) throws Exception {
DocumentReference wikiMacroDocReference = new DocumentReference("wiki", Arrays.asList("space"), "space");
WikiMacroDescriptor descriptor = new WikiMacroDescriptor(new MacroId("testwikimacro"), "Test Wiki Macro", "Description", "Test", visibility, new DefaultContentDescriptor(), Collections.<WikiMacroParameterDescriptor>emptyList());
XDOM xdom = new XDOM(Arrays.asList(new ParagraphBlock(Arrays.<Block>asList(new WordBlock("test")))));
DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocReference, authorReference, true, descriptor, xdom, Syntax.XWIKI_2_0, this.mocker);
return wikiMacro;
}
use of org.xwiki.rendering.block.ParagraphBlock in project xwiki-platform by xwiki.
the class DefaultWikiMacro method removeTopLevelParagraph.
/**
* Removes any top level paragraph since for example for the following use case we don't want an extra paragraph
* block: <code>= hello {{velocity}}world{{/velocity}}</code>.
*
* @param blocks the blocks to check and convert
*/
private void removeTopLevelParagraph(List<Block> blocks) {
// We only remove the paragraph if there's only one top level element and if it's a paragraph.
if ((blocks.size() == 1) && blocks.get(0) instanceof ParagraphBlock) {
Block paragraphBlock = blocks.remove(0);
blocks.addAll(0, paragraphBlock.getChildren());
}
}
use of org.xwiki.rendering.block.ParagraphBlock in project xwiki-platform by xwiki.
the class DefaultDocumentSplitterTest method updateAnchors.
@Test
public void updateAnchors() throws Exception {
SplittingCriterion splittingCriterion = mock(SplittingCriterion.class);
when(splittingCriterion.shouldSplit(any(Block.class), anyInt())).thenReturn(false, true, true);
when(splittingCriterion.shouldIterate(any(SectionBlock.class), anyInt())).thenReturn(false, false, false);
NamingCriterion namingCriterion = mock(NamingCriterion.class);
when(namingCriterion.getDocumentName(any(XDOM.class))).thenReturn("Child1", "Child2");
// [[link>>||anchor="chapter1"]]
// = {{id name="chapter1"}}Chapter 1 =
// = Chapter 2 ==
// [[link>>path:#chapter1]]
ResourceReference reference = new ResourceReference("", ResourceType.DOCUMENT);
reference.setParameter("anchor", "chapter1");
LinkBlock link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false);
ParagraphBlock paragraph = new ParagraphBlock(Arrays.<Block>asList(link));
HeaderBlock header = new HeaderBlock(Arrays.<Block>asList(new IdBlock("chapter1"), new WordBlock("Chapter 1")), HeaderLevel.LEVEL1);
SectionBlock section1 = new SectionBlock(Arrays.<Block>asList(header));
header = new HeaderBlock(Arrays.<Block>asList(new WordBlock("Chapter 2")), HeaderLevel.LEVEL1);
reference = new ResourceReference("#chapter1", ResourceType.PATH);
link = new LinkBlock(Arrays.<Block>asList(new WordBlock("link")), reference, false);
SectionBlock section2 = new SectionBlock(Arrays.<Block>asList(header, new ParagraphBlock(Arrays.<Block>asList(link))));
XDOM xdom = new XDOM(Arrays.<Block>asList(paragraph, section1, section2));
WikiDocument document = new WikiDocument("Space.Page", xdom, null);
List<WikiDocument> result = mocker.getComponentUnderTest().split(document, splittingCriterion, namingCriterion);
ClassBlockMatcher linkMatcher = new ClassBlockMatcher(LinkBlock.class);
ResourceReference updatedReference = document.getXdom().<LinkBlock>getFirstBlock(linkMatcher, Axes.DESCENDANT).getReference();
assertEquals("chapter1", updatedReference.getParameter("anchor"));
assertEquals(result.get(1).getFullName(), updatedReference.getReference());
updatedReference = result.get(2).getXdom().<LinkBlock>getFirstBlock(linkMatcher, Axes.DESCENDANT).getReference();
assertEquals(ResourceType.DOCUMENT, updatedReference.getType());
assertEquals("chapter1", updatedReference.getParameter("anchor"));
assertEquals(result.get(1).getFullName(), updatedReference.getReference());
}
use of org.xwiki.rendering.block.ParagraphBlock in project xwiki-platform by xwiki.
the class DefaultDocumentSplitterTest method split.
@Test
public void split() throws Exception {
SplittingCriterion splittingCriterion = mock(SplittingCriterion.class);
when(splittingCriterion.shouldSplit(any(Block.class), anyInt())).thenReturn(true, false, false, true);
when(splittingCriterion.shouldIterate(any(SectionBlock.class), anyInt())).thenReturn(true, false, false, false);
NamingCriterion namingCriterion = mock(NamingCriterion.class);
when(namingCriterion.getDocumentName(any(XDOM.class))).thenReturn("Child1", "Child2");
// = Chapter 1 =
// Once upon a time..
// == Section 1.1 ==
// In a kingdom far away..
HeaderBlock header = new HeaderBlock(Arrays.<Block>asList(new WordBlock("Section 1.1")), HeaderLevel.LEVEL2);
ParagraphBlock paragraph = new ParagraphBlock(Arrays.<Block>asList(new WordBlock("In a kingdom far away..")));
SectionBlock subSection = new SectionBlock(Arrays.<Block>asList(header, paragraph));
header = new HeaderBlock(Arrays.<Block>asList(new WordBlock("Chapter 1")), HeaderLevel.LEVEL1);
paragraph = new ParagraphBlock(Arrays.<Block>asList(new WordBlock("Once upon a time..")));
SectionBlock section = new SectionBlock(Arrays.<Block>asList(header, paragraph, subSection));
XDOM xdom = new XDOM(Arrays.<Block>asList(section));
WikiDocument document = new WikiDocument("Space.Page", xdom, null);
List<WikiDocument> result = mocker.getComponentUnderTest().split(document, splittingCriterion, namingCriterion);
assertEquals(3, result.size());
assertSame(document, result.get(0));
assertEquals("Child1", result.get(1).getFullName());
assertSame(document, result.get(1).getParent());
assertEquals("Child2", result.get(2).getFullName());
assertSame(result.get(1), result.get(2).getParent());
ClassBlockMatcher headerMatcher = new ClassBlockMatcher(HeaderBlock.class);
assertTrue(document.getXdom().<LinkBlock>getBlocks(headerMatcher, Axes.DESCENDANT).isEmpty());
assertEquals(1, result.get(1).getXdom().<LinkBlock>getBlocks(headerMatcher, Axes.DESCENDANT).size());
assertEquals(1, result.get(2).getXdom().<LinkBlock>getBlocks(headerMatcher, Axes.DESCENDANT).size());
}
Aggregations