Java Code Examples for org.asciidoctor.ast.Document#findBy()
The following examples show how to use
org.asciidoctor.ast.Document#findBy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WhenAsciiDocIsRenderedToDocument.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void should_be_able_to_get_source_location() { // Given File file = classpath.getResource("sourcelocation.adoc"); // When Document document = asciidoctor.loadFile(file, OptionsBuilder.options().sourcemap(true).docType("book").asMap()); Map<Object, Object> selector = new HashMap<Object, Object>(); selector.put("context", ":paragraph"); List<StructuralNode> findBy = document.findBy(selector); // Then StructuralNode block1 = findBy.get(0); assertThat(block1.getSourceLocation().getLineNumber(), is(3)); assertThat(block1.getSourceLocation().getPath(), is(file.getName())); assertThat(block1.getSourceLocation().getFile(), is(file.getName())); assertThat(block1.getSourceLocation().getDir(), is(file.getParent().replaceAll("\\\\", "/"))); StructuralNode block2 = findBy.get(1); assertThat(block2.getSourceLocation().getLineNumber(), is(8)); assertThat(block2.getSourceLocation().getPath(), is(file.getName())); assertThat(block2.getSourceLocation().getFile(), is(file.getName())); assertThat(block2.getSourceLocation().getDir(), is(file.getParent().replaceAll("\\\\", "/"))); }
Example 2
Source File: WhenAsciiDocIsRenderedToDocument.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void should_find_elements_from_document() { Document document = asciidoctor.load(DOCUMENT, new HashMap<String, Object>()); Map<Object, Object> selector = new HashMap<Object, Object>(); selector.put("context", ":image"); List<StructuralNode> findBy = document.findBy(selector); assertThat(findBy, hasSize(2)); assertThat((String)findBy.get(0).getAttributes().get("target"), is("tiger.png")); assertThat(findBy.get(0).getLevel(), greaterThan(0)); }