Comments (9)
In truth, the preprocessor extension should never be used to read lines from the reader (unless they are lines that proceed the start of the AsciiDoc document, such as front matter). Although the prepreprocessor was originally designed to allow this use case, we learned after implementing it that it causes side effects that cannot be easily worked around.
The main issue is that when you read lines from the reader in a preprocessor, it blows by the header without processing it. This means it starts processing lines without considering any attributes defined in the document header. Although there's way to do this correctly, it requires a lot of extra code and that code ends up taking on parsing responsibilities. Only someone who is deeply familiar with how AsciiDoc parsed should attempt to do something like this.
The preprocessor can be used as an event listener and can safely modify options and attributes on the document. However, it should never read lines from the reader (except for front matter lines, as already mentioned).
from asciidoctorj.
even using lines() only patially works as the preprocessor extension is only called on the main document but not on any included documents.
lines is just the raw AsciiDoc source split into lines. It's safe to look at it. And that method is not partially working. It's doing exactly what it is supposed to do, which is to return the source of the current document. The source doesn't know anything about includes and thus isn't going to give you those documents.
The readLines
method is what starts to invoke the preprocessor and that's what you should avoid.
from asciidoctorj.
I'm sorry I was unclear.
I didn't meant lines()
per-se is only partially working.
What I meant was, that even with using lines()
you cannot achieve what you want as the preprocessor only gets called for the main document but not for included documents.
At least that is what I observed. :-)
from asciidoctorj.
The current Preprocessor API in AsciidoctorJ unfortunately requires to work on the Reader that was passed as an argument.
Only the next major version of AsciidoctorJ will support creating a new reader from arbitrary content, and returning it from the Preprocessor.
Since this is a breaking change to the API this can only come in a major release.
Since there were complaints about breaking changes in a major release, I have no idea atm when I will be able to resolve this and create a new major release.
from asciidoctorj.
What I meant was, that even with using lines() you cannot achieve what you want as the preprocessor only gets called for the main document but not for included documents.
...and again, because it's not supposed to. The lines()
method is returning the (remaining) raw source lines of the original document. The preprocessor, nor it's reader, should be doing anything with include directives. It's just giving you back the original document. See https://github.com/asciidoctor/asciidoctor/blob/main/lib/asciidoctor/reader.rb#L511-L516
From my perspective, no change is needed to AsciidoctorJ. We are simply discussing how Asciidoctor works.
from asciidoctorj.
I did notice that the Reader in AsciidoctorJ does not have methods for getSource() and getSourceLines(), which is truly the raw source and not just the remaining lines. Those should probably be added, though that's a separate issue.
from asciidoctorj.
the preprocessor only gets called for the main document but not for included documents.
...and a preprocessor is not called for included files because they are not themselves documents. The only time the preprocessor is called is just before the input document is parsed. It has no relationship to includes.
from asciidoctorj.
From my perspective, no change is needed to AsciidoctorJ. We are simply discussing how Asciidoctor works.
Yes, this issue is only about improving the documentation, not about changing the implementation. :-)
...and a preprocessor is not called for included files because they are not themselves documents.
Maybe this could also be changed with the changes @robertpanzer mentioned. :-)
Included files might themselves be documents or not, depends on the include.
But once the preprocessor is more what the term suggests so that you can actually preprocess and modify the input to the parser, it would be great if it would also work on included files, otherwise it again is much less useful than it could be. :-)
from asciidoctorj.
it would be great if it would also work on included files
That's what the include processor is for, not the preprocessor.
from asciidoctorj.
Related Issues (20)
- included jruby version is vulnerable due to snakeyaml dependency HOT 3
- release 3.0.0-alpha.1 is gravely incompatible with earlier releases HOT 11
- 'UnsupportedOperationException' when passing immutable Map as options to 'createPhraseNode' HOT 1
- Use always latest versions in distribution HOT 3
- Ensure AsciidoctorJ version is returned always in CLI
- exception containing itself as nested exception, causing maven endless loop HOT 7
- feature request: render asciidoc to markdown HOT 3
- -s CLI option should be changed to -e to align with Asciidoctor
- Automatic-Module-Name is undefined in MANIFEST file HOT 4
- CLI should set :mkdirs option by default HOT 7
- Custom Macro HOT 1
- setContext not exposed in API HOT 1
- Include processor with all attributes resolution HOT 2
- highlight.js version 9 used by AsciiDoctorJ needs update as it is out of support HOT 2
- problem parsing latex equation to pdf or epub files HOT 3
- Invalid 'backend' attribute HOT 2
- An error occurred when creating an instance of 'asciidoctor' while running the program on Azure Service[Web App]. HOT 2
- `Column#setWidth` is ignored HOT 3
- Unknown style for listing block: mermaid HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asciidoctorj.