asciidoctor / atom-language-asciidoc

⚛ AsciiDoc language package for the Atom editor.
https://atom.io/packages/language-asciidoc
MIT License
42 stars 20 forks source link

feat: url with attributes references #122

Closed ldez closed 8 years ago

ldez commented 8 years ago

Description

Use attributes references with url

Syntax example

{uri-repo}[Asciidoctor]
[{uri-repo}[Asciidoctor]
({uri-repo}[Asciidoctor]
<{uri-repo}[Asciidoctor]
>{uri-repo}[Asciidoctor]
foo {uri-repo}[Asciidoctor] bar

link:http://{uri-repo}[label]
[link:{uri-repo}[label]
(link:{uri-repo}[label]
<link:{uri-repo}[label]
>link:{uri-repo}[label]
foo link:{uri-repo}[label] bar
Go on link:https://foobar.com now

http://foo{uri-repo}bar.com
<http://foobar.com[foobar]
>http://foobar.com[foobar]
(http://foobar.com[foobar]
[http://foobar.com[foobar]
foo http://foobar.com[foobar] bar

Screenshots

capture du 2016-05-14 17-26-19

mojavelinux commented 8 years ago

This is a great example of where the grammar sees something that the parser never does. By the time the parser sees the link, the attribute has been resolved. But to the writer, the attribute is part of the URL.

I'd like to propose a slight modification. I'd like to see the uri- prefix required in order to make this match (e.g., {uri-google}[Google]). That does two things. First, it promotes the best practice of adding the uri- prefix to the name of a URI attribute. Second, it cuts out the ambiguity of matching the pattern {foo}[Bar] when it is not a link.

mojavelinux commented 8 years ago

When the explicit link: prefix is specified, then we can assume it is always a link (e.g., link:{foo}[Bar]).

ldez commented 8 years ago

Done!

mojavelinux commented 8 years ago

I love it!

ldez commented 8 years ago

small bonus: attribute multi-lines who respect the line-break :wink:

capture du 2016-05-16 23-52-39

mojavelinux commented 8 years ago

Sweet like :candy: !

mojavelinux commented 8 years ago

small bonus: attribute multi-lines who respect the line-break

...actually, I almost missed it. In Asciidoctor, we now prefer a backslash (\) instead of a plus (+) at the end of the line (like Bash). Could you switch it?

Asciidoctor also supports a hardbreak by using + \ at the end of the line. Example:

:address: Street + \
City, State ZIP

{address}
ldez commented 8 years ago

Supports backslash line-break and backslash hard-break.

capture du 2016-05-19 19-47-41

mojavelinux commented 8 years ago

:+1:

nicorikken commented 8 years ago

So @ldez if I understand it correctly, your wizardry fix is to have a very generic begin-end match, and only include line breaks with continuation characters, next to the inline styles? Very clever. This will be something to watch out for when we work on multi-line inlines like bold and italics ⚠️ because in paragraphs line-continuation will be handled differently:

:description: test *failing
multi-line*
:description: test *succeeding \
multi-line*

I guess we're going to need a separate library (include) for multi-line inline styles, to enable this type of line continuation in other parts.

Oh and by the way 😉 nice work on the URL matching. I assume you are going to pick up on the uri- suggestion?

ldez commented 8 years ago

The uri- suggestion is already done :wink:

nicorikken commented 8 years ago

My bad, I assumed it was emphasised in highlighting. Reading back I now see it was about restricting the regex. Alright then. LGTM