Skip to content

Commit 947275d

Browse files
committed
wip
1 parent 99c0cec commit 947275d

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/client/app/composables/copyCode.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export function useCopyCode() {
77
const el = e.target as HTMLElement
88
if (el.matches('div[class*="language-"] > button.copy')) {
99
const parent = el.parentElement
10-
const sibling = el.nextElementSibling?.nextElementSibling
10+
const sibling =
11+
el.nextElementSibling?.nextElementSibling?.nextElementSibling
1112
if (!parent || !sibling) {
1213
return
1314
}
@@ -41,6 +42,17 @@ export function useCopyCode() {
4142
timeoutIdMap.set(el, timeoutId)
4243
})
4344
}
45+
46+
if (el.matches('div[class*="language-"] > button.modal')) {
47+
const parent = el.parentElement
48+
const sibling = el.nextElementSibling?.nextElementSibling
49+
?.nextElementSibling as HTMLDialogElement
50+
if (!parent || !sibling) {
51+
return
52+
}
53+
54+
sibling.showModal()
55+
}
4456
})
4557
}
4658
}

src/client/theme-default/styles/components/vp-doc.css

+28-1
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,35 @@
454454
opacity 0.25s;
455455
}
456456

457+
.vp-doc [class*='language-'] > button.modal {
458+
/*rtl:ignore*/
459+
direction: ltr;
460+
position: absolute;
461+
top: 64px;
462+
/*rtl:ignore*/
463+
right: 12px;
464+
z-index: 3;
465+
border: 1px solid var(--vp-code-copy-code-border-color);
466+
border-radius: 4px;
467+
width: 40px;
468+
height: 40px;
469+
background-color: var(--vp-code-copy-code-bg);
470+
opacity: 0;
471+
cursor: pointer;
472+
background-image: var(--vp-icon-copy);
473+
background-position: 50%;
474+
background-size: 20px;
475+
background-repeat: no-repeat;
476+
transition:
477+
border-color 0.25s,
478+
background-color 0.25s,
479+
opacity 0.25s;
480+
}
481+
457482
.vp-doc [class*='language-']:hover > button.copy,
458-
.vp-doc [class*='language-'] > button.copy:focus {
483+
.vp-doc [class*='language-'] > button.copy:focus,
484+
.vp-doc [class*='language-']:hover > button.modal,
485+
.vp-doc [class*='language-'] > button.modal:focus {
459486
opacity: 1;
460487
}
461488

src/node/markdown/plugins/preWrapper.ts

+4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ export function preWrapperPlugin(md: MarkdownIt, options: Options) {
2222
return (
2323
`<div class="language-${lang}${getAdaptiveThemeMarker(options)}${active}">` +
2424
`<button title="${options.codeCopyButtonTitle}" class="copy"></button>` +
25+
`<button title="${options.codeCopyButtonTitle}" class="modal"></button>` +
2526
`<span class="lang">${lang}</span>` +
2627
fence(...args) +
28+
'<dialog>' +
29+
fence(...args) +
30+
'</dialog>' +
2731
'</div>'
2832
)
2933
}

0 commit comments

Comments
 (0)