subs="attributes+" by default for code blocks..

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

subs="attributes+" by default for code blocks..

eitan
i'd like to be able to replace attributes everywhere in my document.  but i don't want to have to repeat the subs="attributes+" in every single block i define.  how do i do that?

ditto for other things.  all my images have the [.thumb] decorator.  is there a way to not have to specify it individually for each image, but rather, globally?

thanks in advance,
/ eitan
Reply | Threaded
Open this post in threaded view
|

Re: subs="attributes+" by default for code blocks..

eitan
i'm also curious to know why no substitution of attributes is the default for code blocks.  i can imagine many situations where authors are writing instructions that are parameterized. anyhow..
Reply | Threaded
Open this post in threaded view
|

Re: subs="attributes+" by default for code blocks..

abelsromero
This post was updated on .
Edit: removed the comment since I was miss-interpreting the issue.
Reply | Threaded
Open this post in threaded view
|

Re: subs="attributes+" by default for code blocks..

mojavelinux
Administrator
What we're talking about here is different from https://github.com/asciidoctor/asciidoctor/issues/1061, which I just wrote in a comment.

You're both correct that there's currently no mechanism available in the AsciiDoc source to change the substitutions for a type of block globally. That is something we could add.

However, it is still possible to achieve this using the extension facility. You could use a Treeprocessor to visit every source block and add the attributes substitution to the block. The Treeprocessor executes before substitutions are performed on the block, so it's the perfect opportunity.

You could even program the Treeprocessor so it is driven by the AsciiDoc source. For instance, you can define an attribute in your document named `source-subs` as follows:

:source-subs: attributes+

Then, the Treeprocessor can visit all the source blocks and set the subs just as though subs=attributes+ was set on every block explicitly.

You can do the same thing to apply roles to blocks as well.

I want to end by commenting on why subs=attributes+ isn't, and shouldn't be, the default on verbatim blocks (source, listing, literal). The expectation is that the contents in those blocks is output verbatim. If we started performing substitutions on that content by default, then we'd break the contract and cause unexpected behavior for a lot of users. For instance, Ruby and Groovy source code would get mangled since both uses the syntax {variable} to interpolate strings. (A lesser reason is that it would slow down the processor).

-Dan

On Thu, Feb 16, 2017 at 8:16 AM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I fear there's no way to achieve what you want, but there's a conversation about that in the GitHub repo https://github.com/asciidoctor/asciidoctor/issues/1061, feel free to drop your experiences and suggestions.

I have the same problem with substitutions and it's really annoying. But still I think the current behaviour for code blocks is right, since that's considered a literal rendered in "verbatim" (Verbatim as in here http://asciidoctor.org/docs/user-manual/#built-in-blocks-summary).





If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/subs-attributes-by-default-for-code-blocks-tp5284p5286.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: subs="attributes+" by default for code blocks..

mojavelinux
Administrator
In reply to this post by abelsromero
Keep in mind that while it may be annoying to have to repeat metadata on each block, that information is often semantic so it actually belongs there. I could see where a global setting on the document makes sense, but I would caution from applying it without any reference in the document because then the document doesn't tell the whole story.

If the information is not semantic, and it's just needed for styling the output (i.e., publishing), then I would argue it doesn't belong in the document at all and should be added by a Treeprocessor or a custom converter.

-Dan

On Thu, Feb 16, 2017 at 11:09 AM, Dan Allen <[hidden email]> wrote:
What we're talking about here is different from https://github.com/asciidoctor/asciidoctor/issues/1061, which I just wrote in a comment.

You're both correct that there's currently no mechanism available in the AsciiDoc source to change the substitutions for a type of block globally. That is something we could add.

However, it is still possible to achieve this using the extension facility. You could use a Treeprocessor to visit every source block and add the attributes substitution to the block. The Treeprocessor executes before substitutions are performed on the block, so it's the perfect opportunity.

You could even program the Treeprocessor so it is driven by the AsciiDoc source. For instance, you can define an attribute in your document named `source-subs` as follows:

:source-subs: attributes+

Then, the Treeprocessor can visit all the source blocks and set the subs just as though subs=attributes+ was set on every block explicitly.

You can do the same thing to apply roles to blocks as well.

I want to end by commenting on why subs=attributes+ isn't, and shouldn't be, the default on verbatim blocks (source, listing, literal). The expectation is that the contents in those blocks is output verbatim. If we started performing substitutions on that content by default, then we'd break the contract and cause unexpected behavior for a lot of users. For instance, Ruby and Groovy source code would get mangled since both uses the syntax {variable} to interpolate strings. (A lesser reason is that it would slow down the processor).

-Dan

On Thu, Feb 16, 2017 at 8:16 AM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I fear there's no way to achieve what you want, but there's a conversation about that in the GitHub repo https://github.com/asciidoctor/asciidoctor/issues/1061, feel free to drop your experiences and suggestions.

I have the same problem with substitutions and it's really annoying. But still I think the current behaviour for code blocks is right, since that's considered a literal rendered in "verbatim" (Verbatim as in here http://asciidoctor.org/docs/user-manual/#built-in-blocks-summary).





If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/subs-attributes-by-default-for-code-blocks-tp5284p5286.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: subs="attributes+" by default for code blocks..

eitan
thank you for the very informative reply and for pointing me to a solution! / eitan