forked from asciidoctor/asciidoctorj
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes asciidoctor#325. Added method AbstractBlock.append(AbstractBloc…
…k) to append child blocks
- Loading branch information
1 parent
7ce71cd
commit 66067d4
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...j-core/src/test/groovy/org/asciidoctor/extension/WhenAnExtensionAppendsChildBlocks.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.asciidoctor.extension | ||
|
||
import org.asciidoctor.Asciidoctor | ||
import org.asciidoctor.OptionsBuilder | ||
import org.asciidoctor.ast.Block | ||
import org.asciidoctor.ast.DocumentRuby | ||
import org.asciidoctor.ast.Section | ||
import org.jboss.arquillian.spock.ArquillianSputnik | ||
import org.jboss.arquillian.test.api.ArquillianResource | ||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
import org.junit.runner.RunWith | ||
import spock.lang.Specification | ||
|
||
@RunWith(ArquillianSputnik) | ||
class WhenAnExtensionAppendsChildBlocks extends Specification { | ||
|
||
String document = '''= Test document | ||
== Section 1 | ||
some text | ||
== Section 2 | ||
more text | ||
''' | ||
|
||
@ArquillianResource | ||
private Asciidoctor asciidoctor | ||
|
||
def 'then child blocks appended by a tree processor should be rendered'() { | ||
|
||
given: | ||
|
||
final String additionalText = 'Text added by Treeprocessor' | ||
asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { | ||
|
||
int lastid = 0 | ||
|
||
@Override | ||
DocumentRuby process(DocumentRuby document) { | ||
document.blocks.findAll { block -> block instanceof Section }.each { | ||
block -> | ||
Block newBlock = createBlock(block, 'paragraph', additionalText, [:]) | ||
newBlock.id = "NewBlock_${lastid++}" | ||
block.append(newBlock) | ||
} | ||
document | ||
} | ||
}) | ||
|
||
when: | ||
String result = asciidoctor.convert(this.document, OptionsBuilder.options().headerFooter(false)) | ||
|
||
then: | ||
Document htmlDocument = Jsoup.parse(result) | ||
!htmlDocument.select('#NewBlock_0').empty | ||
!htmlDocument.select('#NewBlock_1').empty | ||
htmlDocument.select('#NewBlock_2').empty | ||
|
||
} | ||
|
||
} |