Skip to content

Commit

Permalink
Enable showdown's literalMidWordUnderscores
Browse files Browse the repository at this point in the history
This stops showdown from interpreting underscores in the middle of words
as <em> and <strong>, instead it treats them as literal underscores.

Example:

some text with__underscores__in middle

will be parsed as

<p>some text with__underscores__in middle</p>

Fixes #2598 (URLs with _'s in them were getting <em> tags inserted into
them, breaking the links).

Also see <showdownjs/showdown#211>.
  • Loading branch information
seanh committed Dec 15, 2015
1 parent f012477 commit e81ce9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion h/static/scripts/filter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ module.exports = function () {
// see https://github.com/showdownjs/showdown#valid-options
var converter = new showdown.Converter({
extensions: [targetBlank],
simplifiedAutoLink: true
simplifiedAutoLink: true,
// Since we're using simplifiedAutoLink we also use
// literalMidWordUnderscores because otherwise _'s in URLs get
// transformed into <em>'s.
// See https://github.com/showdownjs/showdown/issues/211
literalMidWordUnderscores: true,
});
return converter.makeHtml.bind(converter);
};
10 changes: 10 additions & 0 deletions h/static/scripts/filter/test/converter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ var converter = require('../converter');

describe('markdown converter', function () {
var markdownToHTML = converter();

it('should autolink URLs', function () {
assert.equal(markdownToHTML('See this link - http://arxiv.org/article'),
'<p>See this link - <a target="_blank" href="http://arxiv.org/article">' +
'http://arxiv.org/article</a></p>');
});

it('should autolink URLs with _\'s in them correctly', function () {
assert.equal(
markdownToHTML(
'See this https://hypothes.is/stream?q=tag:group_test_needs_card'),
'<p>See this <a target="_blank" ' +
'href="https://hypothes.is/stream?q=tag:group_test_needs_card">' +
'https://hypothes.is/stream?q=tag:group_test_needs_card</a></p>');
});
});

0 comments on commit e81ce9e

Please sign in to comment.