quote-quote
Version:
Convert straight quotes to curly quotes — also known as smart quotes.
2 lines • 1.39 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.convertMarkdown=convertMarkdown;const convert_js_1=require("./convert.js"),utils_js_1=require("./utils.js"),fencedBlockRegex=/(^|(?<!\\)(?:\r\n|\n))([`,~]{3})([\s\S]*?)(?<!\\)(?:\r\n|\n)(\2)(?=(?:\r\n|\n)|$)/g,indentedBlockRegex=/(^|(?<!\\)(?:\r\n|\n))( {4}|\t)([\s\S]*?)(?=(?<!\\)(?:\r\n|\n)(?!\2)|$)/g,codeSingleRegex=/(?<!\\)`([\s\S]*?)(?<!\\)`/g,codeDoubleRegex=/(?<!\\)``([\s\S]*?)(?<!\\)``/g,codeTripleRegex=/(?<!\\)```([\s\S]*?)(?<!\\)```/g;function convertMarkdown(e,o){(0,utils_js_1.throwForInvalidArgumentTypes)(e,o);const r=[{regex:fencedBlockRegex,token:"\n_QQxFENCED_\n",code:[]},{regex:indentedBlockRegex,token:"\n_QQxINDENTED_\n",code:[]},{regex:codeTripleRegex,token:"_QQxTRIPLE_",code:[]},{regex:codeDoubleRegex,token:"_QQxDOUBLE_",code:[]},{regex:codeSingleRegex,token:"_QQxSINGLE_",code:[]}],n=r.reduce(((e,o)=>e.replace(o.regex,(e=>(o.code.push(e),o.token)))),e),t=(0,convert_js_1.convert)(n,o),c=[...r].reverse().reduce(((e,o)=>e.replaceAll(o.token,(()=>shiftFrom(o.code)))),t);if(r.some((e=>0!==e.code.length)))throw new Error('quote-quote: "convertMarkdown()" could not parse Markdown');return c}function shiftFrom(e){const o=e.shift();if("string"!=typeof o)throw new Error('quote-quote: "convertMarkdown()" could not parse Markdown');return o}
//# sourceMappingURL=convert-markdown.js.map