-
Notifications
You must be signed in to change notification settings - Fork 172
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
Unable to modify imagesdir
from Treeprocessor
#547
Comments
IIRC the TreeProcessor is called after the document is loaded, so after all other block processors and attribute replacements have already taken place. But this is from the top of my head as I am currently behind a small screen, so could be wrong. |
Could be it can't be done in an easy way? I tried with Preprocessor, but then the document hasn't not been parsed and I have no nice access to the AST.
Take a rest. I am just doing this for fun. |
The following works in Ruby: require 'asciidoctor/extensions'
Asciidoctor::Extensions.register do
treeprocessor do
process do |doc|
doc.set_attr 'imagesdir', 'img'
doc
end
end
end Keep in mind that there is a difference between |
Modifying the attribute (with In any case, I am aware I am going against some of the principles of the tool. And my curiosity is satisfied, thank you both for enduring me. |
Okay, I see what you're trying to do. You want to modify the path for a specific image. That's not something that's really supported at the moment. You can modify the target, but that is still combined with the document-level imagesdir. This is a limitation of core I've hit myself. I've wanted to set the imagesdir used for a specific image. We could consider allowing imagesdir to be set as an attribute on the image node. That would require a change to the image_uri helper here: https://github.com/asciidoctor/asciidoctor/blob/7c433c0688edb09a7652c4620b460d24951ca331/lib/asciidoctor/abstract_node.rb#L330-L348 Either way, this is a change to core. |
Alternatively, we could add an attribute that marks the target as resolved so it doesn't get combined with imagesdir. |
Another solution is go through all the images in the document and set the target to a resolved value, then unset imagesdir on the document, then update the target of the image you want. That would work today. |
Just as an excercise, I am trying to build an extension that:
But I found that setting the attribute in the block or the parent, does not update the attribute (see).
I can however update the target with the same code, so I assume the
setAttr
method works.Afaik, updating the parent should be equivalent to defining the attribute in the block in the AsciiDoc document, which I did and works.
So, is this an issue or I am doing something wrong?
Other minor things:
org.jruby.exceptions.RaiseException: (SystemCallError) Unknown error 123 - FindFirstFile
with 1.6.0-alpha.3 (using jRuby 9.1.8.0)The text was updated successfully, but these errors were encountered: