@milkdown/preset-commonmark 7.2.4 → 7.3.1
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/lib/composed/plugins.d.ts.map +1 -1
- package/lib/index.es.js +561 -539
- package/lib/index.es.js.map +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/context.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/regexp.d.ts +5 -0
- package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -1
- package/lib/plugin/inline-sync-plugin/utils.d.ts +1 -0
- package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -1
- package/lib/plugin/remark-add-order-in-list-plugin.d.ts +1 -1
- package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -1
- package/lib/plugin/remark-html-transformer.d.ts +1 -1
- package/lib/plugin/remark-html-transformer.d.ts.map +1 -1
- package/lib/plugin/remark-inline-link-plugin.d.ts +1 -1
- package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -1
- package/lib/plugin/remark-line-break.d.ts +1 -1
- package/lib/plugin/remark-line-break.d.ts.map +1 -1
- package/lib/plugin/remark-marker-plugin.d.ts +1 -1
- package/lib/plugin/remark-marker-plugin.d.ts.map +1 -1
- package/package.json +10 -11
- package/src/composed/plugins.ts +1 -1
- package/src/node/hardbreak.ts +5 -2
- package/src/plugin/inline-sync-plugin/context.ts +8 -5
- package/src/plugin/inline-sync-plugin/regexp.ts +7 -0
- package/src/plugin/inline-sync-plugin/utils.ts +16 -1
- package/src/plugin/remark-add-order-in-list-plugin.ts +9 -5
- package/src/plugin/remark-html-transformer.ts +13 -8
- package/src/plugin/remark-inline-link-plugin.ts +7 -2
- package/src/plugin/remark-line-break.ts +9 -4
- package/src/plugin/remark-marker-plugin.ts +9 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hardbreak.d.ts","sourceRoot":"","sources":["../../src/node/hardbreak.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,aAAa,qCAIxB,CAAA;AAQF,eAAO,MAAM,eAAe,oDA4BzB,CAAA;AAaH,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"hardbreak.d.ts","sourceRoot":"","sources":["../../src/node/hardbreak.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,aAAa,qCAIxB,CAAA;AAQF,eAAO,MAAM,eAAe,oDA4BzB,CAAA;AAaH,eAAO,MAAM,sBAAsB,6CAoBjC,CAAA;AASF,eAAO,MAAM,eAAe,6EAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAiED,eAAO,MAAM,iBAAiB,QAAS,GAAG,SAAS,WAAW,KAAG,iBAAiB,GAAG,IAuCpF,CAAA"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export declare const linkRegexp: RegExp;
|
|
2
2
|
export declare const keepLinkRegexp: RegExp;
|
|
3
3
|
export declare const punctuationRegexp: (holePlaceholder: string) => RegExp;
|
|
4
|
+
export declare const ZERO_WIDTH_SPACE = "\u200B";
|
|
5
|
+
export declare const asterisk: string;
|
|
6
|
+
export declare const asteriskHolder: string;
|
|
7
|
+
export declare const underline: string;
|
|
8
|
+
export declare const underlineHolder: string;
|
|
4
9
|
//# sourceMappingURL=regexp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA"}
|
|
1
|
+
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA;AAE9D,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,eAAO,MAAM,QAAQ,QAAyB,CAAA;AAC9C,eAAO,MAAM,cAAc,QAAyB,CAAA;AACpD,eAAO,MAAM,SAAS,QAAyB,CAAA;AAC/C,eAAO,MAAM,eAAe,QAAyB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Node } from '@milkdown/prose/model';
|
|
2
2
|
import type { SyncNodePlaceholder } from './config';
|
|
3
3
|
export declare const keepLink: (str: string) => string;
|
|
4
|
+
export declare const mergeSlash: (str: string) => string;
|
|
4
5
|
export declare const swap: (text: string, first: number, last: number) => string;
|
|
5
6
|
export declare const replacePunctuation: (holePlaceholder: string) => (text: string) => string;
|
|
6
7
|
export declare const calculatePlaceholder: (placeholder: SyncNodePlaceholder) => (text: string) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAUnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,UAAU,QAAS,MAAM,WAMrC,CAAA;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACtB,CAAA;AAEtD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAkBtF,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,WAwBvE,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const remarkAddOrderInListPlugin: import("@milkdown/utils").$Remark
|
|
1
|
+
export declare const remarkAddOrderInListPlugin: import("@milkdown/utils").$Remark<"remarkAddOrderInList", unknown>;
|
|
2
2
|
//# sourceMappingURL=remark-add-order-in-list-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-add-order-in-list-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-add-order-in-list-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remark-add-order-in-list-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-add-order-in-list-plugin.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,0BAA0B,oEASrC,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const remarkHtmlTransformer: import("@milkdown/utils").$Remark
|
|
1
|
+
export declare const remarkHtmlTransformer: import("@milkdown/utils").$Remark<"remarkHTMLTransformer", unknown>;
|
|
2
2
|
//# sourceMappingURL=remark-html-transformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-html-transformer.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-html-transformer.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"remark-html-transformer.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-html-transformer.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,qBAAqB,qEAahC,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const remarkInlineLinkPlugin: import("@milkdown/utils").$Remark
|
|
1
|
+
export declare const remarkInlineLinkPlugin: import("@milkdown/utils").$Remark<"remarkInlineLink", unknown>;
|
|
2
2
|
//# sourceMappingURL=remark-inline-link-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-inline-link-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-inline-link-plugin.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"remark-inline-link-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-inline-link-plugin.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,gEAAuD,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const remarkLineBreak: import("@milkdown/utils").$Remark
|
|
1
|
+
export declare const remarkLineBreak: import("@milkdown/utils").$Remark<"remarkLineBreak", unknown>;
|
|
2
2
|
//# sourceMappingURL=remark-line-break.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-line-break.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-line-break.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"remark-line-break.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-line-break.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,+DAmC1B,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const remarkMarker: import("@milkdown/utils").$Remark
|
|
1
|
+
export declare const remarkMarker: import("@milkdown/utils").$Remark<"remarkMarker", unknown>;
|
|
2
2
|
//# sourceMappingURL=remark-marker-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-marker-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-marker-plugin.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"remark-marker-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-marker-plugin.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,4DAOvB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,24 +29,23 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@sindresorhus/slugify": "^2.2.0",
|
|
32
|
-
"remark-inline-links": "^
|
|
32
|
+
"remark-inline-links": "^7.0.0",
|
|
33
33
|
"tslib": "^2.5.0",
|
|
34
|
-
"unist-util-visit": "^
|
|
35
|
-
"@milkdown/exception": "7.
|
|
36
|
-
"@milkdown/utils": "7.
|
|
34
|
+
"unist-util-visit": "^5.0.0",
|
|
35
|
+
"@milkdown/exception": "7.3.1",
|
|
36
|
+
"@milkdown/utils": "7.3.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@milkdown/
|
|
41
|
-
"@milkdown/
|
|
42
|
-
"@milkdown/
|
|
43
|
-
"@milkdown/transformer": "7.2.4"
|
|
39
|
+
"@milkdown/core": "7.3.1",
|
|
40
|
+
"@milkdown/ctx": "7.3.1",
|
|
41
|
+
"@milkdown/prose": "7.3.1",
|
|
42
|
+
"@milkdown/transformer": "7.3.1"
|
|
44
43
|
},
|
|
45
44
|
"nx": {
|
|
46
45
|
"targets": {
|
|
47
46
|
"build": {
|
|
48
47
|
"outputs": [
|
|
49
|
-
"
|
|
48
|
+
"{projectRoot}/lib"
|
|
50
49
|
],
|
|
51
50
|
"dependsOn": [
|
|
52
51
|
{
|
package/src/composed/plugins.ts
CHANGED
package/src/node/hardbreak.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { commandsCtx } from '@milkdown/core'
|
|
3
|
-
import { Selection } from '@milkdown/prose/state'
|
|
3
|
+
import { Selection, TextSelection } from '@milkdown/prose/state'
|
|
4
4
|
import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
|
|
5
5
|
import { withMeta } from '../__internal__'
|
|
6
6
|
|
|
@@ -34,7 +34,7 @@ export const hardbreakSchema = $nodeSchema('hardbreak', ctx => ({
|
|
|
34
34
|
parseMarkdown: {
|
|
35
35
|
match: ({ type }) => type === 'break',
|
|
36
36
|
runner: (state, node, type) => {
|
|
37
|
-
state.addNode(type, { isInline: Boolean(node.data?.isInline) })
|
|
37
|
+
state.addNode(type, { isInline: Boolean((node.data as (undefined | { isInline: boolean }))?.isInline) })
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
leafText: () => '\n',
|
|
@@ -63,6 +63,9 @@ withMeta(hardbreakSchema.ctx, {
|
|
|
63
63
|
/// Command to insert a hardbreak.
|
|
64
64
|
export const insertHardbreakCommand = $command('InsertHardbreak', ctx => () => (state, dispatch) => {
|
|
65
65
|
const { selection, tr } = state
|
|
66
|
+
if (!(selection instanceof TextSelection))
|
|
67
|
+
return false
|
|
68
|
+
|
|
66
69
|
if (selection.empty) {
|
|
67
70
|
// Transform two successive hardbreak into a new line
|
|
68
71
|
const node = selection.$from.node()
|
|
@@ -6,7 +6,8 @@ import type { EditorState } from '@milkdown/prose/state'
|
|
|
6
6
|
import { pipe } from '@milkdown/utils'
|
|
7
7
|
|
|
8
8
|
import { inlineSyncConfig } from './config'
|
|
9
|
-
import { calculatePlaceholder, keepLink, replacePunctuation } from './utils'
|
|
9
|
+
import { calculatePlaceholder, keepLink, mergeSlash, replacePunctuation } from './utils'
|
|
10
|
+
import { asterisk, asteriskHolder, underline, underlineHolder } from './regexp'
|
|
10
11
|
|
|
11
12
|
export interface InlineSyncContext {
|
|
12
13
|
text: string
|
|
@@ -23,9 +24,7 @@ const getMarkdown = (ctx: Ctx, state: EditorState, node: Node, globalNode: Node[
|
|
|
23
24
|
const serializer = ctx.get(serializerCtx)
|
|
24
25
|
const doc = state.schema.topNodeType.create(undefined, [node, ...globalNode])
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return markdown
|
|
27
|
+
return serializer(doc)
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
const addPlaceholder = (ctx: Ctx, markdown: string) => {
|
|
@@ -36,7 +35,7 @@ const addPlaceholder = (ctx: Ctx, markdown: string) => {
|
|
|
36
35
|
|
|
37
36
|
const movePlaceholder = (text: string) => config.movePlaceholder(holePlaceholder, text)
|
|
38
37
|
|
|
39
|
-
const handleText = pipe(replacePunctuation(holePlaceholder), movePlaceholder, keepLink)
|
|
38
|
+
const handleText = pipe(replacePunctuation(holePlaceholder), movePlaceholder, keepLink, mergeSlash)
|
|
40
39
|
|
|
41
40
|
let text = handleText(firstLine)
|
|
42
41
|
const placeholder = calculatePlaceholder(config.placeholderConfig)(text)
|
|
@@ -103,6 +102,10 @@ export const getContextByState = (ctx: Ctx, state: EditorState): InlineSyncConte
|
|
|
103
102
|
// @ts-expect-error hijack the mark attribute
|
|
104
103
|
link.attrs.href = link.attrs.href.replace(placeholder, '')
|
|
105
104
|
}
|
|
105
|
+
if (node.text?.includes(asteriskHolder) || node.text?.includes(underlineHolder)) {
|
|
106
|
+
// @ts-expect-error hijack the attribute
|
|
107
|
+
node.text = node.text.replaceAll(asteriskHolder, asterisk).replaceAll(underlineHolder, underline)
|
|
108
|
+
}
|
|
106
109
|
})
|
|
107
110
|
|
|
108
111
|
return {
|
|
@@ -6,3 +6,10 @@ export const keepLinkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\
|
|
|
6
6
|
|
|
7
7
|
export const punctuationRegexp = (holePlaceholder: string) =>
|
|
8
8
|
new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
|
|
9
|
+
|
|
10
|
+
export const ZERO_WIDTH_SPACE = '\u200B'
|
|
11
|
+
|
|
12
|
+
export const asterisk = `${ZERO_WIDTH_SPACE}*`
|
|
13
|
+
export const asteriskHolder = `${ZERO_WIDTH_SPACE}*`
|
|
14
|
+
export const underline = `${ZERO_WIDTH_SPACE}_`
|
|
15
|
+
export const underlineHolder = `${ZERO_WIDTH_SPACE}⎽`
|
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
import type { Node } from '@milkdown/prose/model'
|
|
4
4
|
|
|
5
5
|
import type { SyncNodePlaceholder } from './config'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
asterisk,
|
|
8
|
+
asteriskHolder,
|
|
9
|
+
keepLinkRegexp,
|
|
10
|
+
punctuationRegexp,
|
|
11
|
+
underline,
|
|
12
|
+
underlineHolder,
|
|
13
|
+
} from './regexp'
|
|
7
14
|
|
|
8
15
|
export const keepLink = (str: string) => {
|
|
9
16
|
let text = str
|
|
@@ -17,6 +24,14 @@ export const keepLink = (str: string) => {
|
|
|
17
24
|
return text
|
|
18
25
|
}
|
|
19
26
|
|
|
27
|
+
export const mergeSlash = (str: string) => {
|
|
28
|
+
return str
|
|
29
|
+
.replaceAll(/\\\\\*/g, asterisk)
|
|
30
|
+
.replaceAll(/\\\\_/g, underline)
|
|
31
|
+
.replaceAll(asterisk, asteriskHolder)
|
|
32
|
+
.replaceAll(underline, underlineHolder)
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
export const swap = (text: string, first: number, last: number) => {
|
|
21
36
|
const arr = text.split('')
|
|
22
37
|
const temp = arr[first]
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { $remark } from '@milkdown/utils'
|
|
3
|
-
import type { Node, Parent } from 'unist'
|
|
4
3
|
import { visit } from 'unist-util-visit'
|
|
5
4
|
import { withMeta } from '../__internal__'
|
|
6
5
|
|
|
7
6
|
/// This plugin is used to add order in list for remark AST.
|
|
8
|
-
export const remarkAddOrderInListPlugin = $remark(() => () => (tree
|
|
9
|
-
visit(tree, 'list', (node
|
|
7
|
+
export const remarkAddOrderInListPlugin = $remark('remarkAddOrderInList', () => () => (tree) => {
|
|
8
|
+
visit(tree, 'list', (node) => {
|
|
10
9
|
if (node.ordered) {
|
|
11
10
|
const start = node.start ?? 1
|
|
12
11
|
node.children.forEach((child, index) => {
|
|
13
|
-
(child as
|
|
12
|
+
(child as unknown as Record<string, number>).label = index + start
|
|
14
13
|
})
|
|
15
14
|
}
|
|
16
15
|
})
|
|
17
16
|
})
|
|
18
17
|
|
|
19
|
-
withMeta(remarkAddOrderInListPlugin, {
|
|
18
|
+
withMeta(remarkAddOrderInListPlugin.plugin, {
|
|
20
19
|
displayName: 'Remark<remarkAddOrderInListPlugin>',
|
|
21
20
|
group: 'Remark',
|
|
22
21
|
})
|
|
22
|
+
|
|
23
|
+
withMeta(remarkAddOrderInListPlugin.options, {
|
|
24
|
+
displayName: 'RemarkConfig<remarkAddOrderInListPlugin>',
|
|
25
|
+
group: 'Remark',
|
|
26
|
+
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { $remark } from '@milkdown/utils'
|
|
3
|
-
import type {
|
|
3
|
+
import type { Node } from '@milkdown/transformer'
|
|
4
4
|
import { withMeta } from '../__internal__'
|
|
5
5
|
|
|
6
|
-
const isParent = (node: Node): node is
|
|
7
|
-
const isHTML = (node: Node): node is
|
|
6
|
+
const isParent = (node: Node): node is Node & { children: Node[] } => !!(node as Node & { children: Node[] }).children
|
|
7
|
+
const isHTML = (node: Node): node is Node & { children: Node[]; value: unknown } => node.type === 'html'
|
|
8
8
|
|
|
9
9
|
function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
|
|
10
10
|
return transform(ast, 0, null)[0]
|
|
@@ -34,22 +34,27 @@ function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Nod
|
|
|
34
34
|
|
|
35
35
|
/// @internal
|
|
36
36
|
/// This plugin should be deprecated after we support HTML.
|
|
37
|
-
export const remarkHtmlTransformer = $remark(() => () => (tree: Node) => {
|
|
37
|
+
export const remarkHtmlTransformer = $remark('remarkHTMLTransformer', () => () => (tree: Node) => {
|
|
38
38
|
flatMapWithDepth(tree, (node, _index, parent) => {
|
|
39
39
|
if (!isHTML(node))
|
|
40
40
|
return [node]
|
|
41
41
|
|
|
42
42
|
if (parent?.type === 'root') {
|
|
43
|
-
|
|
44
|
-
delete
|
|
45
|
-
node.type = 'paragraph'
|
|
43
|
+
node.children = [{ ...node }]
|
|
44
|
+
delete node.value;
|
|
45
|
+
(node as { type: string }).type = 'paragraph'
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return [node]
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
withMeta(remarkHtmlTransformer, {
|
|
52
|
+
withMeta(remarkHtmlTransformer.plugin, {
|
|
53
53
|
displayName: 'Remark<remarkHtmlTransformer>',
|
|
54
54
|
group: 'Remark',
|
|
55
55
|
})
|
|
56
|
+
|
|
57
|
+
withMeta(remarkHtmlTransformer.options, {
|
|
58
|
+
displayName: 'RemarkConfig<remarkHtmlTransformer>',
|
|
59
|
+
group: 'Remark',
|
|
60
|
+
})
|
|
@@ -4,9 +4,14 @@ import remarkInlineLinks from 'remark-inline-links'
|
|
|
4
4
|
import { withMeta } from '../__internal__'
|
|
5
5
|
|
|
6
6
|
/// This plugin wraps [remark-inline-links](https://github.com/remarkjs/remark-inline-links).
|
|
7
|
-
export const remarkInlineLinkPlugin = $remark(() => remarkInlineLinks)
|
|
7
|
+
export const remarkInlineLinkPlugin = $remark('remarkInlineLink', () => remarkInlineLinks)
|
|
8
8
|
|
|
9
|
-
withMeta(remarkInlineLinkPlugin, {
|
|
9
|
+
withMeta(remarkInlineLinkPlugin.plugin, {
|
|
10
10
|
displayName: 'Remark<remarkInlineLinkPlugin>',
|
|
11
11
|
group: 'Remark',
|
|
12
12
|
})
|
|
13
|
+
|
|
14
|
+
withMeta(remarkInlineLinkPlugin.options, {
|
|
15
|
+
displayName: 'RemarkConfig<remarkInlineLinkPlugin>',
|
|
16
|
+
group: 'Remark',
|
|
17
|
+
})
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { $remark } from '@milkdown/utils'
|
|
3
|
-
import type {
|
|
3
|
+
import type { Node } from '@milkdown/transformer'
|
|
4
4
|
import { visit } from 'unist-util-visit'
|
|
5
5
|
import { withMeta } from '../__internal__'
|
|
6
6
|
|
|
7
7
|
/// This plugin is used to add inline line break for remark AST.
|
|
8
8
|
/// The inline line break should be treated as a `space`.
|
|
9
9
|
/// And the normal line break should be treated as a `LF`.
|
|
10
|
-
export const remarkLineBreak = $remark(() => () => (tree: Node) => {
|
|
10
|
+
export const remarkLineBreak = $remark('remarkLineBreak', () => () => (tree: Node) => {
|
|
11
11
|
const find = /[\t ]*(?:\r?\n|\r)/g
|
|
12
|
-
visit(tree, 'text', (node:
|
|
12
|
+
visit(tree, 'text', (node: Node & { value: string }, index: number, parent: Node & { children: Node[] }) => {
|
|
13
13
|
if (!node.value || typeof node.value !== 'string')
|
|
14
14
|
return
|
|
15
15
|
|
|
@@ -44,7 +44,12 @@ export const remarkLineBreak = $remark(() => () => (tree: Node) => {
|
|
|
44
44
|
})
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
withMeta(remarkLineBreak, {
|
|
47
|
+
withMeta(remarkLineBreak.plugin, {
|
|
48
48
|
displayName: 'Remark<remarkLineBreak>',
|
|
49
49
|
group: 'Remark',
|
|
50
50
|
})
|
|
51
|
+
|
|
52
|
+
withMeta(remarkLineBreak.options, {
|
|
53
|
+
displayName: 'RemarkConfig<remarkLineBreak>',
|
|
54
|
+
group: 'Remark',
|
|
55
|
+
})
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { $remark } from '@milkdown/utils'
|
|
3
|
-
import type { Node } from '
|
|
3
|
+
import type { Node } from '@milkdown/transformer'
|
|
4
4
|
import { visit } from 'unist-util-visit'
|
|
5
5
|
import { withMeta } from '../__internal__'
|
|
6
6
|
|
|
7
7
|
/// This plugin is used to keep the marker (`_` and `*`) of emphasis and strong nodes.
|
|
8
|
-
export const remarkMarker = $remark(() => () => (tree, file) => {
|
|
8
|
+
export const remarkMarker = $remark('remarkMarker', () => () => (tree, file) => {
|
|
9
9
|
const getMarker = (node: Node) => {
|
|
10
10
|
return (file.value as string).charAt(node.position!.start.offset!)
|
|
11
11
|
}
|
|
12
|
-
visit(tree, node => ['strong', 'emphasis'].includes(node.type), (node: Node) => {
|
|
12
|
+
visit(tree, (node: Node) => ['strong', 'emphasis'].includes(node.type), (node: Node) => {
|
|
13
13
|
(node as Node & { marker: string }).marker = getMarker(node)
|
|
14
14
|
})
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
withMeta(remarkMarker, {
|
|
17
|
+
withMeta(remarkMarker.plugin, {
|
|
18
18
|
displayName: 'Remark<remarkMarker>',
|
|
19
19
|
group: 'Remark',
|
|
20
20
|
})
|
|
21
|
+
|
|
22
|
+
withMeta(remarkMarker.options, {
|
|
23
|
+
displayName: 'RemarkConfig<remarkMarker>',
|
|
24
|
+
group: 'Remark',
|
|
25
|
+
})
|