diff --git a/bin/smartypants.cjs b/bin/smartypants.cjs new file mode 100755 index 0000000..2be0cca --- /dev/null +++ b/bin/smartypants.cjs @@ -0,0 +1,39 @@ +#! /usr/bin/env node + +const binary = "smartypants"; +const mode = process.argv[2] || "1"; + +if (mode == "-h" || mode == "--help") { + process.stdout.write(`Usage: ${binary} [mode] + +Available modes: + + 0 Suppress all transformations. (Do nothing.) + 1 Performs default SmartyPants transformations: quotes (including backticks-style), em-dashes, and ellipses. -- (dash dash) is used to signify an em-dash; there is no support for en-dashes. + 2 Same as 1, except that it uses the old-school typewriter shorthand for dashes: -- (dash dash) for en-dashes, --- (dash dash dash) for em-dashes. + 3 Same 2, but inverts the shorthand for dashes: -- (dash dash) for em-dashes, and --- (dash dash dash) for en-dashes. + -1 Stupefy mode. Reverses the SmartyPants transformation process, turning the HTML entities produced by SmartyPants into their ASCII equivalents. E.g. “ is turned into a simple double-quote ("), — is turned into two dashes, etc. This is useful if you are using SmartyPants from Brad Choate's MT-Textile text filter, but wish to suppress smart punctuation in specific MT templates, such as RSS feeds. Text filters do their work before templates are processed; but you can use smarty_pants="-1" to reverse the transformations in specific templates. + `); + process.exit(0); +} + +if (process.stdin.isTTY) { + console.error("No input!"); + process.exit(1); +} + +let smartypants = require("../smartypants.cjs").smartypants; +let text = ""; + +process.stdin.setEncoding("utf8"); + +process.stdin.on("readable", () => { + let chunk = process.stdin.read(); + if (chunk !== null) { + text = text + chunk; + } +}); + +process.stdin.on("end", () => { + process.stdout.write(smartypants(text, mode)); +}); diff --git a/bin/smartypants.js b/bin/smartypants.js deleted file mode 100755 index 7c7bd77..0000000 --- a/bin/smartypants.js +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env node - -if (process.stdin.isTTY) { - console.error('No input!'); - process.exit(1); -} - -var smartypants = require('..').smartypants; - -var text = ''; - -process.stdin.setEncoding('utf8'); - -process.stdin.on('readable', () => { - var chunk = process.stdin.read(); - if (chunk !== null) { - text = text + chunk; - } -}); - -process.stdin.on('end', () => { - process.stdout.write(smartypants(text, '1')); -}); - diff --git a/bin/smartypantsu.cjs b/bin/smartypantsu.cjs new file mode 100755 index 0000000..532eb92 --- /dev/null +++ b/bin/smartypantsu.cjs @@ -0,0 +1,39 @@ +#! /usr/bin/env node + +const binary = "smartypantsu"; +const mode = process.argv[2] || "1"; + +if (mode == "-h" || mode == "--help") { + process.stdout.write(`Usage: ${binary} [mode] + +Available modes: + + 0 Suppress all transformations. (Do nothing.) + 1 Performs default SmartyPants transformations: quotes (including backticks-style), em-dashes, and ellipses. -- (dash dash) is used to signify an em-dash; there is no support for en-dashes. + 2 Same as 1, except that it uses the old-school typewriter shorthand for dashes: -- (dash dash) for en-dashes, --- (dash dash dash) for em-dashes. + 3 Same 2, but inverts the shorthand for dashes: -- (dash dash) for em-dashes, and --- (dash dash dash) for en-dashes. + -1 Stupefy mode. Reverses the SmartyPants transformation process, turning the HTML entities produced by SmartyPants into their ASCII equivalents. E.g. “ is turned into a simple double-quote ("), — is turned into two dashes, etc. This is useful if you are using SmartyPants from Brad Choate's MT-Textile text filter, but wish to suppress smart punctuation in specific MT templates, such as RSS feeds. Text filters do their work before templates are processed; but you can use smarty_pants="-1" to reverse the transformations in specific templates. + `); + process.exit(0); +} + +if (process.stdin.isTTY) { + console.error("No input!"); + process.exit(1); +} + +let smartypants = require("../smartypants.cjs").smartypantsu; +let text = ""; + +process.stdin.setEncoding("utf8"); + +process.stdin.on("readable", () => { + let chunk = process.stdin.read(); + if (chunk !== null) { + text = text + chunk; + } +}); + +process.stdin.on("end", () => { + process.stdout.write(smartypants(text, mode)); +}); diff --git a/bin/smartypantsu.js b/bin/smartypantsu.js deleted file mode 100755 index 22db5d7..0000000 --- a/bin/smartypantsu.js +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env node - -if (process.stdin.isTTY) { - console.error('No input!'); - process.exit(1); -} - -var smartypants = require('..').smartypantsu; - -var text = ''; - -process.stdin.setEncoding('utf8'); - -process.stdin.on('readable', () => { - var chunk = process.stdin.read(); - if (chunk !== null) { - text = text + chunk; - } -}); - -process.stdin.on('end', () => { - process.stdout.write(smartypants(text, '1')); -}); - diff --git a/package.json b/package.json index d5b5977..bfaf666 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ "bin/smartypantsu.js" ], "bin": { - "smartypants": "./bin/smartypants.js", - "smartypantsu": "./bin/smartypantsu.js" + "smartypants": "./bin/smartypants.cjs", + "smartypantsu": "./bin/smartypantsu.cjs" }, "devDependencies": { "babel-eslint": "^9.0.0", @@ -55,4 +55,4 @@ "typescript": "^3.0.3", "uglify-js": "3.9.4" } -} +} \ No newline at end of file diff --git a/smartypants.cjs b/smartypants.cjs index f7873d7..164ef98 100644 --- a/smartypants.cjs +++ b/smartypants.cjs @@ -33,7 +33,7 @@ "use strict"; exports.__esModule = true; exports.smartypantsu = exports.smartellipses = exports.smartdashes = exports.smartquotes = exports.smartypants = void 0; - var tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i; + var tags_to_skip = /<(\/?)(?:pre|code|kbd|script|style|math)[^>]*>/i; /** * @param text text to be parsed * @param attr value of the smart_quotes="" attribute diff --git a/smartypants.es6.js b/smartypants.es6.js index caebce0..e92f725 100644 --- a/smartypants.es6.js +++ b/smartypants.es6.js @@ -1,4 +1,4 @@ -const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i; +const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|style|math)[^>]*>/i; /** * @param text text to be parsed * @param attr value of the smart_quotes="" attribute diff --git a/smartypants.js b/smartypants.js index f7873d7..164ef98 100644 --- a/smartypants.js +++ b/smartypants.js @@ -33,7 +33,7 @@ "use strict"; exports.__esModule = true; exports.smartypantsu = exports.smartellipses = exports.smartdashes = exports.smartquotes = exports.smartypants = void 0; - var tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i; + var tags_to_skip = /<(\/?)(?:pre|code|kbd|script|style|math)[^>]*>/i; /** * @param text text to be parsed * @param attr value of the smart_quotes="" attribute diff --git a/smartypants.mjs b/smartypants.mjs index caebce0..e92f725 100644 --- a/smartypants.mjs +++ b/smartypants.mjs @@ -1,4 +1,4 @@ -const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i; +const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|style|math)[^>]*>/i; /** * @param text text to be parsed * @param attr value of the smart_quotes="" attribute diff --git a/smartypants.ts b/smartypants.ts index d618c76..3ad5a2a 100644 --- a/smartypants.ts +++ b/smartypants.ts @@ -1,6 +1,6 @@ type token = [string, string]; -const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|math)[^>]*>/i; +const tags_to_skip = /<(\/?)(?:pre|code|kbd|script|style|math)[^>]*>/i; /**