@khanacademy/pure-markdown 2.0.10 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.js +5 -3
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/traversal.d.ts +5 -0
- package/package.json +3 -3
package/dist/es/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-utils';
|
|
2
2
|
import SimpleMarkdown from '@khanacademy/simple-markdown';
|
|
3
3
|
|
|
4
|
-
const libName="@khanacademy/pure-markdown";const libVersion="2.0
|
|
4
|
+
const libName="@khanacademy/pure-markdown";const libVersion="2.2.0";addLibraryVersionToPerseusDebug(libName,libVersion);
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const traverseContent=(ast,cb)=>{if(Array.isArray(ast)){ast.forEach(node=>traverseContent(node,cb));}else if(typeof ast==="object"&&ast!==null){cb(ast);if(ast.type==="table"){traverseContent(ast.header,cb);traverseContent(ast.cells,cb);}else if(ast.type==="list"){traverseContent(ast.items,cb);}else if(ast.type==="titledTable"){traverseContent(ast.table,cb);}else if(ast.type==="columns"){traverseContent(ast.col1,cb);traverseContent(ast.col2,cb);}else if(Array.isArray(ast.content)){traverseContent(ast.content,cb);}}};
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const rWidgetRule=/^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;const mathMatcher=(source,state,isBlock)=>{const length=source.length;let index=0;if(isBlock){if(state.inline){return null}while(index<length&&source[index]===" "){index++;}}if(!(index<length&&source[index]==="$")){return null}index++;const startIndex=index;let braceLevel=0;while(index<length){const character=source[index];if(character==="\\"){index++;}else if(braceLevel<=0&&character==="$"){let endIndex=index+1;if(isBlock){const match=/^(?: *\n){2,}/.exec(source.slice(endIndex));endIndex=match?endIndex+match[0].length:null;}if(endIndex){return [source.substring(0,endIndex),source.substring(startIndex,index)]}return null}else if(character==="{"){braceLevel++;}else if(character==="}"){braceLevel--;}else if(character==="\n"&&source[index-1]==="\n"){return null}index++;}return null};const mathMatch=(source,state)=>mathMatcher(source,state,false);const blockMathMatch=(source,state)=>mathMatcher(source,state,true);const TITLED_TABLE_REGEX=new RegExp("^\\|\\| +(.*) +\\|\\| *\\n"+"("+SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1)+")");const crowdinJiptMatcher=SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);const pureMarkdownRules={...SimpleMarkdown.defaultRules,columns:{order:-2,match:SimpleMarkdown.blockRegex(/^([\s\S]*\n\n)={5,}\n\n([\s\S]*)/),parse:(capture,parse,state)=>{return {col1:parse(capture[1],state),col2:parse(capture[2],state)}}},crowdinId:{order:-1,match:(source,state,prevCapture)=>{if(state.isJipt){return crowdinJiptMatcher(source,state,prevCapture)}return null},parse:(capture,parse,state)=>({id:capture[1]})},titledTable:{order:SimpleMarkdown.defaultRules.nptable.order-.5,match:SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX),parse:(capture,parse,state)=>{const title=SimpleMarkdown.parseInline(parse,capture[1],state);const tableCapture=capture.slice(2);const table=SimpleMarkdown.defaultRules.nptable.parse(tableCapture,parse,state);return {title:title,table:table}}},widget:{order:SimpleMarkdown.defaultRules.link.order-.75,match:SimpleMarkdown.inlineRegex(rWidgetRule),parse:(capture,parse,state)=>{return {id:capture[1],widgetType:capture[2]}}},blockMath:{order:SimpleMarkdown.defaultRules.codeBlock.order+.5,match:blockMathMatch,parse:(capture,parse,state)=>{return {content:capture[1]}}},math:{order:SimpleMarkdown.defaultRules.link.order-.25,match:mathMatch,parse:(capture,parse,state)=>{return {content:capture[1]}}},unescapedDollar:{order:SimpleMarkdown.defaultRules.link.order-.24,match:SimpleMarkdown.inlineRegex(/^(?!\\)\$/),parse:(capture,parse,state)=>{return {}}},fence:{...SimpleMarkdown.defaultRules.fence,parse:(capture,parse,state)=>{const node=SimpleMarkdown.defaultRules.fence.parse(capture,parse,state);if(node.lang==="alt"){return {type:"codeBlock",lang:"alt",content:parse(node.content+"\n\n",state)}}return node}},blockQuote:{...SimpleMarkdown.defaultRules.blockQuote,match:SimpleMarkdown.blockRegex(/^ *>[^\n]+(\n( *>)?[^\n]+)*\n{2,}/)},lint:{order:1e3,match:s=>null,parse:(capture,parse,state)=>({})}};const builtParser=SimpleMarkdown.parserFor(pureMarkdownRules);function parse(source,state){const paragraphedSource=source+"\n\n";return builtParser(paragraphedSource,{...state,inline:false})}
|
|
9
|
+
|
|
10
|
+
export { libVersion, parse, pureMarkdownRules, traverseContent };
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/version.ts","../../src/index.ts"],"sourcesContent":["// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"@khanacademy/perseus-utils\";\n\nconst libName = \"@khanacademy/pure-markdown\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n","/**\n * Contains markdown related functions in pure javascript,\n * extracted from perseus-markdown.jsx\n * Note that this file may be used in stand alone nodejs, thus\n * do not import anything from Perseus\n */\nexport {libVersion} from \"./version\";\n\nimport SimpleMarkdown from \"@khanacademy/simple-markdown\";\n\nconst rWidgetRule = /^\\[\\[\\u2603 (([a-z-]+) ([0-9]+))\\]\\]/;\n\n/**\n * This match function matches math in `$`s, such as:\n *\n * $y = x + 1$\n *\n * It functions roughly like the following regex:\n * /\\$([^\\$]*)\\$/\n *\n * Unfortunately, math may have other `$`s inside it, as\n * long as they are inside `{` braces `}`, mostly for\n * `\\text{ $math$ }`.\n *\n * To parse this, we can't use a regex, since we\n * should support arbitrary nesting (even though\n * MathJax actually only supports two levels of nesting\n * here, which we *could* parse with a regex).\n *\n * Non-regex matchers like this are now a first-class\n * concept in simple-markdown. Yay!\n *\n * This can also match block-math, which is math alone in a paragraph.\n */\nconst mathMatcher = (source: any, state: any, isBlock: boolean) => {\n const length = source.length;\n let index = 0;\n\n // When looking for blocks, skip over leading spaces\n if (isBlock) {\n if (state.inline) {\n return null;\n }\n while (index < length && source[index] === \" \") {\n index++;\n }\n }\n\n // Our source must start with a \"$\"\n if (!(index < length && source[index] === \"$\")) {\n return null;\n }\n\n index++;\n const startIndex = index;\n let braceLevel = 0;\n\n // Loop through the source, looking for a closing '$'\n // closing '$'s only count if they are not escaped with\n // a `\\`, and we are not in nested `{}` braces.\n while (index < length) {\n const character = source[index];\n\n if (character === \"\\\\\") {\n // Consume both the `\\` and the escaped char as a single\n // token.\n // This is so that the second `$` in `$\\\\$` closes\n // the math expression, since the first `\\` is escaping\n // the second `\\`, but the second `\\` is not escaping\n // the second `$`.\n // This also handles the case of escaping `$`s or\n // braces `\\{`\n index++;\n } else if (braceLevel <= 0 && character === \"$\") {\n let endIndex = index + 1;\n if (isBlock) {\n // Look for two trailing newlines after the closing `$`\n const match = /^(?: *\\n){2,}/.exec(source.slice(endIndex));\n // @ts-expect-error - TS2322 - Type 'number | null' is not assignable to type 'number'.\n endIndex = match ? endIndex + match[0].length : null;\n }\n\n // Return an array that looks like the results of a\n // regex's .exec function:\n // capture[0] is the whole string\n // capture[1] is the first \"paren\" match, which is the\n // content of the math here, as if we wrote the regex\n // /\\$([^\\$]*)\\$/\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (endIndex) {\n return [\n source.substring(0, endIndex),\n source.substring(startIndex, index),\n ];\n }\n return null;\n } else if (character === \"{\") {\n braceLevel++;\n } else if (character === \"}\") {\n braceLevel--;\n } else if (character === \"\\n\" && source[index - 1] === \"\\n\") {\n // This is a weird case we supported in the old\n // math implementation--double newlines break\n // math. I'm preserving it for now because content\n // creators might have questions with single '$'s\n // in paragraphs...\n return null;\n }\n\n index++;\n }\n\n // we didn't find a closing `$`\n return null;\n};\nconst mathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, false);\nconst blockMathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, true);\n\nconst TITLED_TABLE_REGEX = new RegExp(\n \"^\\\\|\\\\| +(.*) +\\\\|\\\\| *\\\\n\" +\n \"(\" +\n // The simple-markdown nptable regex, without\n // the leading `^`\n // @ts-expect-error - TS2532 - Object is possibly 'undefined'.\n SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +\n \")\",\n);\n\nconst crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\\n\\s*\\n/);\n\nexport const pureMarkdownRules = {\n ...SimpleMarkdown.defaultRules,\n\n // NOTE: basically ignored by JIPT. wraps everything at the outer layer\n columns: {\n order: -2,\n match: SimpleMarkdown.blockRegex(\n /^([\\s\\S]*\\n\\n)={5,}\\n\\n([\\s\\S]*)/,\n ) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n col1: parse(capture[1], state),\n col2: parse(capture[2], state),\n };\n },\n },\n crowdinId: {\n order: -1,\n match: (source: any, state: any, prevCapture: any): any => {\n // Only match on the just-in-place translation site\n if (state.isJipt) {\n return crowdinJiptMatcher(source, state, prevCapture);\n }\n return null;\n },\n parse: (capture: any, parse: any, state: any): any => ({\n id: capture[1],\n }),\n },\n // This is pretty much horrible, but we have a regex here to capture an\n // entire table + a title. capture[1] is the title. capture[2] of the\n // regex is a copy of the simple-markdown nptable regex. Then we turn\n // our capture[2] into tableCapture[0], and any further captures in\n // our table regex into tableCapture[1..], and we pass tableCapture to\n // our nptable regex\n titledTable: {\n // process immediately before nptables\n order: SimpleMarkdown.defaultRules.nptable.order - 0.5,\n match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX) as any,\n parse: (capture: any, parse: any, state: any): any => {\n const title = SimpleMarkdown.parseInline(parse, capture[1], state);\n\n // Remove our [0] and [1] captures, and pass the rest to\n // the nptable parser\n const tableCapture = capture.slice(2);\n const table = SimpleMarkdown.defaultRules.nptable.parse(\n tableCapture,\n parse,\n state,\n );\n return {\n title: title,\n table: table,\n };\n },\n },\n widget: {\n order: SimpleMarkdown.defaultRules.link.order - 0.75,\n match: SimpleMarkdown.inlineRegex(rWidgetRule) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n id: capture[1],\n widgetType: capture[2],\n };\n },\n },\n blockMath: {\n order: (SimpleMarkdown.defaultRules.codeBlock.order + 0.5) as any,\n match: blockMathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n math: {\n order: SimpleMarkdown.defaultRules.link.order - 0.25,\n match: mathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n unescapedDollar: {\n order: SimpleMarkdown.defaultRules.link.order - 0.24,\n match: SimpleMarkdown.inlineRegex(/^(?!\\\\)\\$/) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {};\n },\n },\n fence: {\n ...SimpleMarkdown.defaultRules.fence,\n parse: (capture: any, parse: any, state: any): any => {\n const node = SimpleMarkdown.defaultRules.fence.parse(\n capture,\n parse,\n state,\n );\n\n // support screenreader-only text with ```alt\n if (node.lang === \"alt\") {\n return {\n type: \"codeBlock\",\n lang: \"alt\",\n // default codeBlock parsing doesn't parse the contents.\n // We need to parse the contents for things like table\n // support :).\n // The \\n\\n is because the inside of the codeblock might\n // not end in double newlines for block rules, because\n // ordinarily we don't parse this :).\n content: parse(node.content + \"\\n\\n\", state),\n };\n }\n return node;\n },\n },\n blockQuote: {\n ...SimpleMarkdown.defaultRules.blockQuote,\n // Replace the less restrictive blockquote regex from SimpleMarkdown\n // with a more restrictive one. The only difference should be that\n //\n // > A blockquote\n //\n // > Another blockquote\n //\n // will now match as two different blockQuotes instead of a single\n // blockquote with some paragraph breaks in it.\n //\n // The main motivation for doing this is to provide better support for\n // translators translating blockquotes with multiple paragraphs in\n // them. When translating articles, we split up paragraphs, translate\n // them separately, and then recombine them. We do this so that\n // translators don't have to translate an entire article at a time,\n // they can instead translate paragraph-by-paragraph.That system\n // doesn't understand blockquotes, so it will split up blockquotes into\n // more than one paragraph. A way to solve this would be to make that\n // system understand blockquotes, but then translators would have to\n // translate an entire, multi-paragraph blockquote at a time. Instead,\n // we choose to modify our blockquote matching to split up\n // multi-paragraph blockquotes into multiple blockquotes.\n //\n // There is also precedence for doing this splitting up in other\n // libraries, for instance CommonMark also splits up blockquotes with\n // empty lines into multiple blockquotes:\n // https://spec.commonmark.org/0.28/#example-205\n match: SimpleMarkdown.blockRegex(\n /^ *>[^\\n]+(\\n( *>)?[^\\n]+)*\\n{2,}/,\n ) as any,\n },\n // The lint rule never actually matches anything.\n // We check for lint after parsing, and, if we find any, we\n // transform the tree to add lint nodes. This rule is here\n // just for the react() function\n lint: {\n order: 1000,\n match: (s: any): any => null,\n parse: (capture: any, parse: any, state: any): any => ({}),\n },\n} as const;\n\n// @ts-expect-error - TS2345 - Argument of type '{ readonly columns: { readonly order: -2; readonly match: any; readonly parse: (capture: any, parse: any, state: any) => any; }; readonly crowdinId: { readonly order: -1; readonly match: (source: any, state: any, prevCapture: any) => any; readonly parse: (capture: any, parse: any, state: any) => any; }; ... 34 more ...' is not assignable to parameter of type 'ParserRules'.\nconst builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);\n\nexport const parse = (source: string, state?: any): any => {\n const paragraphedSource = source + \"\\n\\n\";\n\n return builtParser(paragraphedSource, {\n ...state,\n inline: false,\n });\n};\n"],"names":["libName","libVersion","addLibraryVersionToPerseusDebug","rWidgetRule","mathMatcher","source","state","isBlock","length","index","inline","startIndex","braceLevel","character","endIndex","match","exec","slice","substring","mathMatch","blockMathMatch","TITLED_TABLE_REGEX","RegExp","SimpleMarkdown","defaultRules","nptable","regex","crowdinJiptMatcher","blockRegex","pureMarkdownRules","columns","order","parse","capture","col1","col2","crowdinId","prevCapture","isJipt","id","titledTable","title","parseInline","tableCapture","table","widget","link","inlineRegex","widgetType","blockMath","codeBlock","content","math","unescapedDollar","fence","node","lang","type","blockQuote","lint","s","builtParser","parserFor","paragraphedSource"],"mappings":";;;AAMA,MAAMA,OAAAA,CAAU,4BAChB,CAAaC,MAAAA,UAAAA,CAAa,SAE1BC,gCAAgCF,OAASC,CAAAA,UAAAA,CAAAA;;ACCzC,MAAME,WAAc,CAAA,sCAAA,CAwBpB,MAAMC,WAAAA,CAAc,CAACC,MAAaC,CAAAA,KAAAA,CAAYC,OAC1C,GAAA,CAAA,MAAMC,MAASH,CAAAA,MAAAA,CAAOG,MAAM,CAC5B,IAAIC,KAAQ,CAAA,CAAA,CAGZ,GAAIF,OAAAA,CAAS,CACT,GAAID,KAAMI,CAAAA,MAAM,CAAE,CACd,OAAO,IACX,CACA,MAAOD,KAAAA,CAAQD,MAAUH,EAAAA,MAAM,CAACI,KAAM,CAAA,GAAK,GAAK,CAAA,CAC5CA,KACJ,GAAA,CACJ,CAGA,GAAI,EAAEA,KAAAA,CAAQD,MAAUH,EAAAA,MAAM,CAACI,KAAAA,CAAM,GAAK,GAAE,EAAI,CAC5C,OAAO,IACX,CAEAA,QACA,MAAME,UAAAA,CAAaF,KACnB,CAAA,IAAIG,WAAa,CAKjB,CAAA,MAAOH,KAAQD,CAAAA,MAAAA,CAAQ,CACnB,MAAMK,SAAYR,CAAAA,MAAM,CAACI,KAAM,CAAA,CAE/B,GAAII,SAAAA,GAAc,IAAM,CAAA,CASpBJ,KACJ,GAAA,CAAA,KAAO,GAAIG,UAAc,EAAA,CAAA,EAAKC,SAAc,GAAA,GAAA,CAAK,CAC7C,IAAIC,QAAWL,CAAAA,KAAAA,CAAQ,EACvB,GAAIF,OAAAA,CAAS,CAET,MAAMQ,KAAQ,CAAA,eAAA,CAAgBC,IAAI,CAACX,OAAOY,KAAK,CAACH,QAEhDA,CAAAA,CAAAA,CAAAA,QAAAA,CAAWC,KAAQD,CAAAA,QAAAA,CAAWC,KAAK,CAAC,EAAE,CAACP,MAAM,CAAG,KACpD,CAS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A,CAIJ,GAAIiD,IAAKC,CAAAA,IAAI,GAAK,KAAA,CAAO,CACrB,OAAO,CACHC,IAAM,CAAA,WAAA,CACND,KAAM,KAONL,CAAAA,OAAAA,CAASnB,KAAMuB,CAAAA,IAAAA,CAAKJ,OAAO,CAAG,MAAQ7C,CAAAA,KAAAA,CAC1C,CACJ,CACA,OAAOiD,IACX,CACJ,CACAG,CAAAA,UAAAA,CAAY,CACR,GAAGnC,eAAeC,YAAY,CAACkC,UAAU,CA4BzC3C,KAAOQ,CAAAA,cAAAA,CAAeK,UAAU,CAC5B,oCAER,CAKA+B,CAAAA,IAAAA,CAAM,CACF5B,KAAAA,CAAO,IACPhB,KAAO,CAAC6C,CAAgB,EAAA,IAAA,CACxB5B,MAAO,CAACC,OAAAA,CAAcD,KAAY1B,CAAAA,KAAAA,IAAqB,EAAC,CAC5D,CACJ,EAGA,MAAMuD,WAAAA,CAActC,cAAeuC,CAAAA,SAAS,CAACjC,iBAAAA,CAE7C,CAAaG,MAAAA,KAAAA,CAAQ,CAAC3B,MAAAA,CAAgBC,KAClC,GAAA,CAAA,MAAMyD,iBAAoB1D,CAAAA,MAAAA,CAAS,OAEnC,OAAOwD,WAAAA,CAAYE,iBAAmB,CAAA,CAClC,GAAGzD,KAAK,CACRI,MAAQ,CAAA,KACZ,EACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/version.ts","../../src/traversal.ts","../../src/index.ts"],"sourcesContent":["// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"@khanacademy/perseus-utils\";\n\nconst libName = \"@khanacademy/pure-markdown\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n","/**\n * Traverse all of the nodes in the Perseus Markdown AST. The callback is\n * called for each node in the AST.\n */\nexport const traverseContent = (ast: any, cb: (node: any) => void) => {\n if (Array.isArray(ast)) {\n ast.forEach((node) => traverseContent(node, cb));\n } else if (typeof ast === \"object\" && ast !== null) {\n cb(ast);\n if (ast.type === \"table\") {\n traverseContent(ast.header, cb);\n traverseContent(ast.cells, cb);\n } else if (ast.type === \"list\") {\n traverseContent(ast.items, cb);\n } else if (ast.type === \"titledTable\") {\n traverseContent(ast.table, cb);\n } else if (ast.type === \"columns\") {\n traverseContent(ast.col1, cb);\n traverseContent(ast.col2, cb);\n } else if (Array.isArray(ast.content)) {\n traverseContent(ast.content, cb);\n }\n }\n};\n","/**\n * Contains markdown related functions in pure javascript,\n * extracted from perseus-markdown.jsx\n * Note that this file may be used in stand alone nodejs, thus\n * do not import anything from Perseus\n */\nexport {libVersion} from \"./version\";\n\nexport {traverseContent} from \"./traversal\";\n\nimport SimpleMarkdown from \"@khanacademy/simple-markdown\";\n\nconst rWidgetRule = /^\\[\\[\\u2603 (([a-z-]+) ([0-9]+))\\]\\]/;\n\n/**\n * This match function matches math in `$`s, such as:\n *\n * $y = x + 1$\n *\n * It functions roughly like the following regex:\n * /\\$([^\\$]*)\\$/\n *\n * Unfortunately, math may have other `$`s inside it, as\n * long as they are inside `{` braces `}`, mostly for\n * `\\text{ $math$ }`.\n *\n * To parse this, we can't use a regex, since we\n * should support arbitrary nesting (even though\n * MathJax actually only supports two levels of nesting\n * here, which we *could* parse with a regex).\n *\n * Non-regex matchers like this are now a first-class\n * concept in simple-markdown. Yay!\n *\n * This can also match block-math, which is math alone in a paragraph.\n */\nconst mathMatcher = (source: any, state: any, isBlock: boolean) => {\n const length = source.length;\n let index = 0;\n\n // When looking for blocks, skip over leading spaces\n if (isBlock) {\n if (state.inline) {\n return null;\n }\n while (index < length && source[index] === \" \") {\n index++;\n }\n }\n\n // Our source must start with a \"$\"\n if (!(index < length && source[index] === \"$\")) {\n return null;\n }\n\n index++;\n const startIndex = index;\n let braceLevel = 0;\n\n // Loop through the source, looking for a closing '$'\n // closing '$'s only count if they are not escaped with\n // a `\\`, and we are not in nested `{}` braces.\n while (index < length) {\n const character = source[index];\n\n if (character === \"\\\\\") {\n // Consume both the `\\` and the escaped char as a single\n // token.\n // This is so that the second `$` in `$\\\\$` closes\n // the math expression, since the first `\\` is escaping\n // the second `\\`, but the second `\\` is not escaping\n // the second `$`.\n // This also handles the case of escaping `$`s or\n // braces `\\{`\n index++;\n } else if (braceLevel <= 0 && character === \"$\") {\n let endIndex = index + 1;\n if (isBlock) {\n // Look for two trailing newlines after the closing `$`\n const match = /^(?: *\\n){2,}/.exec(source.slice(endIndex));\n // @ts-expect-error - TS2322 - Type 'number | null' is not assignable to type 'number'.\n endIndex = match ? endIndex + match[0].length : null;\n }\n\n // Return an array that looks like the results of a\n // regex's .exec function:\n // capture[0] is the whole string\n // capture[1] is the first \"paren\" match, which is the\n // content of the math here, as if we wrote the regex\n // /\\$([^\\$]*)\\$/\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (endIndex) {\n return [\n source.substring(0, endIndex),\n source.substring(startIndex, index),\n ];\n }\n return null;\n } else if (character === \"{\") {\n braceLevel++;\n } else if (character === \"}\") {\n braceLevel--;\n } else if (character === \"\\n\" && source[index - 1] === \"\\n\") {\n // This is a weird case we supported in the old\n // math implementation--double newlines break\n // math. I'm preserving it for now because content\n // creators might have questions with single '$'s\n // in paragraphs...\n return null;\n }\n\n index++;\n }\n\n // we didn't find a closing `$`\n return null;\n};\nconst mathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, false);\nconst blockMathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, true);\n\nconst TITLED_TABLE_REGEX = new RegExp(\n \"^\\\\|\\\\| +(.*) +\\\\|\\\\| *\\\\n\" +\n \"(\" +\n // The simple-markdown nptable regex, without\n // the leading `^`\n // @ts-expect-error - TS2532 - Object is possibly 'undefined'.\n SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +\n \")\",\n);\n\nconst crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\\n\\s*\\n/);\n\nexport const pureMarkdownRules = {\n ...SimpleMarkdown.defaultRules,\n\n // NOTE: basically ignored by JIPT. wraps everything at the outer layer\n columns: {\n order: -2,\n match: SimpleMarkdown.blockRegex(\n /^([\\s\\S]*\\n\\n)={5,}\\n\\n([\\s\\S]*)/,\n ) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n col1: parse(capture[1], state),\n col2: parse(capture[2], state),\n };\n },\n },\n crowdinId: {\n order: -1,\n match: (source: any, state: any, prevCapture: any): any => {\n // Only match on the just-in-place translation site\n if (state.isJipt) {\n return crowdinJiptMatcher(source, state, prevCapture);\n }\n return null;\n },\n parse: (capture: any, parse: any, state: any): any => ({\n id: capture[1],\n }),\n },\n // This is pretty much horrible, but we have a regex here to capture an\n // entire table + a title. capture[1] is the title. capture[2] of the\n // regex is a copy of the simple-markdown nptable regex. Then we turn\n // our capture[2] into tableCapture[0], and any further captures in\n // our table regex into tableCapture[1..], and we pass tableCapture to\n // our nptable regex\n titledTable: {\n // process immediately before nptables\n order: SimpleMarkdown.defaultRules.nptable.order - 0.5,\n match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX) as any,\n parse: (capture: any, parse: any, state: any): any => {\n const title = SimpleMarkdown.parseInline(parse, capture[1], state);\n\n // Remove our [0] and [1] captures, and pass the rest to\n // the nptable parser\n const tableCapture = capture.slice(2);\n const table = SimpleMarkdown.defaultRules.nptable.parse(\n tableCapture,\n parse,\n state,\n );\n return {\n title: title,\n table: table,\n };\n },\n },\n widget: {\n order: SimpleMarkdown.defaultRules.link.order - 0.75,\n match: SimpleMarkdown.inlineRegex(rWidgetRule) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n id: capture[1],\n widgetType: capture[2],\n };\n },\n },\n blockMath: {\n order: (SimpleMarkdown.defaultRules.codeBlock.order + 0.5) as any,\n match: blockMathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n math: {\n order: SimpleMarkdown.defaultRules.link.order - 0.25,\n match: mathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n unescapedDollar: {\n order: SimpleMarkdown.defaultRules.link.order - 0.24,\n match: SimpleMarkdown.inlineRegex(/^(?!\\\\)\\$/) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {};\n },\n },\n fence: {\n ...SimpleMarkdown.defaultRules.fence,\n parse: (capture: any, parse: any, state: any): any => {\n const node = SimpleMarkdown.defaultRules.fence.parse(\n capture,\n parse,\n state,\n );\n\n // support screenreader-only text with ```alt\n if (node.lang === \"alt\") {\n return {\n type: \"codeBlock\",\n lang: \"alt\",\n // default codeBlock parsing doesn't parse the contents.\n // We need to parse the contents for things like table\n // support :).\n // The \\n\\n is because the inside of the codeblock might\n // not end in double newlines for block rules, because\n // ordinarily we don't parse this :).\n content: parse(node.content + \"\\n\\n\", state),\n };\n }\n return node;\n },\n },\n blockQuote: {\n ...SimpleMarkdown.defaultRules.blockQuote,\n // Replace the less restrictive blockquote regex from SimpleMarkdown\n // with a more restrictive one. The only difference should be that\n //\n // > A blockquote\n //\n // > Another blockquote\n //\n // will now match as two different blockQuotes instead of a single\n // blockquote with some paragraph breaks in it.\n //\n // The main motivation for doing this is to provide better support for\n // translators translating blockquotes with multiple paragraphs in\n // them. When translating articles, we split up paragraphs, translate\n // them separately, and then recombine them. We do this so that\n // translators don't have to translate an entire article at a time,\n // they can instead translate paragraph-by-paragraph.That system\n // doesn't understand blockquotes, so it will split up blockquotes into\n // more than one paragraph. A way to solve this would be to make that\n // system understand blockquotes, but then translators would have to\n // translate an entire, multi-paragraph blockquote at a time. Instead,\n // we choose to modify our blockquote matching to split up\n // multi-paragraph blockquotes into multiple blockquotes.\n //\n // There is also precedence for doing this splitting up in other\n // libraries, for instance CommonMark also splits up blockquotes with\n // empty lines into multiple blockquotes:\n // https://spec.commonmark.org/0.28/#example-205\n match: SimpleMarkdown.blockRegex(\n /^ *>[^\\n]+(\\n( *>)?[^\\n]+)*\\n{2,}/,\n ) as any,\n },\n // The lint rule never actually matches anything.\n // We check for lint after parsing, and, if we find any, we\n // transform the tree to add lint nodes. This rule is here\n // just for the react() function\n lint: {\n order: 1000,\n match: (s: any): any => null,\n parse: (capture: any, parse: any, state: any): any => ({}),\n },\n} as const;\n\n// @ts-expect-error - TS2345 - Argument of type '{ readonly columns: { readonly order: -2; readonly match: any; readonly parse: (capture: any, parse: any, state: any) => any; }; readonly crowdinId: { readonly order: -1; readonly match: (source: any, state: any, prevCapture: any) => any; readonly parse: (capture: any, parse: any, state: any) => any; }; ... 34 more ...' is not assignable to parameter of type 'ParserRules'.\nconst builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);\n\n/**\n * Parses a **Perseus** Markdown string into an AST.\n *\n * Use this function when you have content that may contain Perseus-specific\n * Markdown including things like math (`$...$`), tables, and widgets (`[[☃\n * ...]]`).\n * @param source The Perseus Markdown string to parse.\n * @param state The state object to pass to the parser.\n * @returns The Abstract Syntax Tree (AST) of the parsed Markdown.\n *\n * @todo The return type should be Array<SingleASTNode> but that breaks the\n * perseus-linter's types, so leaving it as `any` for now.\n */\nexport function parse(source: string, state?: any): any {\n const paragraphedSource = source + \"\\n\\n\";\n\n return builtParser(paragraphedSource, {\n ...state,\n inline: false,\n });\n}\n"],"names":["libName","libVersion","addLibraryVersionToPerseusDebug","traverseContent","ast","cb","Array","isArray","forEach","node","type","header","cells","items","table","col1","col2","content","rWidgetRule","mathMatcher","source","state","isBlock","length","index","inline","startIndex","braceLevel","character","endIndex","match","exec","slice","substring","mathMatch","blockMathMatch","TITLED_TABLE_REGEX","RegExp","SimpleMarkdown","defaultRules","nptable","regex","crowdinJiptMatcher","blockRegex","pureMarkdownRules","columns","order","parse","capture","crowdinId","prevCapture","isJipt","id","titledTable","title","parseInline","tableCapture","widget","link","inlineRegex","widgetType","blockMath","codeBlock","math","unescapedDollar","fence","lang","blockQuote","lint","s","builtParser","parserFor","paragraphedSource"],"mappings":";;;AAMA,MAAMA,OAAAA,CAAU,4BAChB,CAAaC,MAAAA,UA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cAAAA,CAAeK,UAAU,CAC5B,oCAER,CAKAyB,CAAAA,IAAAA,CAAM,CACFtB,KAAAA,CAAO,IACPhB,KAAO,CAACuC,CAAgB,EAAA,IAAA,CACxBtB,MAAO,CAACC,OAAAA,CAAcD,KAAY1B,CAAAA,KAAAA,IAAqB,EAAC,CAC5D,CACJ,EAGA,MAAMiD,WAAAA,CAAchC,cAAeiC,CAAAA,SAAS,CAAC3B,iBAAAA,CAe7C,CAAO,SAASG,KAAAA,CAAM3B,MAAc,CAAEC,KAAW,CAAA,CAC7C,MAAMmD,iBAAAA,CAAoBpD,OAAS,MAEnC,CAAA,OAAOkD,WAAYE,CAAAA,iBAAAA,CAAmB,CAClC,GAAGnD,KAAK,CACRI,MAAAA,CAAQ,KACZ,CACJ,CAAA;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* do not import anything from Perseus
|
|
6
6
|
*/
|
|
7
7
|
export { libVersion } from "./version";
|
|
8
|
+
export { traverseContent } from "./traversal";
|
|
8
9
|
export declare const pureMarkdownRules: {
|
|
9
10
|
readonly columns: {
|
|
10
11
|
readonly order: -2;
|
|
@@ -345,4 +346,17 @@ export declare const pureMarkdownRules: {
|
|
|
345
346
|
readonly html: (node: import("@khanacademy/simple-markdown").SingleASTNode, nestedOutput: import("@khanacademy/simple-markdown").Output<string>, state: import("@khanacademy/simple-markdown").State) => string;
|
|
346
347
|
};
|
|
347
348
|
};
|
|
348
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Parses a **Perseus** Markdown string into an AST.
|
|
351
|
+
*
|
|
352
|
+
* Use this function when you have content that may contain Perseus-specific
|
|
353
|
+
* Markdown including things like math (`$...$`), tables, and widgets (`[[☃
|
|
354
|
+
* ...]]`).
|
|
355
|
+
* @param source The Perseus Markdown string to parse.
|
|
356
|
+
* @param state The state object to pass to the parser.
|
|
357
|
+
* @returns The Abstract Syntax Tree (AST) of the parsed Markdown.
|
|
358
|
+
*
|
|
359
|
+
* @todo The return type should be Array<SingleASTNode> but that breaks the
|
|
360
|
+
* perseus-linter's types, so leaving it as `any` for now.
|
|
361
|
+
*/
|
|
362
|
+
export declare function parse(source: string, state?: any): any;
|
package/dist/index.js
CHANGED
|
@@ -9,11 +9,14 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
|
|
10
10
|
var SimpleMarkdown__default = /*#__PURE__*/_interopDefaultCompat(SimpleMarkdown);
|
|
11
11
|
|
|
12
|
-
const libName="@khanacademy/pure-markdown";const libVersion="2.0
|
|
12
|
+
const libName="@khanacademy/pure-markdown";const libVersion="2.2.0";perseusUtils.addLibraryVersionToPerseusDebug(libName,libVersion);
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const traverseContent=(ast,cb)=>{if(Array.isArray(ast)){ast.forEach(node=>traverseContent(node,cb));}else if(typeof ast==="object"&&ast!==null){cb(ast);if(ast.type==="table"){traverseContent(ast.header,cb);traverseContent(ast.cells,cb);}else if(ast.type==="list"){traverseContent(ast.items,cb);}else if(ast.type==="titledTable"){traverseContent(ast.table,cb);}else if(ast.type==="columns"){traverseContent(ast.col1,cb);traverseContent(ast.col2,cb);}else if(Array.isArray(ast.content)){traverseContent(ast.content,cb);}}};
|
|
15
|
+
|
|
16
|
+
const rWidgetRule=/^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;const mathMatcher=(source,state,isBlock)=>{const length=source.length;let index=0;if(isBlock){if(state.inline){return null}while(index<length&&source[index]===" "){index++;}}if(!(index<length&&source[index]==="$")){return null}index++;const startIndex=index;let braceLevel=0;while(index<length){const character=source[index];if(character==="\\"){index++;}else if(braceLevel<=0&&character==="$"){let endIndex=index+1;if(isBlock){const match=/^(?: *\n){2,}/.exec(source.slice(endIndex));endIndex=match?endIndex+match[0].length:null;}if(endIndex){return [source.substring(0,endIndex),source.substring(startIndex,index)]}return null}else if(character==="{"){braceLevel++;}else if(character==="}"){braceLevel--;}else if(character==="\n"&&source[index-1]==="\n"){return null}index++;}return null};const mathMatch=(source,state)=>mathMatcher(source,state,false);const blockMathMatch=(source,state)=>mathMatcher(source,state,true);const TITLED_TABLE_REGEX=new RegExp("^\\|\\| +(.*) +\\|\\| *\\n"+"("+SimpleMarkdown__default.default.defaultRules.nptable.match.regex.source.substring(1)+")");const crowdinJiptMatcher=SimpleMarkdown__default.default.blockRegex(/^(crwdns.*)\n\s*\n/);const pureMarkdownRules={...SimpleMarkdown__default.default.defaultRules,columns:{order:-2,match:SimpleMarkdown__default.default.blockRegex(/^([\s\S]*\n\n)={5,}\n\n([\s\S]*)/),parse:(capture,parse,state)=>{return {col1:parse(capture[1],state),col2:parse(capture[2],state)}}},crowdinId:{order:-1,match:(source,state,prevCapture)=>{if(state.isJipt){return crowdinJiptMatcher(source,state,prevCapture)}return null},parse:(capture,parse,state)=>({id:capture[1]})},titledTable:{order:SimpleMarkdown__default.default.defaultRules.nptable.order-.5,match:SimpleMarkdown__default.default.blockRegex(TITLED_TABLE_REGEX),parse:(capture,parse,state)=>{const title=SimpleMarkdown__default.default.parseInline(parse,capture[1],state);const tableCapture=capture.slice(2);const table=SimpleMarkdown__default.default.defaultRules.nptable.parse(tableCapture,parse,state);return {title:title,table:table}}},widget:{order:SimpleMarkdown__default.default.defaultRules.link.order-.75,match:SimpleMarkdown__default.default.inlineRegex(rWidgetRule),parse:(capture,parse,state)=>{return {id:capture[1],widgetType:capture[2]}}},blockMath:{order:SimpleMarkdown__default.default.defaultRules.codeBlock.order+.5,match:blockMathMatch,parse:(capture,parse,state)=>{return {content:capture[1]}}},math:{order:SimpleMarkdown__default.default.defaultRules.link.order-.25,match:mathMatch,parse:(capture,parse,state)=>{return {content:capture[1]}}},unescapedDollar:{order:SimpleMarkdown__default.default.defaultRules.link.order-.24,match:SimpleMarkdown__default.default.inlineRegex(/^(?!\\)\$/),parse:(capture,parse,state)=>{return {}}},fence:{...SimpleMarkdown__default.default.defaultRules.fence,parse:(capture,parse,state)=>{const node=SimpleMarkdown__default.default.defaultRules.fence.parse(capture,parse,state);if(node.lang==="alt"){return {type:"codeBlock",lang:"alt",content:parse(node.content+"\n\n",state)}}return node}},blockQuote:{...SimpleMarkdown__default.default.defaultRules.blockQuote,match:SimpleMarkdown__default.default.blockRegex(/^ *>[^\n]+(\n( *>)?[^\n]+)*\n{2,}/)},lint:{order:1e3,match:s=>null,parse:(capture,parse,state)=>({})}};const builtParser=SimpleMarkdown__default.default.parserFor(pureMarkdownRules);function parse(source,state){const paragraphedSource=source+"\n\n";return builtParser(paragraphedSource,{...state,inline:false})}
|
|
15
17
|
|
|
16
18
|
exports.libVersion = libVersion;
|
|
17
19
|
exports.parse = parse;
|
|
18
20
|
exports.pureMarkdownRules = pureMarkdownRules;
|
|
21
|
+
exports.traverseContent = traverseContent;
|
|
19
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/version.ts","../src/index.ts"],"sourcesContent":["// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"@khanacademy/perseus-utils\";\n\nconst libName = \"@khanacademy/pure-markdown\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n","/**\n * Contains markdown related functions in pure javascript,\n * extracted from perseus-markdown.jsx\n * Note that this file may be used in stand alone nodejs, thus\n * do not import anything from Perseus\n */\nexport {libVersion} from \"./version\";\n\nimport SimpleMarkdown from \"@khanacademy/simple-markdown\";\n\nconst rWidgetRule = /^\\[\\[\\u2603 (([a-z-]+) ([0-9]+))\\]\\]/;\n\n/**\n * This match function matches math in `$`s, such as:\n *\n * $y = x + 1$\n *\n * It functions roughly like the following regex:\n * /\\$([^\\$]*)\\$/\n *\n * Unfortunately, math may have other `$`s inside it, as\n * long as they are inside `{` braces `}`, mostly for\n * `\\text{ $math$ }`.\n *\n * To parse this, we can't use a regex, since we\n * should support arbitrary nesting (even though\n * MathJax actually only supports two levels of nesting\n * here, which we *could* parse with a regex).\n *\n * Non-regex matchers like this are now a first-class\n * concept in simple-markdown. Yay!\n *\n * This can also match block-math, which is math alone in a paragraph.\n */\nconst mathMatcher = (source: any, state: any, isBlock: boolean) => {\n const length = source.length;\n let index = 0;\n\n // When looking for blocks, skip over leading spaces\n if (isBlock) {\n if (state.inline) {\n return null;\n }\n while (index < length && source[index] === \" \") {\n index++;\n }\n }\n\n // Our source must start with a \"$\"\n if (!(index < length && source[index] === \"$\")) {\n return null;\n }\n\n index++;\n const startIndex = index;\n let braceLevel = 0;\n\n // Loop through the source, looking for a closing '$'\n // closing '$'s only count if they are not escaped with\n // a `\\`, and we are not in nested `{}` braces.\n while (index < length) {\n const character = source[index];\n\n if (character === \"\\\\\") {\n // Consume both the `\\` and the escaped char as a single\n // token.\n // This is so that the second `$` in `$\\\\$` closes\n // the math expression, since the first `\\` is escaping\n // the second `\\`, but the second `\\` is not escaping\n // the second `$`.\n // This also handles the case of escaping `$`s or\n // braces `\\{`\n index++;\n } else if (braceLevel <= 0 && character === \"$\") {\n let endIndex = index + 1;\n if (isBlock) {\n // Look for two trailing newlines after the closing `$`\n const match = /^(?: *\\n){2,}/.exec(source.slice(endIndex));\n // @ts-expect-error - TS2322 - Type 'number | null' is not assignable to type 'number'.\n endIndex = match ? endIndex + match[0].length : null;\n }\n\n // Return an array that looks like the results of a\n // regex's .exec function:\n // capture[0] is the whole string\n // capture[1] is the first \"paren\" match, which is the\n // content of the math here, as if we wrote the regex\n // /\\$([^\\$]*)\\$/\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (endIndex) {\n return [\n source.substring(0, endIndex),\n source.substring(startIndex, index),\n ];\n }\n return null;\n } else if (character === \"{\") {\n braceLevel++;\n } else if (character === \"}\") {\n braceLevel--;\n } else if (character === \"\\n\" && source[index - 1] === \"\\n\") {\n // This is a weird case we supported in the old\n // math implementation--double newlines break\n // math. I'm preserving it for now because content\n // creators might have questions with single '$'s\n // in paragraphs...\n return null;\n }\n\n index++;\n }\n\n // we didn't find a closing `$`\n return null;\n};\nconst mathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, false);\nconst blockMathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, true);\n\nconst TITLED_TABLE_REGEX = new RegExp(\n \"^\\\\|\\\\| +(.*) +\\\\|\\\\| *\\\\n\" +\n \"(\" +\n // The simple-markdown nptable regex, without\n // the leading `^`\n // @ts-expect-error - TS2532 - Object is possibly 'undefined'.\n SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +\n \")\",\n);\n\nconst crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\\n\\s*\\n/);\n\nexport const pureMarkdownRules = {\n ...SimpleMarkdown.defaultRules,\n\n // NOTE: basically ignored by JIPT. wraps everything at the outer layer\n columns: {\n order: -2,\n match: SimpleMarkdown.blockRegex(\n /^([\\s\\S]*\\n\\n)={5,}\\n\\n([\\s\\S]*)/,\n ) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n col1: parse(capture[1], state),\n col2: parse(capture[2], state),\n };\n },\n },\n crowdinId: {\n order: -1,\n match: (source: any, state: any, prevCapture: any): any => {\n // Only match on the just-in-place translation site\n if (state.isJipt) {\n return crowdinJiptMatcher(source, state, prevCapture);\n }\n return null;\n },\n parse: (capture: any, parse: any, state: any): any => ({\n id: capture[1],\n }),\n },\n // This is pretty much horrible, but we have a regex here to capture an\n // entire table + a title. capture[1] is the title. capture[2] of the\n // regex is a copy of the simple-markdown nptable regex. Then we turn\n // our capture[2] into tableCapture[0], and any further captures in\n // our table regex into tableCapture[1..], and we pass tableCapture to\n // our nptable regex\n titledTable: {\n // process immediately before nptables\n order: SimpleMarkdown.defaultRules.nptable.order - 0.5,\n match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX) as any,\n parse: (capture: any, parse: any, state: any): any => {\n const title = SimpleMarkdown.parseInline(parse, capture[1], state);\n\n // Remove our [0] and [1] captures, and pass the rest to\n // the nptable parser\n const tableCapture = capture.slice(2);\n const table = SimpleMarkdown.defaultRules.nptable.parse(\n tableCapture,\n parse,\n state,\n );\n return {\n title: title,\n table: table,\n };\n },\n },\n widget: {\n order: SimpleMarkdown.defaultRules.link.order - 0.75,\n match: SimpleMarkdown.inlineRegex(rWidgetRule) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n id: capture[1],\n widgetType: capture[2],\n };\n },\n },\n blockMath: {\n order: (SimpleMarkdown.defaultRules.codeBlock.order + 0.5) as any,\n match: blockMathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n math: {\n order: SimpleMarkdown.defaultRules.link.order - 0.25,\n match: mathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n unescapedDollar: {\n order: SimpleMarkdown.defaultRules.link.order - 0.24,\n match: SimpleMarkdown.inlineRegex(/^(?!\\\\)\\$/) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {};\n },\n },\n fence: {\n ...SimpleMarkdown.defaultRules.fence,\n parse: (capture: any, parse: any, state: any): any => {\n const node = SimpleMarkdown.defaultRules.fence.parse(\n capture,\n parse,\n state,\n );\n\n // support screenreader-only text with ```alt\n if (node.lang === \"alt\") {\n return {\n type: \"codeBlock\",\n lang: \"alt\",\n // default codeBlock parsing doesn't parse the contents.\n // We need to parse the contents for things like table\n // support :).\n // The \\n\\n is because the inside of the codeblock might\n // not end in double newlines for block rules, because\n // ordinarily we don't parse this :).\n content: parse(node.content + \"\\n\\n\", state),\n };\n }\n return node;\n },\n },\n blockQuote: {\n ...SimpleMarkdown.defaultRules.blockQuote,\n // Replace the less restrictive blockquote regex from SimpleMarkdown\n // with a more restrictive one. The only difference should be that\n //\n // > A blockquote\n //\n // > Another blockquote\n //\n // will now match as two different blockQuotes instead of a single\n // blockquote with some paragraph breaks in it.\n //\n // The main motivation for doing this is to provide better support for\n // translators translating blockquotes with multiple paragraphs in\n // them. When translating articles, we split up paragraphs, translate\n // them separately, and then recombine them. We do this so that\n // translators don't have to translate an entire article at a time,\n // they can instead translate paragraph-by-paragraph.That system\n // doesn't understand blockquotes, so it will split up blockquotes into\n // more than one paragraph. A way to solve this would be to make that\n // system understand blockquotes, but then translators would have to\n // translate an entire, multi-paragraph blockquote at a time. Instead,\n // we choose to modify our blockquote matching to split up\n // multi-paragraph blockquotes into multiple blockquotes.\n //\n // There is also precedence for doing this splitting up in other\n // libraries, for instance CommonMark also splits up blockquotes with\n // empty lines into multiple blockquotes:\n // https://spec.commonmark.org/0.28/#example-205\n match: SimpleMarkdown.blockRegex(\n /^ *>[^\\n]+(\\n( *>)?[^\\n]+)*\\n{2,}/,\n ) as any,\n },\n // The lint rule never actually matches anything.\n // We check for lint after parsing, and, if we find any, we\n // transform the tree to add lint nodes. This rule is here\n // just for the react() function\n lint: {\n order: 1000,\n match: (s: any): any => null,\n parse: (capture: any, parse: any, state: any): any => ({}),\n },\n} as const;\n\n// @ts-expect-error - TS2345 - Argument of type '{ readonly columns: { readonly order: -2; readonly match: any; readonly parse: (capture: any, parse: any, state: any) => any; }; readonly crowdinId: { readonly order: -1; readonly match: (source: any, state: any, prevCapture: any) => any; readonly parse: (capture: any, parse: any, state: any) => any; }; ... 34 more ...' is not assignable to parameter of type 'ParserRules'.\nconst builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);\n\nexport const parse = (source: string, state?: any): any => {\n const paragraphedSource = source + \"\\n\\n\";\n\n return builtParser(paragraphedSource, {\n ...state,\n inline: false,\n });\n};\n"],"names":["libName","libVersion","addLibraryVersionToPerseusDebug","rWidgetRule","mathMatcher","source","state","isBlock","length","index","inline","startIndex","braceLevel","character","endIndex","match","exec","slice","substring","mathMatch","blockMathMatch","TITLED_TABLE_REGEX","RegExp","SimpleMarkdown","defaultRules","nptable","regex","crowdinJiptMatcher","blockRegex","pureMarkdownRules","columns","order","parse","capture","col1","col2","crowdinId","prevCapture","isJipt","id","titledTable","title","parseInline","tableCapture","table","widget","link","inlineRegex","widgetType","blockMath","codeBlock","content","math","unescapedDollar","fence","node","lang","type","blockQuote","lint","s","builtParser","parserFor","paragraphedSource"],"mappings":";;;;;;;;;;;AAMA,MAAMA,OAAAA,CAAU,4BAChB,CAAaC,MAAAA,UAAAA,CAAa,SAE1BC,6CAAgCF,OAASC,CAAAA,UAAAA,CAAAA;;ACCzC,MAAME,WAAc,CAAA,sCAAA,CAwBpB,MAAMC,WAAAA,CAAc,CAACC,MAAaC,CAAAA,KAAAA,CAAYC,OAC1C,GAAA,CAAA,MAAMC,MAASH,CAAAA,MAAAA,CAAOG,MAAM,CAC5B,IAAIC,KAAQ,CAAA,CAAA,CAGZ,GAAIF,OAAAA,CAAS,CACT,GAAID,KAAMI,CAAAA,MAAM,CAAE,CACd,OAAO,IACX,CACA,MAAOD,KAAAA,CAAQD,MAAUH,EAAAA,MAAM,CAACI,KAAM,CAAA,GAAK,GAAK,CAAA,CAC5CA,KACJ,GAAA,CACJ,CAGA,GAAI,EAAEA,KAAAA,CAAQD,MAAUH,EAAAA,MAAM,CAACI,KAAAA,CAAM,GAAK,GAAE,EAAI,CAC5C,OAAO,IACX,CAEAA,QACA,MAAME,UAAAA,CAAaF,KACnB,CAAA,IAAIG,WAAa,CAKjB,CAAA,MAAOH,KAAQD,CAAAA,MAAAA,CAAQ,CACnB,MAAMK,SAAYR,CAAAA,MAAM,CAACI,KAAM,CAAA,CAE/B,GAAII,SAAAA,GAAc,IAAM,CAAA,CASpBJ,KACJ,GAAA,CAAA,KAAO,GAAIG,UAAc,EAAA,CAAA,EAAKC,SAAc,GAAA,GAAA,CAAK,CAC7C,IAAIC,QAAWL,CAAAA,KAAAA,CAAQ,EACvB,GAAIF,OAAAA,CAAS,CAET,MAAMQ,KAAQ,CAAA,eAAA,CAAgBC,IAAI,CAACX,OAAOY,KAAK,CAACH,QAEhDA,CAAAA,CAAAA,CAAAA,QAAAA,CAAWC,KAAQD,CAAAA,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AY,CAAC8B,KAAK,CAACtB,KAAK,CAChDC,OAAAA,CACAD,KACA1B,CAAAA,KAAAA,CAAAA,CAIJ,GAAIiD,IAAKC,CAAAA,IAAI,GAAK,KAAA,CAAO,CACrB,OAAO,CACHC,IAAM,CAAA,WAAA,CACND,KAAM,KAONL,CAAAA,OAAAA,CAASnB,KAAMuB,CAAAA,IAAAA,CAAKJ,OAAO,CAAG,MAAQ7C,CAAAA,KAAAA,CAC1C,CACJ,CACA,OAAOiD,IACX,CACJ,CACAG,CAAAA,UAAAA,CAAY,CACR,GAAGnC,gCAAeC,YAAY,CAACkC,UAAU,CA4BzC3C,KAAOQ,CAAAA,+BAAAA,CAAeK,UAAU,CAC5B,oCAER,CAKA+B,CAAAA,IAAAA,CAAM,CACF5B,KAAAA,CAAO,IACPhB,KAAO,CAAC6C,CAAgB,EAAA,IAAA,CACxB5B,MAAO,CAACC,OAAAA,CAAcD,KAAY1B,CAAAA,KAAAA,IAAqB,EAAC,CAC5D,CACJ,EAGA,MAAMuD,WAAAA,CAActC,+BAAeuC,CAAAA,SAAS,CAACjC,iBAAAA,CAE7C,CAAaG,MAAAA,KAAAA,CAAQ,CAAC3B,MAAAA,CAAgBC,KAClC,GAAA,CAAA,MAAMyD,iBAAoB1D,CAAAA,MAAAA,CAAS,OAEnC,OAAOwD,WAAAA,CAAYE,iBAAmB,CAAA,CAClC,GAAGzD,KAAK,CACRI,MAAQ,CAAA,KACZ,EACJ;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/version.ts","../src/traversal.ts","../src/index.ts"],"sourcesContent":["// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"@khanacademy/perseus-utils\";\n\nconst libName = \"@khanacademy/pure-markdown\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n","/**\n * Traverse all of the nodes in the Perseus Markdown AST. The callback is\n * called for each node in the AST.\n */\nexport const traverseContent = (ast: any, cb: (node: any) => void) => {\n if (Array.isArray(ast)) {\n ast.forEach((node) => traverseContent(node, cb));\n } else if (typeof ast === \"object\" && ast !== null) {\n cb(ast);\n if (ast.type === \"table\") {\n traverseContent(ast.header, cb);\n traverseContent(ast.cells, cb);\n } else if (ast.type === \"list\") {\n traverseContent(ast.items, cb);\n } else if (ast.type === \"titledTable\") {\n traverseContent(ast.table, cb);\n } else if (ast.type === \"columns\") {\n traverseContent(ast.col1, cb);\n traverseContent(ast.col2, cb);\n } else if (Array.isArray(ast.content)) {\n traverseContent(ast.content, cb);\n }\n }\n};\n","/**\n * Contains markdown related functions in pure javascript,\n * extracted from perseus-markdown.jsx\n * Note that this file may be used in stand alone nodejs, thus\n * do not import anything from Perseus\n */\nexport {libVersion} from \"./version\";\n\nexport {traverseContent} from \"./traversal\";\n\nimport SimpleMarkdown from \"@khanacademy/simple-markdown\";\n\nconst rWidgetRule = /^\\[\\[\\u2603 (([a-z-]+) ([0-9]+))\\]\\]/;\n\n/**\n * This match function matches math in `$`s, such as:\n *\n * $y = x + 1$\n *\n * It functions roughly like the following regex:\n * /\\$([^\\$]*)\\$/\n *\n * Unfortunately, math may have other `$`s inside it, as\n * long as they are inside `{` braces `}`, mostly for\n * `\\text{ $math$ }`.\n *\n * To parse this, we can't use a regex, since we\n * should support arbitrary nesting (even though\n * MathJax actually only supports two levels of nesting\n * here, which we *could* parse with a regex).\n *\n * Non-regex matchers like this are now a first-class\n * concept in simple-markdown. Yay!\n *\n * This can also match block-math, which is math alone in a paragraph.\n */\nconst mathMatcher = (source: any, state: any, isBlock: boolean) => {\n const length = source.length;\n let index = 0;\n\n // When looking for blocks, skip over leading spaces\n if (isBlock) {\n if (state.inline) {\n return null;\n }\n while (index < length && source[index] === \" \") {\n index++;\n }\n }\n\n // Our source must start with a \"$\"\n if (!(index < length && source[index] === \"$\")) {\n return null;\n }\n\n index++;\n const startIndex = index;\n let braceLevel = 0;\n\n // Loop through the source, looking for a closing '$'\n // closing '$'s only count if they are not escaped with\n // a `\\`, and we are not in nested `{}` braces.\n while (index < length) {\n const character = source[index];\n\n if (character === \"\\\\\") {\n // Consume both the `\\` and the escaped char as a single\n // token.\n // This is so that the second `$` in `$\\\\$` closes\n // the math expression, since the first `\\` is escaping\n // the second `\\`, but the second `\\` is not escaping\n // the second `$`.\n // This also handles the case of escaping `$`s or\n // braces `\\{`\n index++;\n } else if (braceLevel <= 0 && character === \"$\") {\n let endIndex = index + 1;\n if (isBlock) {\n // Look for two trailing newlines after the closing `$`\n const match = /^(?: *\\n){2,}/.exec(source.slice(endIndex));\n // @ts-expect-error - TS2322 - Type 'number | null' is not assignable to type 'number'.\n endIndex = match ? endIndex + match[0].length : null;\n }\n\n // Return an array that looks like the results of a\n // regex's .exec function:\n // capture[0] is the whole string\n // capture[1] is the first \"paren\" match, which is the\n // content of the math here, as if we wrote the regex\n // /\\$([^\\$]*)\\$/\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (endIndex) {\n return [\n source.substring(0, endIndex),\n source.substring(startIndex, index),\n ];\n }\n return null;\n } else if (character === \"{\") {\n braceLevel++;\n } else if (character === \"}\") {\n braceLevel--;\n } else if (character === \"\\n\" && source[index - 1] === \"\\n\") {\n // This is a weird case we supported in the old\n // math implementation--double newlines break\n // math. I'm preserving it for now because content\n // creators might have questions with single '$'s\n // in paragraphs...\n return null;\n }\n\n index++;\n }\n\n // we didn't find a closing `$`\n return null;\n};\nconst mathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, false);\nconst blockMathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, true);\n\nconst TITLED_TABLE_REGEX = new RegExp(\n \"^\\\\|\\\\| +(.*) +\\\\|\\\\| *\\\\n\" +\n \"(\" +\n // The simple-markdown nptable regex, without\n // the leading `^`\n // @ts-expect-error - TS2532 - Object is possibly 'undefined'.\n SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +\n \")\",\n);\n\nconst crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\\n\\s*\\n/);\n\nexport const pureMarkdownRules = {\n ...SimpleMarkdown.defaultRules,\n\n // NOTE: basically ignored by JIPT. wraps everything at the outer layer\n columns: {\n order: -2,\n match: SimpleMarkdown.blockRegex(\n /^([\\s\\S]*\\n\\n)={5,}\\n\\n([\\s\\S]*)/,\n ) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n col1: parse(capture[1], state),\n col2: parse(capture[2], state),\n };\n },\n },\n crowdinId: {\n order: -1,\n match: (source: any, state: any, prevCapture: any): any => {\n // Only match on the just-in-place translation site\n if (state.isJipt) {\n return crowdinJiptMatcher(source, state, prevCapture);\n }\n return null;\n },\n parse: (capture: any, parse: any, state: any): any => ({\n id: capture[1],\n }),\n },\n // This is pretty much horrible, but we have a regex here to capture an\n // entire table + a title. capture[1] is the title. capture[2] of the\n // regex is a copy of the simple-markdown nptable regex. Then we turn\n // our capture[2] into tableCapture[0], and any further captures in\n // our table regex into tableCapture[1..], and we pass tableCapture to\n // our nptable regex\n titledTable: {\n // process immediately before nptables\n order: SimpleMarkdown.defaultRules.nptable.order - 0.5,\n match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX) as any,\n parse: (capture: any, parse: any, state: any): any => {\n const title = SimpleMarkdown.parseInline(parse, capture[1], state);\n\n // Remove our [0] and [1] captures, and pass the rest to\n // the nptable parser\n const tableCapture = capture.slice(2);\n const table = SimpleMarkdown.defaultRules.nptable.parse(\n tableCapture,\n parse,\n state,\n );\n return {\n title: title,\n table: table,\n };\n },\n },\n widget: {\n order: SimpleMarkdown.defaultRules.link.order - 0.75,\n match: SimpleMarkdown.inlineRegex(rWidgetRule) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n id: capture[1],\n widgetType: capture[2],\n };\n },\n },\n blockMath: {\n order: (SimpleMarkdown.defaultRules.codeBlock.order + 0.5) as any,\n match: blockMathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n math: {\n order: SimpleMarkdown.defaultRules.link.order - 0.25,\n match: mathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n unescapedDollar: {\n order: SimpleMarkdown.defaultRules.link.order - 0.24,\n match: SimpleMarkdown.inlineRegex(/^(?!\\\\)\\$/) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {};\n },\n },\n fence: {\n ...SimpleMarkdown.defaultRules.fence,\n parse: (capture: any, parse: any, state: any): any => {\n const node = SimpleMarkdown.defaultRules.fence.parse(\n capture,\n parse,\n state,\n );\n\n // support screenreader-only text with ```alt\n if (node.lang === \"alt\") {\n return {\n type: \"codeBlock\",\n lang: \"alt\",\n // default codeBlock parsing doesn't parse the contents.\n // We need to parse the contents for things like table\n // support :).\n // The \\n\\n is because the inside of the codeblock might\n // not end in double newlines for block rules, because\n // ordinarily we don't parse this :).\n content: parse(node.content + \"\\n\\n\", state),\n };\n }\n return node;\n },\n },\n blockQuote: {\n ...SimpleMarkdown.defaultRules.blockQuote,\n // Replace the less restrictive blockquote regex from SimpleMarkdown\n // with a more restrictive one. The only difference should be that\n //\n // > A blockquote\n //\n // > Another blockquote\n //\n // will now match as two different blockQuotes instead of a single\n // blockquote with some paragraph breaks in it.\n //\n // The main motivation for doing this is to provide better support for\n // translators translating blockquotes with multiple paragraphs in\n // them. When translating articles, we split up paragraphs, translate\n // them separately, and then recombine them. We do this so that\n // translators don't have to translate an entire article at a time,\n // they can instead translate paragraph-by-paragraph.That system\n // doesn't understand blockquotes, so it will split up blockquotes into\n // more than one paragraph. A way to solve this would be to make that\n // system understand blockquotes, but then translators would have to\n // translate an entire, multi-paragraph blockquote at a time. Instead,\n // we choose to modify our blockquote matching to split up\n // multi-paragraph blockquotes into multiple blockquotes.\n //\n // There is also precedence for doing this splitting up in other\n // libraries, for instance CommonMark also splits up blockquotes with\n // empty lines into multiple blockquotes:\n // https://spec.commonmark.org/0.28/#example-205\n match: SimpleMarkdown.blockRegex(\n /^ *>[^\\n]+(\\n( *>)?[^\\n]+)*\\n{2,}/,\n ) as any,\n },\n // The lint rule never actually matches anything.\n // We check for lint after parsing, and, if we find any, we\n // transform the tree to add lint nodes. This rule is here\n // just for the react() function\n lint: {\n order: 1000,\n match: (s: any): any => null,\n parse: (capture: any, parse: any, state: any): any => ({}),\n },\n} as const;\n\n// @ts-expect-error - TS2345 - Argument of type '{ readonly columns: { readonly order: -2; readonly match: any; readonly parse: (capture: any, parse: any, state: any) => any; }; readonly crowdinId: { readonly order: -1; readonly match: (source: any, state: any, prevCapture: any) => any; readonly parse: (capture: any, parse: any, state: any) => any; }; ... 34 more ...' is not assignable to parameter of type 'ParserRules'.\nconst builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);\n\n/**\n * Parses a **Perseus** Markdown string into an AST.\n *\n * Use this function when you have content that may contain Perseus-specific\n * Markdown including things like math (`$...$`), tables, and widgets (`[[☃\n * ...]]`).\n * @param source The Perseus Markdown string to parse.\n * @param state The state object to pass to the parser.\n * @returns The Abstract Syntax Tree (AST) of the parsed Markdown.\n *\n * @todo The return type should be Array<SingleASTNode> but that breaks the\n * perseus-linter's types, so leaving it as `any` for now.\n */\nexport function parse(source: string, state?: any): any {\n const paragraphedSource = source + \"\\n\\n\";\n\n return builtParser(paragraphedSource, {\n ...state,\n inline: false,\n });\n}\n"],"names":["libName","libVersion","addLibraryVersionToPerseusDebug","traverseContent","ast","cb","Array","isArray","forEach","node","type","header","cells","items","table","col1","col2","content","rWidgetRule","mathMatcher","source","state","isBlock","length","index","inline","startIndex","braceLevel","character","endIndex","match","exec","slice","substring","mathMatch","blockMathMatch","TITLED_TABLE_REGEX","RegExp","SimpleMarkdown","defaultRules","nptable","regex","crowdinJiptMatcher","blockRegex","pureMarkdownRules","columns","order","parse","capture","crowdinId","prevCapture","isJipt","id","titledTable","title","parseInline","tableCapture","widget","link","inlineRegex","widgetType","blockMath","codeBlock","math","unescapedDollar","fence","lang","blockQuote","lint","s","built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Z,IACX,CACJ,CACA0D,CAAAA,UAAAA,CAAY,CACR,GAAG7B,gCAAeC,YAAY,CAAC4B,UAAU,CA4BzCrC,KAAOQ,CAAAA,+BAAAA,CAAeK,UAAU,CAC5B,oCAER,CAKAyB,CAAAA,IAAAA,CAAM,CACFtB,KAAAA,CAAO,IACPhB,KAAO,CAACuC,CAAgB,EAAA,IAAA,CACxBtB,MAAO,CAACC,OAAAA,CAAcD,KAAY1B,CAAAA,KAAAA,IAAqB,EAAC,CAC5D,CACJ,EAGA,MAAMiD,WAAAA,CAAchC,+BAAeiC,CAAAA,SAAS,CAAC3B,iBAAAA,CAe7C,CAAO,SAASG,KAAAA,CAAM3B,MAAc,CAAEC,KAAW,CAAA,CAC7C,MAAMmD,iBAAAA,CAAoBpD,OAAS,MAEnC,CAAA,OAAOkD,WAAYE,CAAAA,iBAAAA,CAAmB,CAClC,GAAGnD,KAAK,CACRI,MAAAA,CAAQ,KACZ,CACJ,CAAA;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "SimpleMarkdown instance with non-react Perseus rules",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.0
|
|
6
|
+
"version": "2.2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@khanacademy/
|
|
26
|
-
"@khanacademy/
|
|
25
|
+
"@khanacademy/simple-markdown": "2.1.0",
|
|
26
|
+
"@khanacademy/perseus-utils": "2.1.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"perseus-build-settings": "0.9.0"
|