Skip to content

Commit c14b4ba

Browse files
committed
Transform emphasis code into InlineCode
1 parent 63c113e commit c14b4ba

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

packages/mdx/src/index.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
}
2828

2929
.ch-inline-code > code {
30-
padding: 0.2em 0.4em;
31-
margin: 0.1em -0.1em;
30+
padding: 0.2em 0.15em;
31+
margin: 0.1em -0.05em;
3232
border-radius: 0.25em;
3333
font-size: 0.9em;
3434
}

packages/mdx/src/plugin/inline-code.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@ import {
44
CH_CODE_CONFIG_PLACEHOLDER,
55
} from "./unist-utils"
66
import { Node } from "unist"
7+
import visit from "unist-util-visit"
8+
import { Parent } from "hast-util-to-estree"
79

810
export async function transformInlineCodes(tree: Node) {
11+
visit(tree, "emphasis", (node: Parent) => {
12+
if (
13+
node.children &&
14+
node.children.length === 1 &&
15+
node.children[0].type === "inlineCode"
16+
) {
17+
node.type = "mdxJsxTextElement"
18+
node.name = "CH.InlineCode"
19+
node.children = [
20+
{ type: "text", value: node.children[0].value },
21+
]
22+
}
23+
})
24+
925
await visitAsync(
1026
tree,
1127
["mdxJsxFlowElement", "mdxJsxTextElement"],

packages/playground/content/test.mdx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
<CH.Section>
1+
Lorem ipsum dolor sit amet. _`console.log("foo bar")`_.
22

3-
Then also install the [mdx plugin for next](focus://2),[mdx](focus://3),[foo bar](focus://4).
3+
Lorem ipsum dolor sit amet. `console.log("foo bar")`.
44

5-
```bash focus=1
6-
npm install
7-
@next/mdx @mdx-js/loader
8-
@code-hike/
9-
mdx@next
10-
```
5+
_`console.log("foo bar")`_
116

12-
</CH.Section>
7+
_`console.log("foo bar")`_
8+
9+
X <CH.InlineCode>console.log("foo bar")</CH.InlineCode>
10+
11+
Lorem ipsum `var x = 1`
12+
13+
_Lorem ipsum `var x = 1`_
14+
15+
**`console.log("foo bar")`**

0 commit comments

Comments
 (0)