asciidoctor
asciidoctor copied to clipboard
Make Raw Content available for titles and content-parts
When accessing the title of a document or section it is already rendered to HTML (I found an unrendered version in the attributes)
The same is true for ContentPart content, so I cannot access the original text. Which is important if for instance that content is code that I want to run :)
The discussion should be about the APIs.
I could imagine, like in doucument.getTitle() that you get an (lazily populated) Content-object back that has methods like:
- getAsciiDoc() / getRaw()
- getHtml() / getRendered()
- there could be additional metadata attached to that "content-object"
The reason this is a challenge is because we want to keep the converters / backends simply by allowing the call to node.title. At one point, I considered adding node.raw_title, but it felt very hackish.
As for the content, you can access that already using several methods:
- lines (returns array of raw source lines)
- source (returns string of raw source lines)
These just aren't mapped right in AsciidoctorJ.
I think the only time we are converting on access is the title.
The open question is, what should the API look like to get the raw title instead of the converted title? Perhaps it should be something like "metadata" which would contain the raw title source.
I will open an issue to AsciidoctorJ to implement these missing methods.
2014-10-13 9:46 GMT+02:00 Dan Allen [email protected]:
The reason this is a challenge is because we want to keep the converters / backends simply by allowing the call to node.title. At one point, I considered adding node.raw_title, but it felt very hackish.
As for the content, you can access that already using several methods:
- lines (returns array of raw source lines)
- source (returns string of raw source lines)
These just aren't mapped right in AsciidoctorJ.
I think the only time we are converting on access is the title.
The open question is, what should the API look like to get the raw title instead of the converted title? Perhaps it should be something like "metadata" which would contain the raw title source.
— Reply to this email directly or view it on GitHub https://github.com/asciidoctor/asciidoctor/issues/1146#issuecomment-58857231 .
+----------------------------------------------------------+ Alex Soto Bueno - Computer Engineer www.lordofthejars.com +----------------------------------------------------------+
Thanks @lordofthejars!
We have the same problem with ListItem. There needs to be a way to access to read the raw text.
For now, this content can be accessed using instance_variable_get. For example:
list_item = ...
list_item.instance_variable_get :@text
We just need to work out the public API.
This came up again, and it got me thinking that the right terminology might be title_source (for regular blocks) and text_source (for list items). That is parallel with source, which gives you the source of a delimited block (without the delimiter lines). Another possible name would be title_line and text_line, respectively, but I'm less convinced about that. Either way, I don't really like the term "raw".
It would be very convenient, and I would need this feature too, to resolve https://github.com/Alwinator/asciidoctor-lists/issues/6
Looking at the existing API closer, now I'm thinking that source_text for a list item and source_title (or source_line) for a heading/block title would be more fitting.
This has become a duplicate of #4386 (and vice versa).