Skip to content

Commit

Permalink
feat: style md <kbd>
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Nov 4, 2024
1 parent f86b099 commit 38d516a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dev/src/routes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ A note[^1]

~one~ or ~~two~~ tildes.

<kbd class="cls">Ctrl</kbd> + <kbd>C</kbd>

| a | b | c | d |
| -------- | :------- | -------: | :------: |
| longword | longword | longword | longword |
Expand Down
2 changes: 2 additions & 0 deletions docs/src/routes/guide/dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ A note[^1]

~one~ or ~~two~~ tildes.

<kbd class="cls">Ctrl</kbd> + <kbd>C</kbd>

| a | b | c | d |
| -------- | :------- | -------: | :------: |
| longword | longword | longword | longword |
Expand Down
2 changes: 2 additions & 0 deletions src/config/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import remarkMdxFrontmatter from "remark-mdx-frontmatter";
import type { SolidBaseResolvedConfig } from ".";
import { rehypeFixExpressiveCodeJsx } from "./rehype-plugins";
import {
remarkAddClass,
remarkDirectiveContainers,
remarkGithubAlertsToDirectives,
remarkIssueAutolink,
Expand Down Expand Up @@ -67,6 +68,7 @@ export function solidBaseMdx(sbConfig: SolidBaseResolvedConfig<any>) {
remarkRelativeImports,
remarkTOC,
remarkDirectiveContainers,
remarkAddClass,
[remarkIssueAutolink, sbConfig.issueAutolink],
...(sbConfig.markdown?.remarkPlugins ?? []),
],
Expand Down
22 changes: 22 additions & 0 deletions src/config/remark-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,25 @@ export function remarkRelativeImports() {
});
};
}

export function remarkAddClass() {
return (tree: any) => {
visit(tree, (node) => {
if (node.type !== "mdxJsxTextElement" && node.name !== "kbd") return;

node.attributes ??= [];

const found = node.attributes.find((attr: any) => attr.name === "class");

if (found) {
found.value += " sb-kbd";
} else {
node.attributes.push({
type: "mdxJsxAttribute",
name: "class",
value: "sb-kbd",
});
}
});
};
}
9 changes: 9 additions & 0 deletions src/default-theme/mdx-components.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ h2[id="footnote-label"] {
line-height: 1.3;
}

:global(.sb-kbd) {
border-radius: var(--border-radius);
border: 1px solid var(--decoration-color);
border-bottom-width: 3px;
background: color-mix(in hsl, var(--decoration-color) 10%, transparent);
color: var(--heading-color);
padding: .1em .4em;
}

.a,
a[data-footnote-backref],
a[data-footnote-ref] {
Expand Down

0 comments on commit 38d516a

Please sign in to comment.