remark-gfm-custom 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 quadratz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # remark-gfm-custom
2
+
3
+ A configurable [remark-gfm][] that allows you to toggle the [GitHub Flavored Markdown
4
+ (GFM)][gfm] features.
5
+
6
+ This package has the same functionality as [remark-gfm], with the additional ability to enable or disable specific GFM features like autolinks, footnotes, tables, and more.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ # Bun
12
+ bun add remark-gfm-custom
13
+
14
+ # Deno
15
+ deno add npm:remark-gfm-custom
16
+
17
+ # pnpm
18
+ pnpm add remark-gfm-custom
19
+
20
+ # npm
21
+ npm install remark-gfm-custom
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import assert from 'node:assert'
28
+ import remarkParse from 'remark-parse'
29
+ import remarkRehype from 'remark-rehype'
30
+ import rehypeStringify from 'rehype-stringify'
31
+ import { unified } from 'unified'
32
+ import { remarkGfmCustom } from 'remark-gfm-custom'
33
+
34
+ const file = await unified()
35
+ .use(remarkParse)
36
+ // This disables the GFM autolink feature.
37
+ .use(remarkGfmCustom, { plugins: { autolinkLiteral: false } })
38
+ .use(remarkRehype)
39
+ .use(rehypeStringify)
40
+ .process('https://example.com')
41
+
42
+ assert.equal(file.toString(), '<p>https://example.com</p>')
43
+ ```
44
+
45
+ ### API
46
+
47
+ This package exports the following:
48
+
49
+ #### `remarkGfmCustom`
50
+
51
+ ```ts
52
+ function remarkGfmCustom(options?: Options): void
53
+ ```
54
+
55
+ The main plugin. It receives one parameter to configure behavior. See the [`Options` section](#options) below for configuration details.
56
+
57
+ #### `Options`
58
+
59
+ ```ts
60
+ type Options = {
61
+ remarkGfm?: FootnoteOptions | TableOptions | StrikethroughOptions
62
+ plugins?: {
63
+ autolinkLiteral?: boolean
64
+ footnote?: boolean
65
+ strikethrough?: boolean
66
+ table?: boolean
67
+ taskListItem?: boolean
68
+ }
69
+ }
70
+ ```
71
+
72
+ Configuration for [`remarkGfmCustom`](#remarkgfmcustom). This consists of two main categories: [`remarkGfm`](#remarkgfm) and [`plugins`](#plugins).
73
+
74
+ ##### `remarkGfm`
75
+
76
+ ```ts
77
+ type remarkGfm = FootnoteOptions | TableOptions | StrikethroughOptions
78
+ ```
79
+
80
+ Options passed directly to the [remark-gfm][] plugins. The available fields are:
81
+
82
+ ##### `firstLineBlank`
83
+
84
+ ```ts
85
+ type firstLineBlank = boolean
86
+ ```
87
+
88
+ Serialize with a blank line for the first line of footnote definitions.
89
+
90
+ - Default: `false`.
91
+ - Reference: <https://github.com/remarkjs/remark-gfm#options>
92
+
93
+ ##### `stringLength`
94
+
95
+ ```ts
96
+ type stringLength = (value: string) => number
97
+ ```
98
+
99
+ Detect the size of table cells, used when aligning cells.
100
+
101
+ - Default: `d => d.length`.
102
+ - Reference: <https://github.com/remarkjs/remark-gfm#options>
103
+
104
+ ##### `singleTilde`
105
+
106
+ ```ts
107
+ type singleTilde = boolean
108
+ ```
109
+
110
+ Whether to support strikethrough with a single tilde. Single tildes work on github.com but are technically prohibited by GFM.
111
+
112
+ - Default: `true`.
113
+ - Reference: <https://github.com/remarkjs/remark-gfm#options>
114
+
115
+ ##### `tablePipeAlign`
116
+
117
+ ```ts
118
+ type tablePipeAlign = boolean
119
+ ```
120
+
121
+ Whether to align table pipes.
122
+
123
+ - Default: `true`.
124
+ - Reference: <https://github.com/remarkjs/remark-gfm#options>
125
+
126
+ ##### `tableCellPadding`
127
+
128
+ ```ts
129
+ type tableCellPadding = boolean
130
+ ```
131
+
132
+ Whether to add a space of padding between table pipes and cells.
133
+
134
+ - Default: `true`.
135
+ - Reference: <https://github.com/remarkjs/remark-gfm#options>
136
+
137
+ ##### `plugins`
138
+
139
+ Options to enable or disable specific [remark-gfm][] bundled plugins.
140
+
141
+ All fields below are `boolean` and default to `true`. Set a field to `false` to disable that specific GFM feature.
142
+
143
+ ##### `autolinkLiteral`
144
+
145
+ Toggle [GFM literal autolinks](https://github.com/micromark/micromark-extension-gfm-autolink-literal).
146
+
147
+ ##### `footnote`
148
+
149
+ Toggle the [GFM footnotes](https://github.com/micromark/micromark-extension-gfm-footnote).
150
+
151
+ ##### `strikethrough`
152
+
153
+ Toggle the [GFM strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough).
154
+
155
+ ##### `table`
156
+
157
+ Toggle the [GFM tables](https://github.com/micromark/micromark-extension-gfm-table).
158
+
159
+ ##### `taskListItem`
160
+
161
+ Toggle the [GFM task list items](https://github.com/micromark/micromark-extension-gfm-task-list-item).
162
+
163
+ ## Contributing
164
+
165
+ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
166
+
167
+ ## License
168
+
169
+ MIT
170
+
171
+ [gfm]: https://github.github.com/gfm/
172
+
173
+ [remark-gfm]: https://github.com/remarkjs/remark-gfm
@@ -0,0 +1,99 @@
1
+ import { ToMarkdownOptions as FootnoteOptions } from "mdast-util-gfm-footnote";
2
+ import { Options as TableOptions } from "mdast-util-gfm-table";
3
+ import { Options as StrikethroughOptions } from "micromark-extension-gfm-strikethrough";
4
+ /**
5
+ * Configuration for `remarkGfmCustom`
6
+ */
7
+ type Options = {
8
+ /**
9
+ * Options for [remark-gfm][] plugins.
10
+ *
11
+ * [remark-gfm]: https://github.com/remarkjs/remark-gfm#options
12
+ */
13
+ remarkGfm?: FootnoteOptions | TableOptions | StrikethroughOptions;
14
+ /**
15
+ * Toggles for individual GFM features.
16
+ */
17
+ plugins?: {
18
+ /**
19
+ * Toggle the [GFM literal autolinks][].
20
+ *
21
+ * Set to `false` to disable.
22
+ *
23
+ * [gfm literal autolinks]: https://github.com/micromark/micromark-extension-gfm-autolink-literal
24
+ *
25
+ * @default true
26
+ */
27
+ autolinkLiteral?: boolean;
28
+ /**
29
+ * Toggle the [GFM footnotes][].
30
+ *
31
+ * Set to `false` to disable.
32
+ *
33
+ * [gfm footnotes]: https://github.com/micromark/micromark-extension-gfm-footnote
34
+ *
35
+ * @default true
36
+ */
37
+ footnote?: boolean;
38
+ /**
39
+ * Toggle the [GFM strikethrough][].
40
+ *
41
+ * Set to `false` to disable.
42
+ *
43
+ * [gfm strikethrough]: https://github.com/micromark/micromark-extension-gfm-strikethrough
44
+ *
45
+ * @default true
46
+ */
47
+ strikethrough?: boolean;
48
+ /**
49
+ * Toggle the [GFM tables][].
50
+ *
51
+ * Set to `false` to disable.
52
+ *
53
+ * [gfm tables]: https://github.com/micromark/micromark-extension-gfm-table
54
+ *
55
+ * @default true
56
+ */
57
+ table?: boolean;
58
+ /**
59
+ * Toggle the [GFM task list items][].
60
+ *
61
+ * Set to `false` to disable.
62
+ *
63
+ * [gfm task list items]: https://github.com/micromark/micromark-extension-gfm-task-list-item
64
+ *
65
+ * @default true
66
+ */
67
+ taskListItem?: boolean;
68
+ };
69
+ };
70
+ /**
71
+ * A custom version of [remark-gfm] that lets you pick and choose which
72
+ * GFM features to enable.
73
+ *
74
+ * [remark-gfm]: https://github.com/remarkjs/remark-gfm
75
+ *
76
+ * @param options - Settings to enable or disable GFM features.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import assert from 'node:assert'
81
+ * import remarkParse from 'remark-parse'
82
+ * import remarkRehype from 'remark-rehype'
83
+ * import rehypeStringify from 'rehype-stringify'
84
+ * import { unified } from 'unified'
85
+ * import { remarkGfmCustom } from 'remark-gfm-custom'
86
+ *
87
+ * const file = await unified()
88
+ * .use(remarkParse)
89
+ * // This disables the GFM autolink feature.
90
+ * .use(remarkGfmCustom, { plugins: { autolinkLiteral: false } })
91
+ * .use(remarkRehype)
92
+ * .use(rehypeStringify)
93
+ * .process('https://example.com');
94
+ *
95
+ * assert.equal(file.toString(), '<p>https://example.com</p>');
96
+ * ```
97
+ */
98
+ declare function remarkGfmCustom(options?: Options): void;
99
+ export { remarkGfmCustom, Options };
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ // src/remark-gfm-custom.ts
2
+ import { merge } from "ts-deepmerge";
3
+
4
+ // src/utils.ts
5
+ function typedObjectKeys(obj) {
6
+ return Object.keys(obj);
7
+ }
8
+
9
+ // src/remark-gfm-custom.ts
10
+ import { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
11
+ import { gfmFootnote } from "micromark-extension-gfm-footnote";
12
+ import { gfmStrikethrough } from "micromark-extension-gfm-strikethrough";
13
+ import { gfmTable } from "micromark-extension-gfm-table";
14
+ import { gfmTaskListItem } from "micromark-extension-gfm-task-list-item";
15
+ import { gfmAutolinkLiteralFromMarkdown } from "mdast-util-gfm-autolink-literal";
16
+ import { gfmFootnoteFromMarkdown } from "mdast-util-gfm-footnote";
17
+ import { gfmStrikethroughFromMarkdown } from "mdast-util-gfm-strikethrough";
18
+ import { gfmTableFromMarkdown } from "mdast-util-gfm-table";
19
+ import { gfmTaskListItemFromMarkdown } from "mdast-util-gfm-task-list-item";
20
+ import { gfmAutolinkLiteralToMarkdown } from "mdast-util-gfm-autolink-literal";
21
+ import { gfmFootnoteToMarkdown } from "mdast-util-gfm-footnote";
22
+ import { gfmStrikethroughToMarkdown } from "mdast-util-gfm-strikethrough";
23
+ import { gfmTableToMarkdown } from "mdast-util-gfm-table";
24
+ import { gfmTaskListItemToMarkdown } from "mdast-util-gfm-task-list-item";
25
+ var DEFAULT_OPTIONS = {
26
+ remarkGfm: {},
27
+ plugins: {
28
+ autolinkLiteral: true,
29
+ footnote: true,
30
+ strikethrough: true,
31
+ table: true,
32
+ taskListItem: true
33
+ }
34
+ };
35
+ function remarkGfmCustom(userOptions = DEFAULT_OPTIONS) {
36
+ const options = merge(DEFAULT_OPTIONS, userOptions);
37
+ const data = this.data();
38
+ if (!data.micromarkExtensions)
39
+ data.micromarkExtensions = [];
40
+ if (!data.fromMarkdownExtensions)
41
+ data.fromMarkdownExtensions = [];
42
+ if (!data.toMarkdownExtensions)
43
+ data.toMarkdownExtensions = [];
44
+ const { micromarkExtensions, fromMarkdownExtensions, toMarkdownExtensions } = data;
45
+ for (const name of typedObjectKeys(options.plugins)) {
46
+ if (options.plugins[name] === false)
47
+ continue;
48
+ switch (name) {
49
+ case "autolinkLiteral":
50
+ micromarkExtensions.push(gfmAutolinkLiteral());
51
+ fromMarkdownExtensions.push(gfmAutolinkLiteralFromMarkdown());
52
+ toMarkdownExtensions.push(gfmAutolinkLiteralToMarkdown());
53
+ continue;
54
+ case "footnote": {
55
+ micromarkExtensions.push(gfmFootnote());
56
+ fromMarkdownExtensions.push(gfmFootnoteFromMarkdown());
57
+ const opt = options.remarkGfm;
58
+ toMarkdownExtensions.push(gfmFootnoteToMarkdown(opt));
59
+ continue;
60
+ }
61
+ case "strikethrough": {
62
+ const opt = options.remarkGfm;
63
+ micromarkExtensions.push(gfmStrikethrough(opt));
64
+ fromMarkdownExtensions.push(gfmStrikethroughFromMarkdown());
65
+ toMarkdownExtensions.push(gfmStrikethroughToMarkdown());
66
+ continue;
67
+ }
68
+ case "table": {
69
+ micromarkExtensions.push(gfmTable());
70
+ fromMarkdownExtensions.push(gfmTableFromMarkdown());
71
+ const opt = options.remarkGfm;
72
+ toMarkdownExtensions.push(gfmTableToMarkdown(opt));
73
+ continue;
74
+ }
75
+ case "taskListItem":
76
+ micromarkExtensions.push(gfmTaskListItem());
77
+ fromMarkdownExtensions.push(gfmTaskListItemFromMarkdown());
78
+ toMarkdownExtensions.push(gfmTaskListItemToMarkdown());
79
+ continue;
80
+ default:
81
+ throw new TypeError(`Unknown "${name}" for plugin options. Please ensure your config is not mistyped.`);
82
+ }
83
+ }
84
+ }
85
+ export {
86
+ remarkGfmCustom
87
+ };
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "remark-gfm-custom",
3
+ "description": "A configurable remark-gfm that allows you to toggle the GitHub Flavored Markdown (GFM) features.",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "homepage": "https://github.com/quadratz/remark-gfm-custom#readme",
21
+ "bugs": {
22
+ "url": "https://github.com/quadratz/remark-gfm-custom/issues"
23
+ },
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/quadratz/remark-gfm-custom.git"
28
+ },
29
+ "scripts": {
30
+ "build": "bunup",
31
+ "dev": "bunup --watch",
32
+ "lint": "biome check .",
33
+ "lint:fix": "biome check --write .",
34
+ "prepare": "bun simple-git-hooks",
35
+ "release": "bumpp --commit --push --tag",
36
+ "test": "bun test",
37
+ "test:coverage": "bun test --coverage",
38
+ "test:watch": "bun test --watch",
39
+ "type-check": "tsc --noEmit"
40
+ },
41
+ "devDependencies": {
42
+ "@biomejs/biome": "^2.3.14",
43
+ "@types/bun": "^1.3.9",
44
+ "bumpp": "^10.4.1",
45
+ "bunup": "^0.16.26",
46
+ "mdast-util-from-markdown": "^2.0.2",
47
+ "mdast-util-to-markdown": "^2.1.2",
48
+ "micromark-util-types": "^2.0.2",
49
+ "rehype-format": "^5.0.1",
50
+ "rehype-stringify": "^10.0.1",
51
+ "remark": "^15.0.1",
52
+ "remark-gfm": "^4.0.1",
53
+ "remark-parse": "^11.0.0",
54
+ "remark-rehype": "^11.1.2",
55
+ "simple-git-hooks": "^2.13.1",
56
+ "string-length": "^7.0.1",
57
+ "to-vfile": "^8.0.0",
58
+ "type-fest": "^5.4.4",
59
+ "typescript": "^5.9.3",
60
+ "unified": "^11.0.5",
61
+ "vfile": "^6.0.3"
62
+ },
63
+ "peerDependencies": {
64
+ "typescript": ">=4.5.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "typescript": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "simple-git-hooks": {
72
+ "pre-commit": "bun run lint && bun run type-check"
73
+ },
74
+ "dependencies": {
75
+ "mdast-util-gfm-autolink-literal": "^2.0.1",
76
+ "mdast-util-gfm-footnote": "^2.1.0",
77
+ "mdast-util-gfm-strikethrough": "^2.0.0",
78
+ "mdast-util-gfm-table": "^2.0.0",
79
+ "mdast-util-gfm-task-list-item": "^2.0.0",
80
+ "micromark-extension-gfm-autolink-literal": "^2.1.0",
81
+ "micromark-extension-gfm-footnote": "^2.1.0",
82
+ "micromark-extension-gfm-strikethrough": "^2.1.0",
83
+ "micromark-extension-gfm-table": "^2.1.1",
84
+ "micromark-extension-gfm-task-list-item": "^2.1.0",
85
+ "ts-deepmerge": "^7.0.3"
86
+ }
87
+ }