diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2486784d5..6f8b502ed 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -49,6 +49,11 @@ Documentation:: Improvement:: +* Add `setContext` function to ContentNode. + +* Add command line option --failure-level to force non-zero exit code from AsciidoctorJ CLI if specified logging level is reached. (#1114) +* Upgrade to asciidoctorj 2.0.20 (#1208) +* Upgrade to asciidoctorj-pdf 2.3.7 (#1182) * Add 'standalone' option, deprecates 'headerFooter' (#1160) (@abelsromero) * Upgrade to asciidoctorj-diagram 2.2.7 diff --git a/asciidoctorj-api/src/main/java/org/asciidoctor/ast/ContentNode.java b/asciidoctorj-api/src/main/java/org/asciidoctor/ast/ContentNode.java index 8eb0439fa..3941285af 100644 --- a/asciidoctorj-api/src/main/java/org/asciidoctor/ast/ContentNode.java +++ b/asciidoctorj-api/src/main/java/org/asciidoctor/ast/ContentNode.java @@ -32,6 +32,9 @@ public interface ContentNode { @Deprecated String context(); String getContext(); + + void setContext(String context); + /** * @deprecated Use {@linkplain #getDocument()} instead. */ diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/ast/impl/ContentNodeImpl.java b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/ast/impl/ContentNodeImpl.java index c1f093516..af0bdf57e 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/ast/impl/ContentNodeImpl.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/ast/impl/ContentNodeImpl.java @@ -46,6 +46,11 @@ public String getContext() { return getString("context"); } + @Override + public void setContext(String context) { + setString("context", context); + + } @Override @Deprecated public ContentNode parent() { diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/ast/impl/ContextChangeTest.java b/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/ast/impl/ContextChangeTest.java new file mode 100644 index 000000000..07165f76e --- /dev/null +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/jruby/ast/impl/ContextChangeTest.java @@ -0,0 +1,54 @@ +package org.asciidoctor.jruby.ast.impl; + +import org.asciidoctor.Asciidoctor; +import org.asciidoctor.Attributes; +import org.asciidoctor.Options; +import org.asciidoctor.ast.Document; +import org.asciidoctor.ast.StructuralNode; + +import org.junit.Test; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + + +public class ContextChangeTest { + + private final Asciidoctor asciiDoctor = Asciidoctor.Factory.create(); + + static String orderedListSample() { + return "= Document Title\n\n" + + "== Section A\n\n" + + ". This it item 1 in an ordered list\n\n" + + ". This is item 2 in an ordered list\n\n" + + ". This is item 3 in and ordered list\n\n"; + + } + + @Test + public void get_context_of_ordered_list(){ + + Document document = loadDocument(orderedListSample()); + + assertThat(document, notNullValue()); + assertThat(document.getBlocks().size(), equalTo(1)); + + StructuralNode orderedList = document.getBlocks().get(0).getBlocks().get(0); + assertThat(orderedList, notNullValue()); + + // Odd – I expected this to send back :'olist' + assertThat(orderedList.getContext(), equalTo("olist")); + + // But can you change it? + + orderedList.setContext("colist"); + + assertThat(orderedList.getContext(), equalTo("colist")); + + } + + private Document loadDocument(String source) { + Attributes attributes = Attributes.builder().sectionNumbers(false).build(); + Options options = Options.builder().attributes(attributes).build(); + return asciiDoctor.load(source, options); + } +}