Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typographic switch #573

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,19 +710,8 @@ InlineLexer.prototype.outputLink = function(cap, link) {

InlineLexer.prototype.smartypants = function(text) {
if (!this.options.smartypants) return text;
return text
// em-dashes
.replace(/--/g, '\u2014')
// opening singles
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
// closing singles & apostrophes
.replace(/'/g, '\u2019')
// opening doubles
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
// closing doubles
.replace(/"/g, '\u201d')
// ellipses
.replace(/\.{3}/g, '\u2026');
var smartypants = require('./smartypants');
return smartypants(text);
};

/**
Expand Down
21 changes: 21 additions & 0 deletions lib/smartypants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var compose = require('fn-compose');

var ellipses = require('typographic-ellipses');
var singleSpaces = require('typographic-single-spaces');

var apostrophes = require('typographic-apostrophes');
var quotes = require('typographic-quotes');
var apostrophesForPlurals = require('typographic-apostrophes-for-possessive-plurals');

var endashes = require('typographic-en-dashes');
var emdashes = require('typographic-em-dashes');

module.exports = compose(
apostrophes,
quotes,
apostrophesForPlurals,
endashes,
emdashes,
ellipses,
singleSpaces
);
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@
"showdown": "*",
"robotskirt": "*"
},
"dependencies": {
"fn-compose": "^1.0.0",
"typographic-apostrophes": "^1.0.0",
"typographic-apostrophes-for-possessive-plurals": "^1.0.0",
"typographic-ellipses": "^1.0.8",
"typographic-em-dashes": "^1.0.0",
"typographic-en-dashes": "^1.0.0",
"typographic-quotes": "^1.0.2",
"typographic-single-spaces": "^1.0.0"
},
"scripts": { "test": "node test", "bench": "node test --bench" }
}
4 changes: 2 additions & 2 deletions test/new/text.smartypants.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>Hello world how “are” youtoday…</p>
<p>Hello world how “are” you — today…</p>

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

<p>And, as a bonus“one
<p>And, as a bonus — “one
multiline” test!</p>
4 changes: 2 additions & 2 deletions test/tests/text.smartypants.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>Hello world how “are” youtoday…</p>
<p>Hello world how “are” you — today…</p>

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

<p>And, as a bonus“one
<p>And, as a bonus — “one
multiline” test!</p>