Polish on typo subs

This commit is contained in:
Shan Carter
2017-02-03 16:54:39 -08:00
parent 1995d75cb0
commit 19da5e90c4
5 changed files with 123 additions and 16 deletions
+9 -7
View File
@@ -12,6 +12,9 @@ export default function(dom, data) {
node.nodeName !== "PRE" &&
node.nodeName !== "SPAN" &&
node.nodeName !== "DT-HEADER" &&
node.nodeName !== "DT-BYLINE" &&
node.nodeName !== "DT-MATH" &&
node.nodeName !== "DT-CODE" &&
node.nodeName !== "DT-BIBLIOGRAPHY" &&
node.nodeName !== "DT-FOOTER" &&
node.nodeType !== 8 && //comment nodes
@@ -19,14 +22,13 @@ export default function(dom, data) {
}
}
);
while (textNodes.nextNode()) {
var n = textNodes.currentNode,
text = n.nodeValue;
if (n.nodeType === 3 && text) {
quotes(text);
punctuation(text);
ligatures(text);
text = quotes(text);
text = punctuation(text);
text = ligatures(text);
n.nodeValue = text;
}
}
@@ -46,14 +48,14 @@ export default function(dom, data) {
function punctuation(text){
// Dashes
text = text.replace(/--/g, '');
text = text.replace(/ /g,' — ');
text = text.replace(/--/g, '\u2014');
text = text.replace(/ \u2014 /g,"\u2009\u2014\u2009"); //this has thin spaces
// Elipses
text = text.replace(/\.\.\./g,'…');
// Nbsp for punc with spaces
var NBSP = ' ';
var NBSP = "\u00a0";
var NBSP_PUNCTUATION_START = /([«¿¡]) /g;
var NBSP_PUNCTUATION_END = / ([\!\?:;\.,‽»])/g;