Skip to content

Commit 7ace41d

Browse files
authored
Merge pull request #695 from maiieul/fix-copy/paste-rehype
fix rehype-pretty-code copy/paste not working
2 parents 230c01b + d56b53c commit 7ace41d

File tree

7 files changed

+5
-37
lines changed

7 files changed

+5
-37
lines changed

apps/website/src/components/code-copy/code-copy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const CodeCopy = component$<CodeCopyProps>(({ code = '', ...props }) => {
1313
return (
1414
<Button
1515
{...props}
16-
look="ghost"
16+
look="link"
1717
title={copied.value ? 'Copied to Clipboard' : 'Copy to Clipboard'}
1818
class={cn(props.class)}
1919
onClick$={async () => {

apps/website/src/components/make-it-yours/make-it-yours.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ export default component$<PropsOf<typeof Button>>(() => {
539539
themeComputedObjectSig.value.mode =
540540
themeComputedObjectSig.value.mode?.includes('light') ? 'dark' : 'light';
541541

542-
console.log(themeComputedObjectSig.value.mode);
543542
setTheme(await themeStoreToThemeClasses$());
544543
}}
545544
/>

apps/website/src/components/mdx-components/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ export const components: Record<string, Component> = {
116116
}>(({ __rawString__ }) => {
117117
return (
118118
<div class="code-example relative mb-6 max-h-[31.25rem] rounded-base">
119-
<CodeCopy
120-
class="absolute right-3 top-3 text-white hover:text-white"
121-
code={__rawString__}
122-
/>
119+
<CodeCopy class="absolute right-3 top-3" code={__rawString__} />
123120
<div
124121
class={cn(
125122
'max-h-[31.25rem] max-w-full overflow-y-auto rounded-base border bg-gradient-to-b from-slate-900 to-slate-800 p-6 text-sm dark:from-background dark:to-accent/30',
@@ -132,7 +129,6 @@ export const components: Record<string, Component> = {
132129
</div>
133130
);
134131
}),
135-
136132
Accordion,
137133
AccordionItem,
138134
AccordionTrigger,

apps/website/src/components/toc/toc.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ const useActiveItem = (itemIds: string[]) => {
3333
const observer = new IntersectionObserver((entries) => {
3434
entries.forEach((entry) => {
3535
if (entry.isIntersecting) {
36-
console.log('entry: ', entry.isIntersecting, entry.target.id);
3736
activeId.value = entry.target.id;
3837
}
3938
});
4039
});
41-
console.log('observer: ', observer);
4240

4341
itemIds.forEach((id) => {
4442
const element = document.getElementById(id);
@@ -67,7 +65,6 @@ type TreeProps = QwikIntrinsicElements['ul'] & {
6765
};
6866

6967
const Tree = component$<TreeProps>(({ headings, level = 1, activeItem }) => {
70-
console.log('level: ', level);
7168
return headings.length > 0 && level < 3 ? (
7269
<ul class={cn('m-0 list-none', { 'pl-4': level !== 1 })}>
7370
{headings.map((heading) => {

apps/website/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
"path": "./tsconfig.spec.json"
2727
}
2828
],
29-
"include": ["src", "../../packages/kit-headless/src/components/select/select.test.ts"]
29+
"include": ["src", "vite.config.ts"]
3030
}

apps/website/tsconfig.spec.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"types": ["vitest/globals", "node"]
66
},
77
"include": [
8-
"vite.config.ts",
98
"src/**/*.test.ts",
109
"src/**/*.spec.ts",
1110
"src/**/*.test.tsx",

apps/website/vite.config.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default defineConfig(async () => {
2121
},
2222
mdx: {
2323
providerImportSource: '~/_state/MDXProvider',
24-
// @ts-ignore
2524
recmaPlugins: [recmaProvideComponents],
2625
rehypePlugins: [
2726
() => (tree) => {
@@ -31,48 +30,26 @@ export default defineConfig(async () => {
3130
if (codeEl.tagName !== 'code') {
3231
return;
3332
}
34-
3533
node.__rawString__ = codeEl.children?.[0].value;
3634
}
3735
});
3836
},
3937
[
40-
// @ts-ignore
4138
rehypePrettyCode,
4239
{
4340
theme: 'poimandres',
44-
onVisitLine(node: any) {
45-
// Prevent lines from collapsing in `display: grid` mode, and allow empty
46-
// lines to be copy/pasted
47-
if (node.children.length === 0) {
48-
node.children = [{ type: 'text', value: ' ' }];
49-
}
50-
},
51-
onVisitHighlightedLine(node: any) {
52-
// Each line node by default has `class="line"`.
53-
if (node.properties.className) {
54-
node.properties.className.push('line--highlighted');
55-
}
56-
},
57-
onVisitHighlightedWord(node: any) {
58-
if (node.properties.className) {
59-
node.properties.className = ['word--highlighted'];
60-
}
61-
},
6241
},
6342
],
6443
() => (tree) => {
6544
visit(tree, (node) => {
66-
if (node?.type === 'element' && node?.tagName === 'div') {
67-
if (!('data-rehype-pretty-code-fragment' in node.properties)) {
45+
if (node?.type === 'element' && node?.tagName === 'figure') {
46+
if (!('data-rehype-pretty-code-figure' in node.properties)) {
6847
return;
6948
}
70-
7149
const preElement = node.children.at(-1);
7250
if (preElement.tagName !== 'pre') {
7351
return;
7452
}
75-
7653
preElement.properties['__rawString__'] = node.__rawString__;
7754
}
7855
});

0 commit comments

Comments
 (0)