UNPKG

quote-quote

Version:

Convert straight quotes to curly quotes — also known as smart quotes.

2 lines 1.27 kB
import{convert}from"./convert.js";import{throwForInvalidArgumentTypes}from"./utils.js";const 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;export function convertMarkdown(e,o){throwForInvalidArgumentTypes(e,o);const n=[{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:[]}],r=n.reduce(((e,o)=>e.replace(o.regex,(e=>(o.code.push(e),o.token)))),e),t=convert(r,o),c=[...n].reverse().reduce(((e,o)=>e.replaceAll(o.token,(()=>shiftFrom(o.code)))),t);if(n.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