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;
+104 -4
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+3
View File
@@ -18,6 +18,9 @@
<h2>A description of the article</h2>
<dt-byline></dt-byline>
<p>This is the first paragraph of the article.</p>
<p>Test a long&thinsp;&mdash;&thinsp;dash -- here it is.</p>
<p>Test for owner's possessive.</p>
<p>Test for "quoting a passage." And another sentence. Or two.</p>
<p>We can also cite <dt-cite key="gregor2015draw,mercier2011humans"></dt-cite> external publications. <dt-cite key="dong2014image,dumoulin2016guide,mordvintsev2015inceptionism"></dt-cite></p>
</dt-article>
+6 -4
View File
@@ -13,6 +13,7 @@ import citation from "./components/citation";
import footnote from "./components/footnote";
import markdown from "./components/markdown";
import code from "./components/code";
import typeset from "./components/typeset";
import hoverBox from "./components/hover-box-include";
import generateCrossref from "./components/generate-crossref";
@@ -34,10 +35,11 @@ function renderOnLoad(dom, data) {
code(dom, data);
citation(dom, data);
footnote(dom, data);
typeset(dom, data);
hoverBox(dom, data);
}
// If we are in a browser, render automatically.
// If we are in a browser, render automatically...
if(window && window.document) {
let data = {};
renderImmediately(window.document);
@@ -51,13 +53,13 @@ if(window && window.document) {
});
}
// For node
// If we are in node...
function render(dom, data) {
renderImmediately(dom);
renderOnLoad(dom, data);
// Remove script tag so it doesn't run again
// Remove script tag so it doesn't run again in the client
let s = dom.querySelector('script[src="http://distill.pub/template.js"]');
if (s) { s.parentElement.removeChild(s); }
if (s) { s.parentElement.removeChild(s); };
}
export {render as render};