How to create external link references in AsciiDoc without repeating the URL multiple times?
Asked Answered
L

2

12

In markdown I can write:

[example1][myid]

[example2][myid]

[myid]: http://example.com

so I don't have to retype the full external link multiple times.

Is there an analogous feature in AsciiDoc? Specially interested in the Asciidoctor implementation.

So far I could only find:

  • internal cross references with <<>>
  • I think I saw a replacement feature of type :myid:, but I can't find it anymore. And I didn't see how to use different texts for each link however.
Laughter answered 22/4, 2018 at 19:15 Comment(0)
E
13

I think you are looking for this (and both will work just fine),

https://www.google.com[Google]

or

link: https://google.com[Google]

Reference: Ascii Doc User Manual Link


Update #1: Use of link along with variables in asciidoc

Declare variable

:url: https://www.google.com  

Use variable feature using format mentioned above

  1. Using ' Link with label '

    {url}[Google]
    
  2. Using a relative link

    link:{url}[Google]
    
Exhibitionism answered 11/6, 2018 at 4:3 Comment(6)
I want to not have to type https://google.com multiple times when linking to it multiple times.Laughter
@CiroSantilli新疆改造中心六四事件法轮功 You can use variable feature of asciidoc for this. Please refer the update in the answer on how to do it. You can also try it here by copying the code snippets in the answer.Exhibitionism
This had already been mentioned on the other answer: https://mcmap.net/q/924868/-how-to-create-external-link-references-in-asciidoc-without-repeating-the-url-multiple-timesLaughter
@CiroSantilli新疆改造中心六四事件法轮功 Just a friendly suggestion: If you've had your question answered, you can accept it and let others know this thread has been answered by choosing any one of the answers listed. :)Exhibitionism
Thanks dev, I'm keeping my accepts as a helper for legendary :-)Laughter
This does not work if url has double __ (link).Takeover
C
6

Probably you mean something like this:

Userguide Chapter 28.1. Setting configuration entries

... Attribute entries promote clarity and eliminate repetition URLs and file names in AsciiDoc3 macros are often quite long — they break paragraph flow and readability suffers. The problem is compounded by redundancy if the same name is used repeatedly. Attribute entries can be used to make your documents easier to read and write, here are some examples:

:1:         http://freshmeat.net/projects/asciidoc3/
:homepage:  http://asciidoc3.org[AsciiDoc3 home page]
:new:       image:./images/smallnew.png[]
:footnote1: footnote:[A meaningless latin term]

Using previously defined attributes: See the {1}[Freshmeat summary]
or the {homepage} for something new {new}. Lorem ispum {footnote1}.

...

BTW, there is a 100% Python3 port available now: https://asciidoc3.org

Crash answered 8/5, 2018 at 20:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.