diff --git a/cli.js b/cli.js index 5ccc0d7..bc728f7 100755 --- a/cli.js +++ b/cli.js @@ -24,7 +24,7 @@ require("yargs") (argv) => { fs.src(argv.files) .pipe(map(tokenize)) - .pipe(map(toHTML({css: argv["css"]}))) + .pipe(map(toHTML({ css: argv["css"] }))) .pipe(fs.dest((file) => path.dirname(file.path))); } ) diff --git a/to-html.js b/to-html.js index 5d4fecc..ca2fcd2 100644 --- a/to-html.js +++ b/to-html.js @@ -1,13 +1,15 @@ const TOKENS_EXT = /\.tokens\.json$/; -module.exports = ({css} = {css: true}) => (file, cb) => { +module.exports = ({ css } = { css: true }) => (file, cb) => { if (!TOKENS_EXT.test(file.path)) return cb(null, file); file.path = file.path.replace(TOKENS_EXT, ".html"); file.contents = Buffer.from(` -${css ? -'\n\n' -: ''} +${ + css + ? '\n\n' + : "" + } ${toHTML(JSON.parse(file.contents.toString("utf8")))} @@ -17,29 +19,29 @@ ${toHTML(JSON.parse(file.contents.toString("utf8")))} }; function toHTML(tokens) { - let body = [] + let body = []; - let cursor = tokens.shift() + let cursor = tokens.shift(); while (tokens.length) { if (cursor.pre) { - body.push(``) - const closing = tokens.findIndex(token => token.pre) - body = body.concat(tokens.slice(0, closing).map(({text}) => text)) - body.push("") - tokens = tokens.slice(closing + 1) + body.push(``); + const closing = tokens.findIndex((token) => token.pre); + body = body.concat(tokens.slice(0, closing).map(({ text }) => text)); + body.push(""); + tokens = tokens.slice(closing + 1); } if (cursor.li) { - body.push(`") - tokens = tokens.slice(closing + 1) + body.push(`"); + tokens = tokens.slice(closing + 1); } - body.push(line(cursor)) - cursor = tokens.shift() + body.push(line(cursor)); + cursor = tokens.shift(); } - return body.join("\n") + return body.join("\n"); } function line({ text, href, title, pre, alt, h1, h2, h3, li, quote }) {