0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Improving underscore handling

Additional changes to how underscores are handled.
This more closely matches codemirror, but is still not 100%.
This commit is contained in:
Hannah Wolfe 2013-09-04 12:53:40 +01:00
parent 21487aa802
commit c45f911a1e
2 changed files with 10 additions and 2 deletions

View file

@ -33,8 +33,9 @@
return "{gfm-js-extract-pre-" + hash + "}";
}, 'm');
// prevent foo_bar_baz from ending up with an italic word in the middle
text = text.replace(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/gm, function (x) {
//prevent foo_bar and foo_bar_baz from ending up with an italic word in the middle
text = text.replace(/(^(?! {4}|\t)\w+_\w[\w_]*)/gm, function (x) {
return x.replace(/_/gm, '\\_');
});

View file

@ -29,6 +29,13 @@ describe("Showdown client side converter", function () {
processedMarkup.should.match(testPhrase.output);
});
it("should not create italic words between lines", function () {
var testPhrase = {input: "foo_bar\nbar_foo", output: /^<p>foo_bar <br \/>\nbar_foo<\/p>$/},
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
});
it("should not touch underscores in code blocks", function () {
var testPhrase = {input: " foo_bar_baz", output: /^<pre><code>foo_bar_baz\n<\/code><\/pre>$/},
processedMarkup = converter.makeHtml(testPhrase.input);