Closed nicorikken closed 8 years ago
Very nice addition!
In the future, I look forward to being able to do this with the AST (once it includes the inline nodes). Any time we have to parse the HTML output, I consider that to be the sign that we are missing a hook or callback in the model.
Another approach here is to provide a custom template that converts the inline_anchor node. That way, you actually get a chance to process the link as it is being generated. Unfortunately, we don't tag e-mail links, though it's easy enough to check for start_with? 'mailto:'
I suppose.
Asciidoctor itself doesn't seem to be handling this correctly
Asciidoctor should definitely be handling Unicode 100% in general. Can you cite a case that isn't working. For instance, I get the correct output when I run:
$ echo 'björn.nußbaum@trouble.org' | asciidoctor -o - -s -
International characters in the e-mail address work fine for me. Keep in mind, however, that JavaScript has serious problems working with international characters, and it varies by browser, so that could be the culprit.
That's why XRegExp is always recommended when working with international characters in JavaScript (even if you only use it at build time to generate a complaint, low-level regexp).
This line could also be a problem:
email = $1.tr 'A-Za-z','N-ZA-Mn-za-m'
I don't know if tr
supports international ranges.
In trying to find an Asciidoctor native solution for obfuscating
mailto:
links, I came across the https://github.com/amsardesai/middleman-protect-emails project and decided to port it as an Asciidoctor extension. The source project is MIT licensed.Known issues:
mailto:
content not intended as a link will still be replaced. The most simple fix would be to test for the<a ></a>
context, neglecting any higher levels of HTML nesting.I consider expanding this obfuscation to other addresses like XMPP, or maybe certain URL's, but they are generally less prone to spamming.
Other methods of obfuscation concern the rendering, which can bring issues to the stylesheets.