asciidoctor / asciidoctor-extensions-lab

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.
Other
104 stars 101 forks source link

feat: middleman-protect-emails port #70

Closed nicorikken closed 8 years ago

nicorikken commented 8 years ago

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:

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.

mojavelinux commented 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 -
mojavelinux commented 8 years ago

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.

mojavelinux commented 8 years ago

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).

mojavelinux commented 8 years ago

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.