- *
- */
-showdown.subParser('encodeEmailAddress', function (addr) {
- 'use strict';
-
- var encode = [
- function (ch) {
- return '' + ch.charCodeAt(0) + ';';
- },
- function (ch) {
- return '' + ch.charCodeAt(0).toString(16) + ';';
- },
- function (ch) {
- return ch;
- }
- ];
-
- addr = 'mailto:' + addr;
-
- addr = addr.replace(/./g, function (ch) {
- if (ch === '@') {
- // this *must* be encoded. I insist.
- ch = encode[Math.floor(Math.random() * 2)](ch);
- } else if (ch !== ':') {
- // leave ':' alone (to spot mailto: later)
- var r = Math.random();
- // roughly 10% raw, 45% hex, 45% dec
- ch = (
- r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
- );
- }
- return ch;
- });
-
- addr = '' + addr + '';
- addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part
-
- return addr;
-});
diff --git a/test/features/disable-email-encoding.html b/test/features/disable-email-encoding.html
new file mode 100644
index 0000000..21e2731
--- /dev/null
+++ b/test/features/disable-email-encoding.html
@@ -0,0 +1 @@
+this email foobar@example.com should not be encoded
diff --git a/test/features/disable-email-encoding.md b/test/features/disable-email-encoding.md
new file mode 100644
index 0000000..80fb6e8
--- /dev/null
+++ b/test/features/disable-email-encoding.md
@@ -0,0 +1 @@
+this email should not be encoded
diff --git a/test/node/showdown.helpers.js b/test/node/showdown.helpers.js
new file mode 100644
index 0000000..ec9fa21
--- /dev/null
+++ b/test/node/showdown.helpers.js
@@ -0,0 +1,30 @@
+/**
+ * Created by Estevao on 27/01/2017.
+ */
+
+var bootstrap = require('../bootstrap.js'),
+ showdown = bootstrap.showdown,
+ encoder = showdown.helper.encodeEmailAddress;
+
+describe('encodeEmailAddress', function () {
+ 'use strict';
+ var email = 'foobar@example.com',
+ encodedEmail = encoder(email);
+
+ it('should encode email', function () {
+ encodedEmail.should.not.equal(email);
+ });
+
+ it('should decode to original email', function () {
+ var decodedEmail = encodedEmail.replace(/(.+?);/g, function (wm, cc) {
+ if (cc.charAt(0) === 'x') {
+ //hex
+ return String.fromCharCode('0' + cc);
+ } else {
+ //dec
+ return String.fromCharCode(cc);
+ }
+ });
+ decodedEmail.should.equal(email);
+ });
+});
diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js
index c25aa6a..f2bccc0 100644
--- a/test/node/testsuite.features.js
+++ b/test/node/testsuite.features.js
@@ -53,6 +53,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({ghCompatibleHeaderId: true});
} else if (testsuite[i].name === 'ghMentions') {
converter = new showdown.Converter({ghMentions: true});
+ } else if (testsuite[i].name === 'disable-email-encoding') {
+ converter = new showdown.Converter({encodeEmails: false});
} else {
converter = new showdown.Converter();
}