|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -/// <reference types="remark-parse" /> |
4 | | -/// <reference types="remark-stringify" /> |
| 3 | +import remarkHeadings from '@vcarl/remark-headings'; |
| 4 | +import rehypeAutolinkHeadings from 'rehype-autolink-headings'; |
| 5 | +import rehypeSlug from 'rehype-slug'; |
| 6 | +import remarkGfm from 'remark-gfm'; |
5 | 7 |
|
6 | | -/** |
7 | | - * @typedef {import('mdast').Root} Root |
8 | | - * @typedef {import('unified').Processor<Root>} Processor |
9 | | - */ |
10 | | - |
11 | | -import * as remarkHeadings from '@vcarl/remark-headings'; |
12 | | -import * as mdastAutoLink from 'mdast-util-gfm-autolink-literal'; |
13 | | -import * as mdastTable from 'mdast-util-gfm-table'; |
14 | | -import * as rehypeAutolinkHeadings from 'rehype-autolink-headings'; |
15 | | -import * as rehypeRaw from 'rehype-raw'; |
16 | | -import * as rehypeShikiji from 'rehype-shikiji'; |
17 | | -import * as rehypeSlug from 'rehype-slug'; |
18 | | - |
19 | | -import { LANGUAGES, DEFAULT_THEME } from './shiki.config.mjs'; |
20 | | - |
21 | | -/** |
22 | | - * This function is used to add individual `mdast` plugins to the unified/mdx |
23 | | - * processor with the intent of being able to customize plugins |
24 | | - * |
25 | | - * @returns {void} |
26 | | - */ |
27 | | -function nextMdastPlugins() { |
28 | | - const self = /** @type {Processor} */ (this); |
29 | | - const data = self.data(); |
30 | | - |
31 | | - const fromMarkdownExtensions = |
32 | | - data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []); |
33 | | - |
34 | | - const toMarkdownExtensions = |
35 | | - data.toMarkdownExtensions || (data.toMarkdownExtensions = []); |
36 | | - |
37 | | - // Converts plain URLs on Markdown to HTML Anchor Tags |
38 | | - fromMarkdownExtensions.push(mdastAutoLink.gfmAutolinkLiteralFromMarkdown()); |
39 | | - toMarkdownExtensions.push(mdastAutoLink.gfmAutolinkLiteralToMarkdown()); |
40 | | - |
41 | | - // Converts plain Markdown Tables (GFM) to HTML Tables |
42 | | - fromMarkdownExtensions.push(mdastTable.gfmTableFromMarkdown); |
43 | | - toMarkdownExtensions.push(mdastTable.gfmTableToMarkdown()); |
44 | | -} |
| 8 | +import rehypeShikiji from './next.mdx.shiki.mjs'; |
45 | 9 |
|
46 | 10 | /** |
47 | 11 | * Provides all our Rehype Plugins that are used within MDX |
48 | 12 | * |
49 | | - * @param {'md' | 'mdx'} fileExtension |
50 | | - * @returns {import('unified').Plugin[]} |
| 13 | + * @type {import('unified').Plugin[]} |
51 | 14 | */ |
52 | | -export function nextRehypePlugins(fileExtension) { |
53 | | - const rehypePlugins = [ |
54 | | - // Generates `id` attributes for headings (H1, ...) |
55 | | - rehypeSlug.default, |
56 | | - [ |
57 | | - // Automatically add anchor links to headings (H1, ...) |
58 | | - rehypeAutolinkHeadings.default, |
59 | | - { |
60 | | - behaviour: 'append', |
61 | | - properties: { ariaHidden: true, tabIndex: -1, class: 'anchor' }, |
62 | | - }, |
63 | | - ], |
64 | | - [ |
65 | | - // Syntax Highlighter for Code Blocks |
66 | | - rehypeShikiji.default, |
67 | | - { theme: DEFAULT_THEME, langs: LANGUAGES }, |
68 | | - ], |
69 | | - ]; |
70 | | - |
71 | | - if (fileExtension === 'md') { |
72 | | - // We add this plugin at the top of the array as it is supposed to parse raw HTML |
73 | | - // before any other plugins (such as adding headings, etc) |
74 | | - // before any of the other plugins being applied |
75 | | - rehypePlugins.unshift(rehypeRaw.default); |
76 | | - } |
77 | | - |
78 | | - return rehypePlugins; |
79 | | -} |
| 15 | +export const NEXT_REHYPE_PLUGINS = [ |
| 16 | + // Generates `id` attributes for headings (H1, ...) |
| 17 | + rehypeSlug, |
| 18 | + // Automatically add anchor links to headings (H1, ...) |
| 19 | + [rehypeAutolinkHeadings, { properties: { tabIndex: -1, class: 'anchor' } }], |
| 20 | + // Adds our syntax highlighter (Shikiji) to Codeboxes |
| 21 | + rehypeShikiji, |
| 22 | +]; |
80 | 23 |
|
81 | 24 | /** |
82 | 25 | * Provides all our Remark Plugins that are used within MDX |
83 | 26 | * |
84 | | - * @param {'md' | 'mdx'} fileExtension |
85 | | - * @returns {import('unified').Plugin[]} |
| 27 | + * @type {import('unified').Plugin[]} |
86 | 28 | */ |
87 | | -export function nextRemarkPlugins() { |
88 | | - return [remarkHeadings.default, nextMdastPlugins]; |
89 | | -} |
| 29 | +export const NEXT_REMARK_PLUGINS = [remarkGfm, remarkHeadings]; |
0 commit comments