Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved context functions to ContentNode #1250

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Bug Fixes::

Improvement::

* Add `setContext` function to StructuralNode.

* 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface ContentNode {

String getContext();
RayOffiah marked this conversation as resolved.
Show resolved Hide resolved

void setContext(String context);

Document getDocument();

boolean isInline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public String getContext() {
return getString("context");
}

@Override
public void setContext(String context) {
setString("context", context);

}

@Override
public ContentNode getParent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.jupiter.api.Test;

import static org.assertj.core.api.Assertions.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).isNotNull();
assertThat(document.getBlocks().size()).isEqualTo(1);

StructuralNode orderedList = document.getBlocks().get(0).getBlocks().get(0);
assertThat(orderedList).isNotNull();

// Odd – I expected this to send back :'olist'
assertThat(orderedList.getContext()).isEqualTo("olist");

// But can you change it?

orderedList.setContext("colist");

assertThat(orderedList.getContext()).isEqualTo("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);
}
}