@cutting/markdown 0.1.3 → 0.1.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundleMarkdown.d.ts","sourceRoot":"","sources":["../../src/bundleMarkdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,SAAS,CAAC;AAM5D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAE3C,wBAAsB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"bundleMarkdown.d.ts","sourceRoot":"","sources":["../../src/bundleMarkdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,SAAS,CAAC;AAM5D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAE3C,wBAAsB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwE1E;AAED,MAAM,MAAM,QAAQ,GAAG,eAAe,GAAG;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,wBAAsB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CA0BzE"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/remark/remark-code-title.ts","../../src/bundleMarkdown.ts","../../src/remark/remark-inline-code-language.ts"],"sourcesContent":["import { visit } from 'unist-util-visit';\n\ntype Tree = Parameters<typeof visit>[0];\n\nexport function remarkCodeTitles() {\n return (tree: Tree): void =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n visit(tree, 'code', (node: { lang?: string }, index: number, parent: any) => {\n const nodeLang = node.lang || '';\n let language = '';\n let title = '';\n\n if (nodeLang.includes(':')) {\n language = nodeLang.slice(0, nodeLang.search(':'));\n title = nodeLang.slice(nodeLang.search(':') + 1, nodeLang.length);\n }\n\n if (!title) {\n return;\n }\n\n const className = 'remark-code-title';\n\n const titleNode = {\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [{ type: 'mdxJsxAttribute', name: 'className', value: className }],\n children: [{ type: 'text', value: title }],\n data: { _xdmExplicitJsx: true },\n };\n\n parent.children.splice(index, 0, titleNode);\n node.lang = language;\n });\n}\n","import parseFrontMatter from 'front-matter';\nimport { bundleMDX } from 'mdx-bundler';\nimport remarkFootnotes from 'remark-footnotes';\nimport remarkMdxImages from 'remark-mdx-images';\nimport remarkBreaks from 'remark-breaks';\nimport { remarkCodeTitles } from './remark/remark-code-title';\nimport { remarkInlineCodeLanguageCreator } from './remark/remark-inline-code-language';\nimport type { FrontMatter, FrontMatterMeta } from './types';\nimport readingTime from 'reading-time';\nimport { join } from 'path';\nimport { readFile, readdir } from 'fs/promises';\nimport { DateTime } from 'luxon';\n\nexport type MarkdownAttributes = {\n title: string;\n};\n\nconst root = process.cwd();\n\ntype Matter = ReturnType<typeof bundleMDX>;\n\nexport async function bundleMarkdown(markdownPath: string): Promise<Matter> {\n const source = await readFile(markdownPath, 'utf-8');\n\n const { default: remarkGfm } = await import('remark-gfm');\n const { default: rehypeAutolinkHeadings } = await import('rehype-autolink-headings');\n\n const { default: rehypeSlug } = await import('rehype-slug');\n const { default: remarkMath } = await import('remark-math');\n\n const { default:
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/remark/remark-code-title.ts","../../src/bundleMarkdown.ts","../../src/remark/remark-inline-code-language.ts"],"sourcesContent":["import { visit } from 'unist-util-visit';\n\ntype Tree = Parameters<typeof visit>[0];\n\nexport function remarkCodeTitles() {\n return (tree: Tree): void =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n visit(tree, 'code', (node: { lang?: string }, index: number, parent: any) => {\n const nodeLang = node.lang || '';\n let language = '';\n let title = '';\n\n if (nodeLang.includes(':')) {\n language = nodeLang.slice(0, nodeLang.search(':'));\n title = nodeLang.slice(nodeLang.search(':') + 1, nodeLang.length);\n }\n\n if (!title) {\n return;\n }\n\n const className = 'remark-code-title';\n\n const titleNode = {\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [{ type: 'mdxJsxAttribute', name: 'className', value: className }],\n children: [{ type: 'text', value: title }],\n data: { _xdmExplicitJsx: true },\n };\n\n parent.children.splice(index, 0, titleNode);\n node.lang = language;\n });\n}\n","import parseFrontMatter from 'front-matter';\nimport { bundleMDX } from 'mdx-bundler';\nimport remarkFootnotes from 'remark-footnotes';\nimport remarkMdxImages from 'remark-mdx-images';\nimport remarkBreaks from 'remark-breaks';\nimport { remarkCodeTitles } from './remark/remark-code-title';\nimport { remarkInlineCodeLanguageCreator } from './remark/remark-inline-code-language';\nimport type { FrontMatter, FrontMatterMeta } from './types';\nimport readingTime from 'reading-time';\nimport { join } from 'path';\nimport { readFile, readdir } from 'fs/promises';\nimport { DateTime } from 'luxon';\n\nexport type MarkdownAttributes = {\n title: string;\n};\n\nconst root = process.cwd();\n\ntype Matter = ReturnType<typeof bundleMDX>;\n\nexport async function bundleMarkdown(markdownPath: string): Promise<Matter> {\n const source = await readFile(markdownPath, 'utf-8');\n\n const { default: remarkGfm } = await import('remark-gfm');\n const { default: rehypeAutolinkHeadings } = await import('rehype-autolink-headings');\n\n const { default: rehypeSlug } = await import('rehype-slug');\n const { default: remarkMath } = await import('remark-math');\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const { default: rehypeMathjax } = await import('rehype-mathjax');\n const { default: rehypeCitation } = await import('rehype-citation');\n const { default: rehypePrismPlus } = await import('rehype-prism-plus');\n const { default: rehypeRaw } = await import('rehype-raw');\n const { default: rehypePresetMinify } = await import('rehype-preset-minify');\n\n const remarkInlineCodeLanguage = await remarkInlineCodeLanguageCreator();\n\n process.env.ESBUILD_BINARY_PATH = join(root, 'node_modules', 'esbuild', 'bin', 'esbuild');\n\n const post = await bundleMDX({\n source,\n mdxOptions(options) {\n options.remarkPlugins = [\n ...(options.remarkPlugins ?? []),\n remarkMdxImages,\n remarkGfm,\n remarkBreaks,\n remarkCodeTitles,\n remarkInlineCodeLanguage,\n [remarkFootnotes, { inlineNotes: true }],\n remarkMath,\n ];\n options.rehypePlugins = [\n ...(options.rehypePlugins ?? []),\n rehypeAutolinkHeadings,\n rehypeSlug,\n rehypeMathjax,\n [rehypeCitation, { path: join(root, 'data') }],\n [rehypePrismPlus, { ignoreMissing: true }],\n rehypePresetMinify,\n [\n rehypeRaw,\n {\n passThrough: [\n 'mdxjsEsm',\n 'mdxFlowExpression',\n 'mdxTextExpression',\n 'mdxJsxFlowElement',\n 'mdxJsxTextElement',\n ],\n },\n ],\n ];\n\n return options;\n },\n }).catch((e) => {\n console.error(e);\n throw e;\n });\n\n return {\n ...post,\n frontmatter: {\n meta: {\n readingTime: readingTime(post.code),\n ...post.frontmatter.meta,\n },\n },\n };\n}\n\nexport type PostData = FrontMatterMeta & { formattedDate: string };\n\nexport async function getPosts(postsRootPath: string): Promise<PostData[]> {\n const postsPath = await readdir(postsRootPath, {\n withFileTypes: true,\n });\n\n const posts: PostData[] = [];\n\n for (const dirent of postsPath) {\n const file = await readFile(join(postsRootPath, dirent.name, 'index.md'));\n\n const {\n attributes: {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n meta: { date, slug, ...meta },\n },\n } = parseFrontMatter(file.toString()) as { attributes: FrontMatter };\n\n posts.push({\n slug: dirent.name.replace(/\\.mdx/, ''),\n date: new Date(date).toISOString(),\n formattedDate: DateTime.fromISO(date).toLocaleString(DateTime.DATE_FULL),\n ...meta,\n });\n }\n\n return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());\n}\n","// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport async function remarkInlineCodeLanguageCreator() {\n const { visit } = await import('unist-util-visit');\n const { escapeHtml } = await import('@cutting/util');\n\n return function remarkInlineCodeLanguage() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (tree: any): void =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n visit(tree, 'inlineCode', (node: any) => {\n const className = `language-typescript`;\n\n node.type = 'html';\n node.value = `<code class=\"${className} cutting-inline\">${escapeHtml(node.value)}</code>`;\n });\n };\n}\n"],"names":["remarkCodeTitles","tree","visit","node","index","parent","nodeLang","lang","language","title","includes","slice","search","length","children","splice","type","name","attributes","value","data","_xdmExplicitJsx","root","process","cwd","async","bundleMarkdown","markdownPath","source","readFile","default","remarkGfm","import","rehypeAutolinkHeadings","rehypeSlug","remarkMath","rehypeMathjax","rehypeCitation","rehypePrismPlus","rehypeRaw","rehypePresetMinify","remarkInlineCodeLanguage","escapeHtml","remarkInlineCodeLanguageCreator","env","ESBUILD_BINARY_PATH","join","post","bundleMDX","mdxOptions","options","remarkPlugins","remarkMdxImages","remarkBreaks","remarkFootnotes","inlineNotes","rehypePlugins","path","ignoreMissing","passThrough","catch","e","console","error","frontmatter","meta","readingTime","code","getPosts","postsRootPath","postsPath","readdir","withFileTypes","posts","dirent","file","date","slug","parseFrontMatter","toString","push","replace","Date","toISOString","formattedDate","DateTime","fromISO","toLocaleString","DATE_FULL","sort","a","b","getTime"],"mappings":"iWAIgBA,IACd,OAAQC,GAENC,EAAMD,EAAM,QAAQ,CAACE,EAAyBC,EAAeC,KAC3D,MAAMC,EAAWH,EAAKI,MAAQ,GAC9B,IAAIC,EAAW,GACXC,EAAQ,GAERH,EAASI,SAAS,OACpBF,EAAW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,EACAE,EACA,CAACC,EAAgB,CAAEoB,KAAMX,EAAKxB,EAAM,UACpC,CAACgB,EAAiB,CAAEoB,eAAe,IACnClB,EACA,CACED,EACA,CACEoB,YAAa,CACX,WACA,oBACA,oBACA,oBACA,wBAMDT,KAERU,OAAOC,IAER,MADAC,QAAQC,MAAMF,GACRA,CAAC,IAGT,MAAO,IACFd,EACHiB,YAAa,CACXC,KAAM,CACJC,YAAaA,EAAYnB,EAAKoB,SAC3BpB,EAAKiB,YAAYC,OAI5B,CAIOxC,eAAe2C,EAASC,GAC7B,MAAMC,QAAkBC,EAAQF,EAAe,CAC7CG,eAAe,IAGXC,EAAoB,GAE1B,IAAK,MAAMC,KAAUJ,EAAW,CAC9B,MAAMK,QAAa9C,EAASiB,EAAKuB,EAAeK,EAAOzD,KAAM,cAG3DC,YAEE+C,MAAMW,KAAEA,EAAIC,KAAEA,KAASZ,KAEvBa,EAAiBH,EAAKI,YAE1BN,EAAMO,KAAK,CACTH,KAAMH,EAAOzD,KAAKgE,QAAQ,QAAS,IACnCL,KAAM,IAAIM,KAAKN,GAAMO,cACrBC,cAAeC,EAASC,QAAQV,GAAMW,eAAeF,EAASG,cAC3DvB,GAEN,CAED,OAAOQ,EAAMgB,MAAK,CAACC,EAAGC,IAAM,IAAIT,KAAKS,EAAEf,MAAMgB,UAAY,IAAIV,KAAKQ,EAAEd,MAAMgB,WAC5E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutting/markdown",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dagda1/cuttingedge.git"
|
|
@@ -14,39 +14,41 @@
|
|
|
14
14
|
"format": "^0.2.2",
|
|
15
15
|
"front-matter": "^4.0.2",
|
|
16
16
|
"github-slugger": "^2.0.0",
|
|
17
|
-
"esbuild": "^0.19.
|
|
17
|
+
"esbuild": "^0.19.5",
|
|
18
18
|
"image-size": "^1.0.2",
|
|
19
19
|
"js-yaml": "^4.1.0",
|
|
20
|
-
"katex": "^0.16.
|
|
20
|
+
"katex": "^0.16.9",
|
|
21
21
|
"leva": "^0.9.35",
|
|
22
|
-
"
|
|
22
|
+
"luxon": "^3.4.3",
|
|
23
|
+
"maath": "^0.10.4",
|
|
23
24
|
"mathjax-full": "3.2.2",
|
|
24
25
|
"mdast-util-to-markdown": "^2.1.0",
|
|
25
26
|
"mdx-bundler": "^9.2.1",
|
|
26
27
|
"reading-time": "^1.5.0",
|
|
27
|
-
"rehype-autolink-headings": "^
|
|
28
|
-
"rehype-citation": "^
|
|
29
|
-
"rehype-highlight": "^
|
|
30
|
-
"rehype-mathjax": "^
|
|
28
|
+
"rehype-autolink-headings": "^7.0.0",
|
|
29
|
+
"rehype-citation": "^2.0.0",
|
|
30
|
+
"rehype-highlight": "^7.0.0",
|
|
31
|
+
"rehype-mathjax": "^5.0.0",
|
|
31
32
|
"rehype-prism-plus": "^1.6.3",
|
|
32
|
-
"rehype-slug": "^
|
|
33
|
+
"rehype-slug": "^6.0.0",
|
|
33
34
|
"rehype-toc": "^3.0.2",
|
|
34
|
-
"remark-breaks": "^
|
|
35
|
-
"remark-gfm": "^
|
|
35
|
+
"remark-breaks": "^4.0.0",
|
|
36
|
+
"remark-gfm": "^4.0.0",
|
|
36
37
|
"remark-footnotes": "^4.0.1",
|
|
37
|
-
"remark-math": "^
|
|
38
|
+
"remark-math": "^6.0.0",
|
|
38
39
|
"remark-mdx-images": "^2.0.0",
|
|
39
|
-
"rehype-preset-minify": "^
|
|
40
|
-
"rehype-raw": "^
|
|
40
|
+
"rehype-preset-minify": "^7.0.0",
|
|
41
|
+
"rehype-raw": "^7.0.0",
|
|
41
42
|
"resize-observer-polyfill": "^1.5.1",
|
|
42
43
|
"unist-util-visit": "^5.0.0",
|
|
43
|
-
"@cutting/util": "4.58.
|
|
44
|
+
"@cutting/util": "4.58.4"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"@cutting/
|
|
47
|
+
"@types/luxon": "^3.3.3",
|
|
48
|
+
"eslint": "8.52.0",
|
|
49
|
+
"typescript": "5.2.2",
|
|
50
|
+
"@cutting/devtools": "4.63.3",
|
|
51
|
+
"@cutting/eslint-config": "4.45.1",
|
|
50
52
|
"@cutting/tsconfig": "4.40.1",
|
|
51
53
|
"@cutting/useful-types": "4.40.1"
|
|
52
54
|
},
|