On 17 September 2013 10:45, Dan Allen <[email protected]> wrote: > Replacing inline macros is a tricky thing, perhaps not even possible. You > can define additional matches, but they can't overlap with matches already > made (since the substitution will have already occurred). > > The best I can seem to do is look for a number in round brackets behind an > optional line comment. > > Here's an example of how it would look: > > [source,ruby] > -- > puts "Hello, World!" # (1) > -- > <1> Prints to the console > > Here's the macro definition (similar to Lex's but changed to match round > brackets since the numbers in angled brackets have already been taken away) > > [macros] > (?://|#|;;) ?\((?P<index>\d+)\)=callout >
Oops I left out [macros], thanks Dan, I'm not at a machine with Asciidoc ATM to test it :) The only note is that this needs to be *exactly* as specified, the space and all, so to use it with other content in the comment you need to put essentially a second comment inside the comment. > That accommodates line comments in C-style languages (//), scripting > languages (#) and lisps (;;). > > On Mon, Sep 16, 2013 at 6:24 PM, Lex Trotman <[email protected]> wrote: > >> >> On 17 September 2013 02:33, Matthew Adams <[email protected]>wrote: >> >>> Hi, >>> >>> Late to the party. >>> >>> I noticed the same thing, and would like to know if there's a way for >>> asciidoc to see patterns like "//<1>" and render *only* the code >>> callout number instead of the "//" plus the code callout number. >>> >> >> It should not be changed in Asciidoc itself since not all languages use >> // for comments. >> > > I think it should. AsciiDoc should recognize well-known line comment > characters and strip them away because callouts that aren't behind line > comments cause compile errors in the code. > The problem is what is "well known", for eg /* in C, and then you have to remove the */, some lisp idioms use more than two semicolons for some meaning, various other comment structures exist. To accommodate them, a version without the comment characters which falls back to the original behaviour is needed. And the more variations of comment are acceptable, the more possibility there is that something will match part of the code, nearly any combination of characters is likely to be legal Perl for example :) And of course you are also setting yourself up for bug reports "asciidoctor doesn't support <language> callouts" :) Cheers Lex > > I've implemented line comment detection for callouts in Asciidoctor and > it's proven to be a very popular addition. It makes callouts "code > friendly". > > ...as a compromise, one way we could implement this without causing > breakage is to add an attribute that specifies a comma-separated list of > line comment "leaders", by default empty. These characters will be captured > and discarded when they appear in front of line comments. Taking this > approach, the risk of breaking existing documents is reduced to 0. > > -Dan > > -- > You received this message because you are subscribed to the Google Groups > "asciidoc" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/asciidoc. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "asciidoc" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/asciidoc. For more options, visit https://groups.google.com/groups/opt_out.
