Skip to content

Commit

Permalink
Add methods Reader.getSource and Reader.getSourceLines (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpanzer committed Mar 3, 2024
1 parent 33e950b commit cf10c14
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co

== Unreleased

Improvement::

* Add Reader.getSource() and Reader.getSourceLines() (#1262)

== 2.5.10 (2023-12-20)

Improvement::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ public interface Reader {

List<String> lines();

/**
* Returns the source lines for this Reader joined as a String
* @return The source lines for this Reader joined as a String
*/
String getSource();

/**
* Get the document source as a List of Strings.
* @return the document source as a List of Strings.
*/
List<String> getSourceLines();

/**
* Push the String line onto the beginning of the Array of source data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public List<String> lines() {
return getList("lines", String.class);
}

@Override
public String getSource() {
return getString("source");
}

@Override
public List<String> getSourceLines() {
return getList("source_lines", String.class);
}

@Override
public void restoreLine(String line) {
getRubyProperty("unshift_line", line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,26 @@ $secondLine"""
preprocessorCalled.get()
}

def 'should be able to get source and source lines'() {
given:

String source = ''
List<String> sourceLines = []

asciidoctor.javaExtensionRegistry().preprocessor(new Preprocessor() {
@Override
void process(Document doc, PreprocessorReader reader) {
source = reader.source
sourceLines = reader.sourceLines
}
})

when:
asciidoctor.convert(document, OptionsBuilder.options())

then:
source == document
sourceLines == [firstLine, secondLine]
}

}

0 comments on commit cf10c14

Please sign in to comment.