Remove ContentPart and StructuredDocument API
DELETE
asciidoctorj-api/src/main/java/org/asciidoctor/ast/ContentPart.java
-package org.asciidoctor.ast;
-
-import java.util.List;
-import java.util.Map;
-
-public interface ContentPart {
-
- String getId();
-
- int getLevel();
-
- String getContext();
-
- String getStyle();
-
- String getRole();
-
- String getTitle();
-
- Map<String, Object> getAttributes();
-
- String getContent();
-
- List<ContentPart> getParts();
-}

DELETE
asciidoctorj-api/src/main/java/org/asciidoctor/ast/StructuredDocument.java
-package org.asciidoctor.ast;
-
-import java.util.List;
-
-/**
- * Structure document containing header and content chunks
- *
- * @author marek
- *
- */
-public interface StructuredDocument {
-
- List<ContentPart> getParts();
-
- DocumentHeader getHeader();
-
- /**
- * Return first matched part by id
- *
- * @param id The id to match
- * @return The ContentPart if the id is not null and the document
- * contains a block-level element with this id or null otherwise.
- */
- ContentPart getPartById(String id);
-
- /**
- * Return first matched part by style
- *
- * @param style The style to match
- * @return The first ContentPart if the style is not null and the document
- * contains a block-level element with this style name or null otherwise.
- */
- ContentPart getPartByStyle(String style);
-
- /**
- * Return first matched part by role
- *
- * @param role The role to match
- * @return The first ContentPart if the role is not null and the document
- * contains a block-level element with this role name or null otherwise.
- */
- ContentPart getPartByRole(String role);
-
- /**
- * Return all parts that match specified context
- *
- * @param context The context to match
- * @return A list of ContentPart items that match the context if the
- * context is not null or an empty collection.
- */
- List<ContentPart> getPartsByContext(String context);
-
- /**
- * Return all parts that match specified style
- *
- * @param style The style to match
- * @return A list of ContentPart items that match the style if the
- * style is not null or an empty collection.
- */
- List<ContentPart> getPartsByStyle(String style);
-
- /**
- * Return all parts that match specified role
- *
- * @param role The role to match
- * @return A list of ContentPart items that match the role if the
- * role is not null or an empty collection.
- */
- List<ContentPart> getPartsByRole(String role);
-}

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java
asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java
package org.asciidoctor;
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.DocumentHeader;
-import org.asciidoctor.ast.StructuredDocument;
import org.asciidoctor.converter.JavaConverterRegistry;
import org.asciidoctor.extension.ExtensionGroup;
import org.asciidoctor.extension.JavaExtensionRegistry;
@@ -18,6 +9,14 @@ import org.asciidoctor.extension.RubyExtensionRegistry;
import org.asciidoctor.internal.JRubyAsciidoctor;
import org.asciidoctor.log.LogHandler;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
/**
*
*
@@ -676,47 +675,6 @@ public interface Asciidoctor {
String[] convertFiles(Collection<File> asciidoctorFiles,
OptionsBuilder options);
- /**
- * Reads and creates structured document containing header and content chunks.
- * By default it dig only one level down but it can be tweak by setting STRUCTURE_MAX_LEVEL
- * option.
- *
- * @param filename
- * to read the attributes.
- * @param options
- * a Hash of options to control processing (default: {}).
- * @return structured document.
- */
- StructuredDocument readDocumentStructure(File filename,Map<String,Object> options);
-
- /**
- * Reads and creates structured document containing header and content chunks.
- * By default it dig only one level down but it can be tweak by setting STRUCTURE_MAX_LEVEL
- * option.
- *
- * @param content
- * where rendered content is written. Writer is flushed, but not
- * closed.
- * @param options
- * a Hash of options to control processing (default: {}).
- * @return structured document.
- */
- StructuredDocument readDocumentStructure(String content,Map<String,Object> options);
-
- /**
- * Reads and creates structured document containing header and content chunks.
- * By default it dig only one level down but it can be tweak by setting STRUCTURE_MAX_LEVEL
- * option.
- *
- * @param contentReader
- * where asciidoc content is read.
- * @param options
- * a Hash of options to control processing (default: {}).
- * @return structured document.
- */
- StructuredDocument readDocumentStructure(Reader contentReader,Map<String,Object> options);
-
-
/**
* Reads only header parameters instead of all document.
*

DELETE
asciidoctorj-core/src/main/java/org/asciidoctor/ast/impl/ContentPartImpl.java
-package org.asciidoctor.ast.impl;
-
-import java.util.List;
-import java.util.Map;
-
-import org.asciidoctor.ast.ContentPart;
-
-public class ContentPartImpl implements ContentPart {
- private String id;
- private int level;
- private String context;
- private String style;
- private String role;
- private String title;
- private Map<String, Object> attributes;
- private String content;
- private List<ContentPart> parts;
-
- private ContentPartImpl() {
- super();
- }
-
- public String getId() {
- return id;
- }
-
- public int getLevel() {
- return level;
- }
-
- public String getContext() {
- return context;
- }
-
- public String getStyle() {
- return style;
- }
-
- public String getRole() {
- return role;
- }
-
- public String getTitle() {
- return title;
- }
-
- public Map<String, Object> getAttributes() {
- return attributes;
- }
-
- public String getContent() {
- return content;
- }
-
- public List<ContentPart> getParts() {
- return parts;
- }
-
- public void setParts(List<ContentPart> parts) {
- this.parts = parts;
- }
-
- public static ContentPartImpl createContentPart(String id, int level, String context, String title, String style,
- String role, Map<String, Object> attributes, String textContent) {
- ContentPartImpl contentPart = new ContentPartImpl();
- contentPart.level = level;
- contentPart.id = id;
- contentPart.context = context;
- contentPart.style = style;
- contentPart.role = role;
- contentPart.title = title;
- contentPart.attributes = attributes;
- contentPart.content = textContent;
-
- return contentPart;
- }
-
-}

DELETE
asciidoctorj-core/src/main/java/org/asciidoctor/ast/impl/StructuredDocumentImpl.java
-package org.asciidoctor.ast.impl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.asciidoctor.ast.ContentPart;
-import org.asciidoctor.ast.DocumentHeader;
-import org.asciidoctor.ast.StructuredDocument;
-
-/**
- * Structure document containing header and content chunks
- *
- * @author marek
- *
- */
-public class StructuredDocumentImpl implements StructuredDocument {
-
- private DocumentHeader header;
-
- private List<ContentPart> parts;
-
- private StructuredDocumentImpl() {
- super();
- }
-
- public List<ContentPart> getParts() {
- return parts;
- }
-
- public DocumentHeader getHeader() {
- return header;
- }
-
- /**
- * Return first matched part by id
- *
- * @param id The id to match
- * @return The ContentPart if the id is not null and the document
- * contains a block-level element with this id or null otherwise.
- */
- public ContentPart getPartById(String id) {
- if (id != null) {
- for (ContentPart part : parts) {
- if (id.equals(part.getId())) {
- return part;
- }
- }
- }
- return null;
- }
-
- /**
- * Return first matched part by style
- *
- * @param style The style to match
- * @return The first ContentPart if the style is not null and the document
- * contains a block-level element with this style name or null otherwise.
- */
- public ContentPart getPartByStyle(String style) {
- if (style != null) {
- for (ContentPart part : parts) {
- if (style.equals(part.getStyle())) {
- return part;
- }
- }
- }
- return null;
- }
-
- /**
- * Return first matched part by role
- *
- * @param role The role to match
- * @return The first ContentPart if the role is not null and the document
- * contains a block-level element with this role name or null otherwise.
- */
- public ContentPart getPartByRole(String role) {
- if (role != null) {
- for (ContentPart part : parts) {
- if (role.equals(part.getRole())) {
- return part;
- }
- }
- }
- return null;
- }
-
- /**
- * Return all parts that match specified context
- *
- * @param context The context to match
- * @return A list of ContentPart items that match the context if the
- * context is not null or an empty collection.
- */
- public List<ContentPart> getPartsByContext(String context) {
- if (context != null) {
- List<ContentPart> filteredParts = new ArrayList<ContentPart>();
- for (ContentPart part : parts) {
- if (context.equals(part.getContext())) {
- filteredParts.add(part);
- }
- }
- return filteredParts;
- }
- return Collections.emptyList();
- }
-
- /**
- * Return all parts that match specified style
- *
- * @param style The style to match
- * @return A list of ContentPart items that match the style if the
- * style is not null or an empty collection.
- */
- public List<ContentPart> getPartsByStyle(String style) {
- if (style != null) {
- List<ContentPart> filteredParts = new ArrayList<ContentPart>();
- for (ContentPart part : parts) {
- if (style.equals(part.getStyle())) {
- filteredParts.add(part);
- }
- }
- return filteredParts;
- }
- return Collections.emptyList();
- }
-
- /**
- * Return all parts that match specified role
- *
- * @param role The role to match
- * @return A list of ContentPart items that match the role if the
- * role is not null or an empty collection.
- */
- public List<ContentPart> getPartsByRole(String role) {
- if (role != null) {
- List<ContentPart> filteredParts = new ArrayList<ContentPart>();
- for (ContentPart part : parts) {
- if (role.equals(part.getRole())) {
- filteredParts.add(part);
- }
- }
- return filteredParts;
- }
- return Collections.emptyList();
- }
-
- public static StructuredDocument createStructuredDocument(DocumentHeader header, List<ContentPart> parts) {
- StructuredDocumentImpl document = new StructuredDocumentImpl();
- document.header = header;
- document.parts = parts;
-
- return document;
- }
-}

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java
asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java
@@ -5,15 +5,10 @@ import org.asciidoctor.Attributes;
import org.asciidoctor.DirectoryWalker;
import org.asciidoctor.Options;
import org.asciidoctor.OptionsBuilder;
-import org.asciidoctor.ast.ContentPart;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.DocumentHeader;
import org.asciidoctor.ast.NodeConverter;
-import org.asciidoctor.ast.StructuralNode;
-import org.asciidoctor.ast.StructuredDocument;
-import org.asciidoctor.ast.impl.ContentPartImpl;
import org.asciidoctor.ast.impl.DocumentHeaderImpl;
-import org.asciidoctor.ast.impl.StructuredDocumentImpl;
import org.asciidoctor.converter.JavaConverterRegistry;
import org.asciidoctor.converter.internal.ConverterRegistryExecutor;
import org.asciidoctor.extension.ExtensionGroup;
@@ -175,75 +170,6 @@ public class JRubyAsciidoctor implements Asciidoctor, LogHandler {
documentImpl.getAttributes());
}
- private StructuredDocument toDocument(Document document, Ruby rubyRuntime, int maxDeepLevel) {
-
- Document documentImpl = (Document) NodeConverter.createASTNode(document);
- List<ContentPart> contentParts = getContents(documentImpl.getBlocks(), maxDeepLevel);
- return StructuredDocumentImpl.createStructuredDocument(toDocumentHeader(documentImpl), contentParts);
- }
-
- private List<ContentPart> getContents(List<StructuralNode> blocks, int maxDeepLevel) {
- if (blocks == null) {
- return null;
- }
- List<ContentPart> parts = new ArrayList<>();
- for (StructuralNode block : blocks) {
- if (block.getLevel() > maxDeepLevel) {
- continue;
- }
- parts.add(getContentPartFromBlock(block, maxDeepLevel));
- }
- return parts;
- }
-
- private ContentPart getContentPartFromBlock(StructuralNode child, int maxDeepLevel) {
- Object content = child.getContent();
- String textContent;
- if (content instanceof String) {
- textContent = (String) content;
- } else {
- textContent = child.convert();
- }
- ContentPartImpl contentPart = ContentPartImpl.createContentPart(child.getId(), child.getLevel(), child.getContext(), child.getTitle(),
- child.getStyle(), child.getRole(), child.getAttributes(), textContent);
- contentPart.setParts(getContents(child.getBlocks(), maxDeepLevel));
- return contentPart;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public StructuredDocument readDocumentStructure(File filename, Map<String, Object> options) {
-
- this.rubyGemsPreloader.preloadRequiredLibraries(options);
-
- RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
- Document document = (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load_file", rubyRuntime.newString(filename.getAbsolutePath()), rubyHash));
- int maxDeepLevel = options.containsKey(STRUCTURE_MAX_LEVEL) ? (Integer) (options.get(STRUCTURE_MAX_LEVEL))
- : DEFAULT_MAX_LEVEL;
- return toDocument(document, rubyRuntime, maxDeepLevel);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public StructuredDocument readDocumentStructure(String content, Map<String, Object> options) {
-
- this.rubyGemsPreloader.preloadRequiredLibraries(options);
-
- RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
-
- Document document = (Document) NodeConverter.createASTNode(
- getAsciidoctorModule().callMethod("load", rubyRuntime.newString(content), rubyHash));
- int maxDeepLevel = options.containsKey(STRUCTURE_MAX_LEVEL) ? (Integer) (options.get(STRUCTURE_MAX_LEVEL))
- : DEFAULT_MAX_LEVEL;
- return toDocument(document, rubyRuntime, maxDeepLevel);
- }
-
- @Override
- public StructuredDocument readDocumentStructure(Reader contentReader, Map<String, Object> options) {
- String content = IOUtils.readFull(contentReader);
- return readDocumentStructure(content, options);
- }
-
@SuppressWarnings("unchecked")
@Override
public DocumentHeader readDocumentHeader(File filename) {

DELETE
asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheSectionLevelIsAccessed.groovy
-package org.asciidoctor
-
-import org.asciidoctor.ast.Section
-import org.asciidoctor.internal.JRubyAsciidoctor
-import org.asciidoctor.util.ClasspathResources
-import org.jboss.arquillian.spock.ArquillianSputnik
-import org.jboss.arquillian.test.api.ArquillianResource
-import org.junit.Rule
-import org.junit.runner.RunWith
-import spock.lang.Specification
-
-/**
- * Tests that the unsubstituted text can be retrieved from nodes
- */
-@RunWith(ArquillianSputnik)
-class WhenTheSectionLevelIsAccessed extends Specification {
-
- public static final String DOC_TITLE = 'Include other files'
- public static final String TITLE_FIRST_CHAPTER = 'First chapter'
- public static final String TITLE_FIRST_SUBSECTION = 'More First'
- public static final String TITLE_SECOND_CHAPTER = 'Second chapter'
-
- public static final String FILENAME_FLAT = 'parts/mainflat.adoc'
- public static final String FILENAME_WITH_INCLUDES = 'parts/main.adoc'
-
- public static final int ONE = 1
- public static final int TWO = 2
- public static final int THREE = 3
- public static final String CONTEXT_PARAGRAPH = 'paragraph'
-
- @ArquillianResource
- private Asciidoctor asciidoctor
-
- @Rule
- ClasspathResources classpath = new ClasspathResources()
-
- def 'it should return the correct level from the ContentPart API'() {
-
- when:
- def doc = asciidoctor.readDocumentStructure(classpath.getResource(FILENAME_FLAT),
- OptionsBuilder.options()
- .safe(SafeMode.UNSAFE)
- .option(JRubyAsciidoctor.STRUCTURE_MAX_LEVEL, THREE)
- .asMap())
-
- then:
- doc.parts.size() == TWO
- doc.parts[0].level == ONE
- doc.parts[0].title == TITLE_FIRST_CHAPTER
- doc.parts[0].parts.size() == TWO
- def subsection = doc.parts[0].parts[ONE]
- subsection.level == THREE
- subsection.title == TITLE_FIRST_SUBSECTION
- subsection.parts.size() == ONE
- doc.parts[ONE].level == ONE
- doc.parts[ONE].title == TITLE_SECOND_CHAPTER
- doc.parts[ONE].parts.size() == ONE
- }
-
- def 'it should not recurse deeper than max level'() {
-
- when:
- def doc = asciidoctor.readDocumentStructure(classpath.getResource(FILENAME_FLAT),
- OptionsBuilder.options()
- .safe(SafeMode.UNSAFE)
- .option(JRubyAsciidoctor.STRUCTURE_MAX_LEVEL, TWO)
- .asMap())
-
- then:
- doc.parts.size() == TWO
- doc.parts[0].level == ONE
- doc.parts[0].title == TITLE_FIRST_CHAPTER
- doc.parts[0].parts.size() == ONE
- def paragraph = doc.parts[0].parts[0]
- paragraph.level == ONE
- paragraph.title == null
- paragraph.parts == null || paragraph.parts.empty
- paragraph.context == CONTEXT_PARAGRAPH
- doc.parts[ONE].level == ONE
- doc.parts[ONE].title == TITLE_SECOND_CHAPTER
- doc.parts[ONE].parts.size() == ONE
- }
-
- def 'it should return the correct level from the ContentPart API with leveloffset'() {
-
- when:
- def doc = asciidoctor.readDocumentStructure(classpath.getResource(FILENAME_WITH_INCLUDES),
- OptionsBuilder.options()
- .safe(SafeMode.UNSAFE)
- .option(JRubyAsciidoctor.STRUCTURE_MAX_LEVEL, THREE)
- .asMap())
-
- then:
- doc.parts.size() == TWO
- doc.parts[0].level == ONE
- doc.parts[0].title == TITLE_FIRST_CHAPTER
- doc.parts[0].parts.size() == TWO
- def subsection = doc.parts[0].parts[ONE]
- subsection.level == THREE
- subsection.title == TITLE_FIRST_SUBSECTION
- subsection.parts.size() == ONE
- doc.parts[ONE].level == ONE
- doc.parts[ONE].title == TITLE_SECOND_CHAPTER
- doc.parts[ONE].parts.size() == ONE
- }
-
- def 'it should not recurse deeper than max level with level offset'() {
-
- when:
- def doc = asciidoctor.readDocumentStructure(classpath.getResource(FILENAME_WITH_INCLUDES),
- OptionsBuilder.options()
- .safe(SafeMode.UNSAFE)
- .option(JRubyAsciidoctor.STRUCTURE_MAX_LEVEL, TWO)
- .asMap())
-
- then:
- doc.parts.size() == TWO
- doc.parts[0].level == ONE
- doc.parts[0].title == TITLE_FIRST_CHAPTER
- doc.parts[0].parts.size() == ONE
- def paragraph = doc.parts[0].parts[0]
- paragraph.level == ONE
- paragraph.title == null
- paragraph.parts == null || paragraph.parts.empty
- paragraph.context == CONTEXT_PARAGRAPH
- doc.parts[ONE].level == ONE
- doc.parts[ONE].title == TITLE_SECOND_CHAPTER
- doc.parts[ONE].parts.size() == ONE
- }
-
-
- def 'it should return the correct level from the AST API'() {
-
-
- when:
- def doc = asciidoctor.loadFile(classpath.getResource(FILENAME_WITH_INCLUDES),
- OptionsBuilder.options().safe(SafeMode.UNSAFE).asMap())
-
- then:
- doc.level == 0
- doc.title == DOC_TITLE
- doc.blocks.size() == TWO
- def section1 = doc.blocks[0] as Section
- section1.level == ONE
- section1.title == TITLE_FIRST_CHAPTER
- section1.blocks.size() == TWO
- section1.blocks[ONE].level == THREE
- section1.blocks[ONE].title == TITLE_FIRST_SUBSECTION
- def section2 = doc.blocks[ONE] as Section
- section2.level == ONE
- section2.title == TITLE_SECOND_CHAPTER
- section2.blocks.size() == ONE
- }
-
-}

DELETE
asciidoctorj-core/src/test/java/org/asciidoctor/WhenStructuredDocumentIsRequired.java
-package org.asciidoctor;
-
-import static org.hamcrest.CoreMatchers.either;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
-import static org.junit.Assert.assertThat;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.asciidoctor.arquillian.api.Unshared;
-import org.asciidoctor.ast.ContentPart;
-import org.asciidoctor.ast.DocumentHeader;
-import org.asciidoctor.ast.StructuredDocument;
-import org.asciidoctor.util.ClasspathResources;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-
-@RunWith(Arquillian.class)
-public class WhenStructuredDocumentIsRequired {
-
- @ArquillianResource
- private ClasspathResources classpath;
-
- @ArquillianResource
- private TemporaryFolder testFolder;
-
- @ArquillianResource(Unshared.class)
- private Asciidoctor asciidoctor;
-
- @Test
- public void empty_parent_title_makes_subsection_be_null_when_is_parsed() {
-
- String s = "= My page\n" + "\n" + "== Totally ignored header\n" + "\n"
- + "What does it mean?\n";
-
- StructuredDocument structuredDocument = asciidoctor
- .readDocumentStructure(s, new java.util.HashMap<String, Object>());
-
- List<? extends ContentPart> parts = structuredDocument.getParts();
- assertThat(parts, hasSize(1));
-
- DocumentHeader header = structuredDocument.getHeader();
- assertThat(header.getDocumentTitle().getMain(), is("My page"));
- assertThat(header.getDocumentTitle().getSubtitle(), nullValue());
- assertThat(header.getAuthor().getFirstName(), nullValue());
-
- }
-
- @Test
- public void structural_content_should_be_retrieved_from_file() {
-
- Map<String, Object> parameters = new HashMap<String, Object>();
- parameters.put(Asciidoctor.STRUCTURE_MAX_LEVEL, 2);
- StructuredDocument document = asciidoctor.readDocumentStructure(
- classpath.getResource("documentblocks.asciidoc"),
- parameters);
-
- DocumentHeader header = document.getHeader();
-
- assertThat(header.getDocumentTitle().getMain(), is("Sample Document"));
- assertThat(header.getPageTitle(), is("Sample Document"));
-
- Map<String, Object> attributes = header.getAttributes();
- assertThat((String) attributes.get("revdate"), is("2013-05-20"));
- assertThat((String) attributes.get("revnumber"), is("1.0"));
- assertThat((String) attributes.get("revremark"), is("First draft"));
- // attributes should be incasesensitive
- assertThat((String) attributes.get("tags"), is("[document, example]"));
- assertThat((String) attributes.get("Tags"), is("[document, example]"));
- assertThat((String) attributes.get("author"), is("Doc Writer"));
- assertThat((String) attributes.get("email"),
- is("doc.writer@asciidoc.org"));
-
- List<? extends ContentPart> parts = document.getParts();
-
- assertThat(parts, notNullValue());
- assertThat(parts, hasSize(3));
-
- assertThat(parts.get(0).getContext(), is("section"));
- assertThat(parts.get(0).getTitle(), is("Abstract"));
-
- assertThat(parts.get(0).getParts(), hasSize(1));
- assertThat(parts.get(0).getParts().get(0).getStyle(), is("abstract"));
- assertThat(parts.get(0).getParts().get(0).getContext(), is("open"));
-
- assertThat(parts.get(1).getTitle(), is("First Section"));
- assertThat(parts.get(1).getId(), is("_first_section"));
- assertThat(parts.get(1).getContext(), is("section"));
- assertThat(parts.get(1).getParts(), hasSize(5));
-
- assertThat(parts.get(1).getParts().get(1).getId(), is("blockid"));
- assertThat(parts.get(1).getParts().get(1).getStyle(), is("quote"));
- assertThat(
- (String) parts.get(1).getParts().get(1).getAttributes()
- .get("attribution"), is("Abraham Lincoln"));
-
- assertThat(parts.get(1).getParts().get(2).getRole(), is("feature-list"));
-
- assertThat(parts.get(2).getTitle(), is("Second Section"));
- assertThat(parts.get(2).getParts(), hasSize(2));
-
- assertThat(parts.get(2).getParts().get(0).getContext(), is("image"));
- assertThat(parts.get(2).getParts().get(1).getContext(), is("image"));
- }
-
- @Test
- public void some_real_content() {
- StructuredDocument document = asciidoctor.readDocumentStructure(
- classpath.getResource("contentstructure.asciidoc"),
- new HashMap<String, Object>());
-
- DocumentHeader header = document.getHeader();
-
- assertThat(header.getDocumentTitle().getMain(), is("TODO"));
- assertThat(header.getDocumentTitle().getSubtitle(), is("Document Title"));
-
- List<? extends ContentPart> parts = document.getParts();
-
- assertThat(parts, notNullValue());
- assertThat(parts, hasSize(4));
-
- assertThat(document.getPartByStyle("literal").getContent(),
- is("TODO: This is description"));
-
- List<? extends ContentPart> images = document.getPartsByContext("image");
- assertThat(images, hasSize(2));
- for (int i = 0; i < 2; i++) {
- assertThat((String) images.get(i).getAttributes().get("target"),
- is("src/some image " + (i + 1) + ".JPG"));
- assertThat((String) images.get(i).getAttributes().get("alt"),
- is("TODO title" + (i + 1)));
- assertThat((String) images.get(i).getAttributes().get("link"),
- is("link" + (i + 1) + ".html"));
- }
- assertThat(document.getPartByStyle("Open").getContent(),
- either(startsWith("<div class=\"paragraph text-center\">")).or(startsWith("<div class=\"text-center paragraph\">")));
- }
-
- @Test
- public void title_should_be_retrieved_from_simple_string() {
-
- StructuredDocument document = asciidoctor.readDocumentStructure(
- "= Sample Document", new HashMap<String, Object>());
-
- DocumentHeader header = document.getHeader();
-
- assertThat(header.getDocumentTitle().getMain(), is("Sample Document"));
-
- List<? extends ContentPart> parts = document.getParts();
-
- assertThat(parts, notNullValue());
- assertThat(parts, hasSize(0));
-
- }
-
- @Test
- public void one_part_should_be_retrieved_from_simple_string() {
-
- StructuredDocument document = asciidoctor.readDocumentStructure(
- "Simple single paragraph", new HashMap<String, Object>());
-
- DocumentHeader header = document.getHeader();
-
- assertThat(header, notNullValue());
-
- List<? extends ContentPart> parts = document.getParts();
-
- assertThat(parts, notNullValue());
- assertThat(parts, hasSize(1));
- assertThat(parts.get(0).getContent(), is("Simple single paragraph"));
-
- }
-
- @Test
- public void no_parts_should_be_retrieved_from_empty_string() {
-
- StructuredDocument document = asciidoctor.readDocumentStructure("",
- new HashMap<String, Object>());
-
- DocumentHeader header = document.getHeader();
-
- assertThat(header, notNullValue());
-
- List<? extends ContentPart> parts = document.getParts();
-
- assertThat(parts, notNullValue());
- assertThat(parts, hasSize(0));
- }
-
-}

Remove ContentPart and StructuredDocument API