@mirrordown/remd-sup 0.1.3 → 0.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/CHANGELOG.md +13 -0
- package/README.md +13 -19
- package/dist/index.d.mts +8 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +22 -88
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
## 0.2.0
|
|
8
|
+
<sub>2026-10-28</sub>
|
|
9
|
+
|
|
10
|
+
- *(minor)*
|
|
11
|
+
`~subscript~` and `^superscript^` now parse the same way in markdown-it, remark and Sätteri: a single `~` or `^` is a delimiter run with emphasis-style flanking, its content is inline markup (spaces, emphasis, links, code and each other), and crossing runs resolve leftmost-first.
|
|
12
|
+
|
|
13
|
+
- `mdit-sub` and `mdit-sup` used to keep the content as plain text and reject any space inside it. They now parse it as inline markup, so `~*a* b~` renders emphasis and `^a~b~c^` nests.
|
|
14
|
+
- `remd-sub` and `remd-sup` are now micromark syntax extensions sharing one resolver from `@mirrordown/core` (`scriptSyntax`), instead of text scans run one after another. Crossing runs such as `^a~b^c~` no longer depend on which plugin was registered first, `~~a~~` without GFM is no longer turned into empty subscripts, and the packages drop their `unist-util-*` dependencies.
|
|
15
|
+
- The sub guide now shows `remark-gfm` with `singleTilde: false`: GFM's single-tilde strikethrough, which Astro enables by default, otherwise claims `~text~` first.
|
|
16
|
+
- *(patch)*
|
|
17
|
+
Backslash-escaped delimiters are now literal in `remd-mark`, `remd-ins`, `remd-del`, `remd-kbd`, `remd-spoiler`, `remd-sub` and `remd-sup`, as they already were in the `mdit-*` plugins: `\==not marked==` renders as `==not marked==` instead of a `<mark>`, while an escaped backslash (`\==marked==`) still allows the markup. These plugins now depend on the new `@mirrordown/core` package, which holds logic shared across Mirrordown's engines.
|
|
18
|
+
|
|
6
19
|
## 0.1.3
|
|
7
20
|
<sub>2026-06-28</sub>
|
|
8
21
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mirrordown/remd-sup
|
|
2
2
|
|
|
3
|
-
> Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified
|
|
3
|
+
> Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified, markdown-it and Sätteri ecosystems.
|
|
4
4
|
|
|
5
5
|
A remark/rehype (unified) plugin for the `sup` syntax extension.
|
|
6
6
|
|
|
@@ -16,11 +16,19 @@ The `sup` plugin renders `^text^` as an HTML `<sup>` element, representing super
|
|
|
16
16
|
|
|
17
17
|
Wrap text in single carets to render it as superscript:
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
````markdown
|
|
20
20
|
E = mc^2^
|
|
21
21
|
|
|
22
22
|
The Pythagorean theorem: a^2^ + b^2^ = c^2^
|
|
23
|
-
|
|
23
|
+
````
|
|
24
|
+
|
|
25
|
+
### Formatting inside
|
|
26
|
+
|
|
27
|
+
The content is inline markup, like emphasis: it can hold spaces, other formatting and subscript, but can't start or end with a space.
|
|
28
|
+
|
|
29
|
+
````markdown
|
|
30
|
+
e^x~0~^ and the ^*n*th power^
|
|
31
|
+
````
|
|
24
32
|
|
|
25
33
|
## Install
|
|
26
34
|
|
|
@@ -53,22 +61,8 @@ import { remarkSup } from "@mirrordown/remd-sup";
|
|
|
53
61
|
|
|
54
62
|
export default defineConfig({
|
|
55
63
|
markdown: {
|
|
56
|
-
remarkPlugins: [remarkSup]
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### VitePress
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
// .vitepress/config.ts
|
|
65
|
-
import { defineConfig } from "vitepress";
|
|
66
|
-
import { remarkSup } from "@mirrordown/remd-sup";
|
|
67
|
-
|
|
68
|
-
export default defineConfig({
|
|
69
|
-
markdown: {
|
|
70
|
-
remarkPlugins: [remarkSup]
|
|
71
|
-
}
|
|
64
|
+
remarkPlugins: [remarkSup],
|
|
65
|
+
},
|
|
72
66
|
});
|
|
73
67
|
```
|
|
74
68
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { Plugin } from "unified";
|
|
2
2
|
import { Data, Parent, PhrasingContent, Root } from "mdast";
|
|
3
|
-
|
|
4
|
-
//#region src/plugin.d.ts
|
|
3
|
+
import { Extension } from "mdast-util-from-markdown";
|
|
5
4
|
/** Optional data carried by a {@link Superscript} node. */
|
|
6
|
-
interface SuperscriptData extends Data {}
|
|
5
|
+
export interface SuperscriptData extends Data {}
|
|
7
6
|
/** An mdast node for `^superscript^` text, rendered as a `<sup>` element. */
|
|
8
|
-
interface Superscript extends Parent {
|
|
7
|
+
export interface Superscript extends Parent {
|
|
9
8
|
type: `superscript`;
|
|
10
9
|
children: PhrasingContent[];
|
|
11
10
|
data?: SuperscriptData | undefined;
|
|
12
11
|
}
|
|
12
|
+
/** mdast-util-from-markdown extension turning `superscript` tokens into {@link Superscript} nodes. */
|
|
13
|
+
export declare const superscriptFromMarkdown: Extension;
|
|
13
14
|
/**
|
|
14
|
-
* remark plugin for superscript syntax (`^text^`),
|
|
15
|
-
* {@link Superscript} node that renders as a `<sup>` element.
|
|
15
|
+
* remark plugin for superscript syntax (`^text^`), parsed as a {@link Superscript} node that renders as a `<sup>` element. A single `^` is a delimiter run like emphasis, and its content is inline markup; it shares its syntax with `remd-sub` through `@mirrordown/core`, so the two nest and resolve crossing runs leftmost-first.
|
|
16
16
|
*/
|
|
17
|
-
declare const remarkSup: Plugin<[], Root>;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/augment.d.ts
|
|
17
|
+
export declare const remarkSup: Plugin<[], Root>;
|
|
20
18
|
declare module "mdast" {
|
|
21
19
|
interface PhrasingContentMap {
|
|
22
20
|
superscript: Superscript;
|
|
@@ -24,7 +22,5 @@ declare module "mdast" {
|
|
|
24
22
|
interface RootContentMap {
|
|
25
23
|
superscript: Superscript;
|
|
26
24
|
}
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { Superscript, SuperscriptData, remarkSup };
|
|
25
|
+
}
|
|
30
26
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts","../src/augment.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["FromMarkdownExtension"],"sources":["../src/plugin.ts","../src/augment.ts"],"mappings":";;;;iBAUiB,wBAAwB;;iBAGxB,oBAAoB;EACnC;EACA,UAAU;EACV,OAAO;;;qBAII,yBAAyBA;;;;qBAwBzB,WAAW,WAAW;;YCrCvB;IACR,aAAa;;YAGL;IACR,aAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,93 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { scriptSyntax } from "@mirrordown/core";
|
|
2
|
+
// src/plugin.ts
|
|
3
|
+
/** mdast-util-from-markdown extension turning `superscript` tokens into {@link Superscript} nodes. */
|
|
4
|
+
const superscriptFromMarkdown = {
|
|
5
|
+
canContainEols: [`superscript`],
|
|
6
|
+
enter: { superscript(token) {
|
|
7
|
+
this.enter({
|
|
8
|
+
type: `superscript`,
|
|
9
|
+
children: [],
|
|
10
|
+
data: { hName: `sup` }
|
|
11
|
+
}, token);
|
|
12
|
+
} },
|
|
13
|
+
exit: { superscript(token) {
|
|
14
|
+
this.exit(token);
|
|
15
|
+
} }
|
|
16
|
+
};
|
|
14
17
|
/**
|
|
15
|
-
* remark plugin for superscript syntax (`^text^`),
|
|
16
|
-
* {@link Superscript} node that renders as a `<sup>` element.
|
|
18
|
+
* remark plugin for superscript syntax (`^text^`), parsed as a {@link Superscript} node that renders as a `<sup>` element. A single `^` is a delimiter run like emphasis, and its content is inline markup; it shares its syntax with `remd-sub` through `@mirrordown/core`, so the two nest and resolve crossing runs leftmost-first.
|
|
17
19
|
*/
|
|
18
|
-
const remarkSup = ()
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
data: { hName: `sup` }
|
|
23
|
-
});
|
|
24
|
-
const visitorFirst = (node, index, parent) => {
|
|
25
|
-
/* v8 ignore next */
|
|
26
|
-
if (!parent || typeof index === `undefined`) return;
|
|
27
|
-
if (!REGEX.test(node.value)) return;
|
|
28
|
-
const children = [];
|
|
29
|
-
const value = node.value;
|
|
30
|
-
let tempValue = ``;
|
|
31
|
-
let prevMatchIndex = 0;
|
|
32
|
-
let prevMatchLength = 0;
|
|
33
|
-
const matches = Array.from(value.matchAll(REGEX_GLOBAL));
|
|
34
|
-
for (const match of matches) {
|
|
35
|
-
const [matched, superscriptText] = match;
|
|
36
|
-
const mIndex = match.index;
|
|
37
|
-
const mLength = matched.length;
|
|
38
|
-
const textPartIndex = prevMatchIndex + prevMatchLength;
|
|
39
|
-
prevMatchIndex = mIndex;
|
|
40
|
-
prevMatchLength = mLength;
|
|
41
|
-
if (mIndex > textPartIndex) children.push(u(`text`, value.substring(textPartIndex, mIndex)));
|
|
42
|
-
children.push(constructSuperscriptNode([{
|
|
43
|
-
type: `text`,
|
|
44
|
-
value: superscriptText.trim()
|
|
45
|
-
}]));
|
|
46
|
-
tempValue = value.slice(mIndex + mLength);
|
|
47
|
-
}
|
|
48
|
-
if (tempValue) children.push(u(`text`, tempValue));
|
|
49
|
-
if (children.length) parent.children.splice(index, 1, ...children);
|
|
50
|
-
};
|
|
51
|
-
const visitorSecond = (node, index, parent) => {
|
|
52
|
-
/* v8 ignore next */
|
|
53
|
-
if (!parent || typeof index === `undefined`) return;
|
|
54
|
-
if (!REGEX_STARTING.test(node.value)) return;
|
|
55
|
-
const openingNode = node;
|
|
56
|
-
const closingNode = findAfter(parent, openingNode, (n) => {
|
|
57
|
-
return n.type === `text` && REGEX_ENDING.test(n.value);
|
|
58
|
-
});
|
|
59
|
-
if (!closingNode) return;
|
|
60
|
-
const beforeChildren = findAllBefore(parent, openingNode);
|
|
61
|
-
const mainChildren = findAllBetween(parent, openingNode, closingNode);
|
|
62
|
-
const afterChildren = findAllAfter(parent, closingNode);
|
|
63
|
-
const value = openingNode.value;
|
|
64
|
-
const match = Array.from(value.matchAll(REGEX_STARTING_GLOBAL))[0];
|
|
65
|
-
const [matched] = match;
|
|
66
|
-
const mIndex = match.index;
|
|
67
|
-
const mLength = matched.length;
|
|
68
|
-
if (mIndex > 0) beforeChildren.push(u(`text`, value.substring(0, mIndex)));
|
|
69
|
-
if (value.length > mIndex + mLength) mainChildren.unshift(u(`text`, value.slice(mIndex + mLength)));
|
|
70
|
-
const value_ = closingNode.value;
|
|
71
|
-
const match_ = Array.from(value_.matchAll(REGEX_ENDING_GLOBAL))[0];
|
|
72
|
-
const [matched_] = match_;
|
|
73
|
-
const mIndex_ = match_.index;
|
|
74
|
-
const mLength_ = matched_.length;
|
|
75
|
-
if (mIndex_ > 0) mainChildren.push(u(`text`, value_.substring(0, mIndex_)));
|
|
76
|
-
if (value_.length > mIndex_ + mLength_) afterChildren.unshift(u(`text`, value_.slice(mIndex_ + mLength_)));
|
|
77
|
-
parent.children = [
|
|
78
|
-
...beforeChildren,
|
|
79
|
-
constructSuperscriptNode(mainChildren),
|
|
80
|
-
...afterChildren
|
|
81
|
-
];
|
|
82
|
-
return index;
|
|
83
|
-
};
|
|
84
|
-
const transformer = (tree) => {
|
|
85
|
-
visit(tree, `text`, visitorFirst);
|
|
86
|
-
visit(tree, `text`, visitorSecond);
|
|
87
|
-
};
|
|
88
|
-
return transformer;
|
|
20
|
+
const remarkSup = function() {
|
|
21
|
+
const data = this.data();
|
|
22
|
+
(data.micromarkExtensions ??= []).push(scriptSyntax(`^`));
|
|
23
|
+
(data.fromMarkdownExtensions ??= []).push(superscriptFromMarkdown);
|
|
89
24
|
};
|
|
90
|
-
|
|
91
|
-
export { remarkSup };
|
|
25
|
+
export { remarkSup, superscriptFromMarkdown };
|
|
92
26
|
|
|
93
27
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Plugin } from \"unified\";\nimport type { Data, Nodes, Parent, PhrasingContent, Root } from \"mdast\";\nimport type {\n CompileContext,\n Extension as FromMarkdownExtension,\n Token\n} from \"mdast-util-from-markdown\";\nimport { scriptSyntax } from \"@mirrordown/core\";\n\n/** Optional data carried by a {@link Superscript} node. */\nexport interface SuperscriptData extends Data {}\n\n/** An mdast node for `^superscript^` text, rendered as a `<sup>` element. */\nexport interface Superscript extends Parent {\n type: `superscript`;\n children: PhrasingContent[];\n data?: SuperscriptData | undefined;\n}\n\n/** mdast-util-from-markdown extension turning `superscript` tokens into {@link Superscript} nodes. */\nexport const superscriptFromMarkdown: FromMarkdownExtension = {\n canContainEols: [`superscript`],\n enter: {\n superscript(this: CompileContext, token: Token) {\n const node: Superscript = {\n type: `superscript`,\n children: [],\n data: { hName: `sup` }\n };\n // The JSR build has no mdast augmentation, so `Superscript` is not in `Nodes` there.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion, typescript/no-unnecessary-type-assertion\n this.enter(node as unknown as Nodes, token);\n }\n },\n exit: {\n superscript(this: CompileContext, token: Token) {\n this.exit(token);\n }\n }\n};\n\n/**\n * remark plugin for superscript syntax (`^text^`), parsed as a {@link Superscript} node that renders as a `<sup>` element. A single `^` is a delimiter run like emphasis, and its content is inline markup; it shares its syntax with `remd-sub` through `@mirrordown/core`, so the two nest and resolve crossing runs leftmost-first.\n */\nexport const remarkSup: Plugin<[], Root> = function () {\n // this.data() in remark plugin context returns a generic shape; the cast narrows the known extension arrays.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const data = this.data() as {\n micromarkExtensions?: unknown[];\n fromMarkdownExtensions?: unknown[];\n };\n (data.micromarkExtensions ??= []).push(scriptSyntax(`^`));\n (data.fromMarkdownExtensions ??= []).push(superscriptFromMarkdown);\n};\n"],"mappings":";;;AAoBA,MAAa,0BAAiD;CAC5D,gBAAgB,CAAC,aAAa;CAC9B,OAAO,EACL,YAAkC,OAAc;EAQ9C,KAAK,MAAM;GANT,MAAM;GACN,UAAU,CAAC;GACX,MAAM,EAAE,OAAO,MAAM;EAIT,GAAuB,KAAK;CAC5C,EACF;CACA,MAAM,EACJ,YAAkC,OAAc;EAC9C,KAAK,KAAK,KAAK;CACjB,EACF;AACF;;;;AAKA,MAAa,YAA8B,WAAY;CAGrD,MAAM,OAAO,KAAK,KAAK;CAIvB,CAAC,KAAK,wBAAwB,CAAC,EAAA,CAAG,KAAK,aAAa,GAAG,CAAC;CACxD,CAAC,KAAK,2BAA2B,CAAC,EAAA,CAAG,KAAK,uBAAuB;AACnE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirrordown/remd-sup",
|
|
3
3
|
"description": "A remark plugin for superscript syntax (^text^), rendering <sup> elements.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
|
|
7
7
|
"repository": {
|
|
@@ -20,12 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"unist-util-find-all-after": "^5.0.0",
|
|
26
|
-
"unist-util-find-all-before": "^5.0.0",
|
|
27
|
-
"unist-util-find-between-all": "^1.1.6",
|
|
28
|
-
"unist-util-visit": "^5.1.0"
|
|
23
|
+
"@mirrordown/core": "^0.1.0",
|
|
24
|
+
"mdast-util-from-markdown": "^2.0.3"
|
|
29
25
|
},
|
|
30
26
|
"devDependencies": {
|
|
31
27
|
"@types/mdast": "^4.0.4",
|