-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52ea37c
commit 657d2fd
Showing
12 changed files
with
203 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
...power/src/client/components/VPDemoVue.vue → ...wer/src/client/components/VPDemoBasic.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { App } from 'vuepress' | ||
import type { Markdown } from 'vuepress/markdown' | ||
import type { DemoContainerRender, DemoFile, DemoMeta, MarkdownDemoEnv } from '../../shared/demo.js' | ||
import { findFile, readFileSync } from './supports/file.js' | ||
|
||
export function markdownEmbed( | ||
app: App, | ||
md: Markdown, | ||
env: MarkdownDemoEnv, | ||
{ url, title, desc, codeSetting = '', expanded = false }: DemoMeta, | ||
): string { | ||
const filepath = findFile(app, env, url) | ||
const code = readFileSync(filepath) | ||
if (code === false) { | ||
console.warn('[vuepress-plugin-md-power] Cannot read markdown file:', filepath) | ||
return '' | ||
} | ||
const demo: DemoFile = { type: 'markdown', path: filepath } | ||
|
||
env.demoFiles ??= [] | ||
|
||
if (!env.demoFiles.some(d => d.path === filepath)) { | ||
env.demoFiles.push(demo) | ||
} | ||
|
||
return `<VPDemoBasic type="markdown"${title ? ` title="${title}"` : ''}${desc ? ` desc="${desc}"` : ''}${expanded ? ' expanded' : ''}> | ||
${md.render(code, { filepath: env.filePath, filepathRelative: env.filePathRelative })} | ||
<template #code> | ||
${md.render(`\`\`\`md ${codeSetting}\n${code}\n\`\`\``, {})} | ||
</template> | ||
</VPDemoBasic>` | ||
} | ||
|
||
export const markdownContainerRender: DemoContainerRender = { | ||
before(app, md, env, meta, codeMap) { | ||
const { title, desc, expanded = false } = meta | ||
const code = codeMap.md || '' | ||
return `<VPDemoBasic type="markdown"${title ? ` title="${title}"` : ''}${desc ? ` desc="${desc}"` : ''}${expanded ? ' expanded' : ''}> | ||
${md.render(code, { filepath: env.filePath, filepathRelative: env.filePathRelative })} | ||
<template #code>` | ||
}, | ||
after: () => '</template></VPDemoBasic>', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.