Skip to content

Commit

Permalink
Merge pull request markedjs#178 from tasuk/improve-smartypants
Browse files Browse the repository at this point in the history
Improve smartypants support
  • Loading branch information
chjj committed Aug 2, 2013
2 parents 2b1f28e + e7e9c07 commit be0c323
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/marked.js
Original file line number Diff line number Diff line change
@@ -728,10 +728,12 @@ InlineLexer.prototype.outputLink = function(cap, link) {
InlineLexer.prototype.smartypants = function(text) {
if (!this.options.smartypants) return text;
return text
.replace(/--/g, '\u2014')
.replace(/'([^']*)'/g, '\u2018$1\u2019')
.replace(/"([^"]*)"/g, '\u201C$1\u201D')
.replace(/\.{3}/g, '\u2026');
.replace(/--/g, "\u2014") // em-dashes
.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // opening singles
.replace(/'/g, "\u2019") // closing singles & apostrophes
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201c") // opening doubles
.replace(/"/g, "\u201d") // closing doubles
.replace(/\.{3}/g, '\u2026'); // ellipses
};

/**
4 changes: 4 additions & 0 deletions test/tests/text.smartypants.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<p>Hello world ‘how’ “are” you — today…</p>

<p>“It’s a more ‘challenging’ smartypants test…”</p>

<p>‘And,’ as a bonus — “one<br>multiline” test!</p>
5 changes: 5 additions & 0 deletions test/tests/text.smartypants.text
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Hello world 'how' "are" you -- today...

"It's a more 'challenging' smartypants test..."

'And,' as a bonus -- "one
multiline" test!

0 comments on commit be0c323

Please sign in to comment.