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

Add methods Reader.getSource and Reader.getSourceLines #1264

Merged
merged 3 commits into from
Mar 3, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Improvement::
* Remove deprecated methods from ast package (#1204) (@abelsromero)
* Add Automatic-Module-Name manifest entry to core, api, and cli for reserving stable JPMS module names (#1240) (@leadpony)
* Remove Java 'requires open access' module warning in modern Java versions (#1246)
* Add Reader.getSource() and Reader.getSourceLines() (#1262)

Bug Fixes::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public interface Reader {
*/
List<String> getLines();

/**
* 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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public List<String> getLines() {
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 @@ -175,4 +175,27 @@ $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
Reader process(Document doc, PreprocessorReader reader) {
source = reader.source
sourceLines = reader.sourceLines
reader
}
})

when:
asciidoctor.convert(document, emptyOptions())

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

}
Loading