Skip to content

Commit 7cdcb7c

Browse files
committed
feat(remark-kbd-nested)!: add support for variable sections
1 parent f900bbf commit 7cdcb7c

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

packages/remark-kbd-nested/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@
5858
"unified": "^10.1.0"
5959
},
6060
"dependencies": {
61-
"micromark-extension-kbd-nested": "workspace:^0.3.1"
61+
"micromark-extension-kbd-nested": "workspace:^0.4.0"
6262
}
6363
}

packages/remark-kbd-nested/src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,26 @@ const fromMarkdown: FromMarkdownExtension = {
1818
token,
1919
);
2020
},
21+
keyboardSequenceVariable: function (token) {
22+
this.enter(
23+
{
24+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-explicit-any */
25+
type: "variable" as any,
26+
data: { hName: "var" },
27+
attributes: {},
28+
children: [],
29+
},
30+
token,
31+
);
32+
},
2133
},
2234
exit: {
2335
keyboardSequence: function (token) {
2436
this.exit(token);
2537
},
38+
keyboardSequenceVariable: function (token) {
39+
this.exit(token);
40+
},
2641
},
2742
};
2843

packages/remark-kbd-nested/tests/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,44 @@ describe("transforming sequences should", () => {
2222
assert.equal(
2323
parse({}, "some text **strongly** *emphasized* `code`"),
2424
"<p>some text <strong>strongly</strong> <em>emphasized</em> <code>code</code></p>",
25-
"",
25+
);
26+
assert.equal(
27+
parse({}, "Here is some //non// *variable* text."),
28+
"<p>Here is some //non// <em>variable</em> text.</p>",
2629
);
2730
});
2831

2932
describe("work for", () => {
30-
const CASES: readonly [string | undefined, string, string][] = [
31-
[undefined, "||something||", "<p><kbd>something</kbd></p>"],
33+
const CASES: readonly [
34+
string | undefined,
35+
string,
36+
string,
37+
string | undefined,
38+
][] = [
39+
[undefined, "||something||", "<p><kbd>something</kbd></p>", undefined],
3240
[
3341
"^",
3442
"Press ^^x^^.\n\nThen something.",
3543
"<p>Press <kbd>x</kbd>.</p>\n<p>Then something.</p>",
44+
undefined,
3645
],
3746
[
3847
"=",
3948
"1. Press === ==Ctrl== + ==Alt== + ==x== ===.\n2. Click on **Cancel**.",
4049
"<ol>\n<li>Press <kbd><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>x</kbd></kbd>.</li>\n<li>Click on <strong>Cancel</strong>.</li>\n</ol>",
50+
undefined,
51+
],
52+
[
53+
"^",
54+
"Press ^^^ ^^Ctrl^^ + ^^ !! x !! ^^ ^^^.\n\nThen something.",
55+
"<p>Press <kbd><kbd>Ctrl</kbd> + <kbd><var>x</var></kbd></kbd>.</p>\n<p>Then something.</p>",
56+
"!",
4157
],
4258
];
4359

44-
for (const [delimiter, input, output] of CASES) {
60+
for (const [delimiter, input, output, variableDelimiter] of CASES) {
4561
it(`delimiter ${delimiter} and input ${JSON.stringify(input)}`, () => {
46-
assert.equal(parse({ delimiter }, input), output);
62+
assert.equal(parse({ delimiter, variableDelimiter }, input), output);
4763
});
4864
}
4965
});

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)