From 1995d75cb0d66f63ea7007da1ba5960d05f43e7f Mon Sep 17 00:00:00 2001 From: Shan Carter Date: Fri, 3 Feb 2017 15:40:11 -0800 Subject: [PATCH] Adding columns and typo subs --- components/styles-layout.css | 18 +++++++ components/typeset.js | 96 ++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 components/typeset.js diff --git a/components/styles-layout.css b/components/styles-layout.css index 1ce3cd8..bd63ce5 100644 --- a/components/styles-layout.css +++ b/components/styles-layout.css @@ -333,3 +333,21 @@ dt-article section > dt-code { } } + +/* Rows and Columns */ + +.row { + display: flex; +} +.column { + flex: 1; + box-sizing: border-box; + margin-right: 24px; + margin-left: 24px; +} +.row > .column:first-of-type { + margin-left: 0; +} +.row > .column:last-of-type { + margin-right: 0; +} diff --git a/components/typeset.js b/components/typeset.js new file mode 100644 index 0000000..c8e84d2 --- /dev/null +++ b/components/typeset.js @@ -0,0 +1,96 @@ +export default function(dom, data) { + + var textNodes = dom.createTreeWalker( + dom.body, + NodeFilter.ALL_ELEMENTS, + { + acceptNode: function(node) { + var isMath = (node.getAttribute && node.getAttribute("class")) ? node.getAttribute("class").includes("katex") || node.getAttribute("class").includes("MathJax") : false; + return node.nodeName !== "SCRIPT" && + node.nodeName !== "STYLE" && + node.nodeName !== "CODE" && + node.nodeName !== "PRE" && + node.nodeName !== "SPAN" && + node.nodeName !== "DT-HEADER" && + node.nodeName !== "DT-BIBLIOGRAPHY" && + node.nodeName !== "DT-FOOTER" && + node.nodeType !== 8 && //comment nodes + !isMath; + } + } + ); + + while (textNodes.nextNode()) { + var n = textNodes.currentNode, + text = n.nodeValue; + if (n.nodeType === 3 && text) { + quotes(text); + punctuation(text); + ligatures(text); + n.nodeValue = text; + } + } +} + + +/*! + * typeset - Typesetting for the web + * @version v0.1.6 + * @link https://github.com/davidmerfield/Typeset.js + * @author David Merfield + */ + // which has a CC0 license + // http://creativecommons.org/publicdomain/zero/1.0/ + + +function punctuation(text){ + + // Dashes + text = text.replace(/--/g, '–'); + text = text.replace(/ – /g,' — '); + + // Elipses + text = text.replace(/\.\.\./g,'…'); + + // Nbsp for punc with spaces + var NBSP = ' '; + var NBSP_PUNCTUATION_START = /([«¿¡]) /g; + var NBSP_PUNCTUATION_END = / ([\!\?:;\.,‽»])/g; + + text = text.replace(NBSP_PUNCTUATION_START, '$1' + NBSP); + text = text.replace(NBSP_PUNCTUATION_END, NBSP + '$1'); + + return text; +} + +function quotes(text) { + + text = text + .replace(/(\W|^)"([^\s\!\?:;\.,‽»])/g, '$1\u201c$2') // beginning " + .replace(/(\u201c[^"]*)"([^"]*$|[^\u201c"]*\u201c)/g, '$1\u201d$2') // ending " + .replace(/([^0-9])"/g,'$1\u201d') // remaining " at end of word + .replace(/(\W|^)'(\S)/g, '$1\u2018$2') // beginning ' + .replace(/([a-z])'([a-z])/ig, '$1\u2019$2') // conjunction's possession + .replace(/((\u2018[^']*)|[a-z])'([^0-9]|$)/ig, '$1\u2019$3') // ending ' + .replace(/(\u2018)([0-9]{2}[^\u2019]*)(\u2018([^0-9]|$)|$|\u2019[a-z])/ig, '\u2019$2$3') // abbrev. years like '93 + .replace(/(\B|^)\u2018(?=([^\u2019]*\u2019\b)*([^\u2019\u2018]*\W[\u2019\u2018]\b|[^\u2019\u2018]*$))/ig, '$1\u2019') // backwards apostrophe + .replace(/'''/g, '\u2034') // triple prime + .replace(/("|'')/g, '\u2033') // double prime + .replace(/'/g, '\u2032'); + + // Allow escaped quotes + text = text.replace(/\\“/, '\"'); + text = text.replace(/\\”/, '\"'); + text = text.replace(/\\’/, '\''); + text = text.replace(/\\‘/, '\''); + + return text; +} + +function ligatures(text){ + + text = text.replace(/fi/g, 'fi'); + text = text.replace(/fl/g, 'fl'); + + return text; +};