reorganize code

pull/3854/head
Divyansh Singh 1 year ago
parent cf507ae5c1
commit 1f42498813

@ -111,6 +111,11 @@ export interface MarkdownOptions extends Options {
* Setup Shiki instance * Setup Shiki instance
*/ */
shikiSetup?: (shiki: Highlighter) => void | Promise<void> shikiSetup?: (shiki: Highlighter) => void | Promise<void>
/**
* The tooltip text for the copy button in code blocks
* @default 'Copy Code'
*/
codeCopyButtonTitle?: string
/* ==================== Markdown It Plugins ==================== */ /* ==================== Markdown It Plugins ==================== */
@ -184,10 +189,6 @@ export interface MarkdownOptions extends Options {
* @see https://vitepress.dev/guide/markdown#github-flavored-alerts * @see https://vitepress.dev/guide/markdown#github-flavored-alerts
*/ */
gfmAlerts?: boolean gfmAlerts?: boolean
/**
* @default 'Copy Code'
*/
codeCopyButtonTitle?: string
} }
export type MarkdownRenderer = MarkdownIt export type MarkdownRenderer = MarkdownIt
@ -234,7 +235,7 @@ export const createMarkdownRenderer = async (
md.use(gitHubAlertsPlugin) md.use(gitHubAlertsPlugin)
} }
// 3rd party plugins // third party plugins
if (!options.attrs?.disable) { if (!options.attrs?.disable) {
md.use(attrsPlugin, options.attrs) md.use(attrsPlugin, options.attrs)
} }

@ -18,11 +18,14 @@ export function preWrapperPlugin(md: MarkdownIt, options: Options) {
token.info = token.info.replace(/ active$/, '').replace(/ active /, ' ') token.info = token.info.replace(/ active$/, '').replace(/ active /, ' ')
const lang = extractLang(token.info) const lang = extractLang(token.info)
const title = options.codeCopyButtonTitle
const rawCode = fence(...args) return (
return `<div class="language-${lang}${getAdaptiveThemeMarker( `<div class="language-${lang}${getAdaptiveThemeMarker(options)}${active}">` +
options `<button title="${options.codeCopyButtonTitle}" class="copy"></button>` +
)}${active}"><button title="${title}" class="copy"></button><span class="lang">${lang}</span>${rawCode}</div>` `<span class="lang">${lang}</span>` +
fence(...args) +
'</div>'
)
} }
} }

Loading…
Cancel
Save