Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ToBinio committed May 10, 2024
1 parent 99c0cec commit 947275d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/client/app/composables/copyCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function useCopyCode() {
const el = e.target as HTMLElement
if (el.matches('div[class*="language-"] > button.copy')) {
const parent = el.parentElement
const sibling = el.nextElementSibling?.nextElementSibling
const sibling =
el.nextElementSibling?.nextElementSibling?.nextElementSibling
if (!parent || !sibling) {
return
}
Expand Down Expand Up @@ -41,6 +42,17 @@ export function useCopyCode() {
timeoutIdMap.set(el, timeoutId)
})
}

if (el.matches('div[class*="language-"] > button.modal')) {
const parent = el.parentElement
const sibling = el.nextElementSibling?.nextElementSibling
?.nextElementSibling as HTMLDialogElement
if (!parent || !sibling) {
return
}

sibling.showModal()
}
})
}
}
Expand Down
29 changes: 28 additions & 1 deletion src/client/theme-default/styles/components/vp-doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,35 @@
opacity 0.25s;
}

.vp-doc [class*='language-'] > button.modal {
/*rtl:ignore*/
direction: ltr;
position: absolute;
top: 64px;
/*rtl:ignore*/
right: 12px;
z-index: 3;
border: 1px solid var(--vp-code-copy-code-border-color);
border-radius: 4px;
width: 40px;
height: 40px;
background-color: var(--vp-code-copy-code-bg);
opacity: 0;
cursor: pointer;
background-image: var(--vp-icon-copy);
background-position: 50%;
background-size: 20px;
background-repeat: no-repeat;
transition:
border-color 0.25s,
background-color 0.25s,
opacity 0.25s;
}

.vp-doc [class*='language-']:hover > button.copy,
.vp-doc [class*='language-'] > button.copy:focus {
.vp-doc [class*='language-'] > button.copy:focus,
.vp-doc [class*='language-']:hover > button.modal,
.vp-doc [class*='language-'] > button.modal:focus {
opacity: 1;
}

Expand Down
4 changes: 4 additions & 0 deletions src/node/markdown/plugins/preWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ export function preWrapperPlugin(md: MarkdownIt, options: Options) {
return (
`<div class="language-${lang}${getAdaptiveThemeMarker(options)}${active}">` +
`<button title="${options.codeCopyButtonTitle}" class="copy"></button>` +
`<button title="${options.codeCopyButtonTitle}" class="modal"></button>` +
`<span class="lang">${lang}</span>` +
fence(...args) +
'<dialog>' +
fence(...args) +
'</dialog>' +
'</div>'
)
}
Expand Down

0 comments on commit 947275d

Please sign in to comment.