Skip to content

Commit

Permalink
feat: new
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskang committed Mar 28, 2024
1 parent 47dee25 commit 67a9f19
Show file tree
Hide file tree
Showing 7 changed files with 1,840 additions and 1,139 deletions.
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@
"docs:preview": "pnpm --filter test-vitepress preview",
"build": "pnpm --filter vite-plugin-markdown-preview build",
"test": "vitest",
"coverage": "vitest --coverage",
"coverage": "vitest --coverage",
"change": "pnpm changeset",
"release": "pnpm build && changeset publish"
},
"devDependencies": {
"@changesets/changelog-git": "^0.1.14",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@changesets/changelog-git": "^0.2.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@jaskang/config": "^2.0.0",
"@jaskang/eslint-config": "^2.0.0",
"@types/node": "^20.5.4",
"@vitejs/plugin-vue": "^4.3.3",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"eslint": "^8.47.0",
"prettier": "^3.0.2",
"tsup": "^7.2.0",
"typescript": "^5.1.6",
"vite": "^4.4.9",
"vite-plugin-dts": "^3.5.2",
"vite-plugin-inspect": "^0.7.38",
"vitest": "^0.34.2",
"vue": "^3.3.4",
"sass": "^1.66.1",
"vitepress": "1.0.0-rc.4"
"@types/node": "^20.11.30",
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"sass": "^1.72.0",
"tsup": "^8.0.2",
"typescript": "^5.4.3",
"vite": "^5.2.6",
"vite-plugin-dts": "^3.8.1",
"vite-plugin-inspect": "^0.8.3",
"vitepress": "1.0.1",
"vitest": "^1.4.0",
"vue": "^3.4.21"
},
"packageManager": "pnpm@8.6.12",
"packageManager": "pnpm@8.15.5",
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
Expand Down
10 changes: 5 additions & 5 deletions packages/vite-plugin-markdown-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
},
"dependencies": {
"debug": "^4.3.4",
"mdast-util-from-markdown": "^1.2.0",
"mdast-util-frontmatter": "^1.0.0",
"mdast-util-to-markdown": "^1.5.0",
"unist-util-visit": "^4.1.1"
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-frontmatter": "^2.0.1",
"mdast-util-to-markdown": "^2.1.0",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@types/mdast": "^3.0.10"
"@types/mdast": "^4.0.3"
}
}
108 changes: 1 addition & 107 deletions packages/vite-plugin-markdown-preview/src/components/CodePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,54 +44,6 @@ export default defineComponent({
<div class="mdp-demo__preview">
<slot />
</div>
<div class="mdp-demo__toolbar">
<div class="mdp-demo__btn mdp-demo__btn-copy" @click="copyCode">
<svg
v-if="copied"
xmlns="http://www.w3.org/2000/svg"
fill="none"
height="20"
width="20"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2m-6 9 2 2 4-4"
/>
</svg>
<svg
v-else
xmlns="http://www.w3.org/2000/svg"
fill="none"
height="20"
width="20"
stroke="currentColor"
stroke-width="2"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2"
/>
</svg>
</div>
<div class="mdp-demo__btn mdp-demo__btn-code" @click="toggleCode">
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">
<path
fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="46"
d="M160 368L32 256l128-112M352 368l128-112-128-112M304 96l-96 320"
/>
</svg>
</div>
</div>
<div
class="mdp-demo__code"
:style="{ height: height + 'px', visibility: height > 0 ? 'visible' : 'hidden' }"
Expand All @@ -101,62 +53,4 @@ export default defineComponent({
</div>
</div>
</div>
</template>
<style>
:root {
--mdp-border-color: var(--vp-c-divider-light-2, rgba(60, 60, 60, 0.12));
--mdp-btn-bg-hover: var(--vp-c-gray-light-5, #f2f2f2);
}
.dark {
--mdp-border-color: var(--vp-c-divider-dark-2, rgba(84, 84, 84, 0.48));
--mdp-btn-bg-hover: var(--vp-c-gray-dark-3, #3a3a3a);
}
.mdp-demo {
border-radius: 4px;
overflow: hidden;
border: 1px solid var(--mdp-border-color);
}
.mdp-demo__preview {
padding: 1rem;
}
.mdp-demo__toolbar {
height: 38px;
display: flex;
align-items: center;
justify-content: flex-end;
border-top: 1px solid var(--mdp-border-color);
}
.mdp-demo__btn {
width: 38px;
height: 100%;
align-items: center;
text-align: center;
margin-left: 4px;
display: flex;
justify-content: center;
cursor: pointer;
user-select: none;
}
.mdp-demo__btn:hover {
background-color: var(--mdp-btn-bg-hover);
}
.mdp-demo__toolbar svg {
width: 1rem;
height: 1rem;
}
.mdp-demo.is-expanded .mdp-demo__code {
border-top: 1px solid var(--mdp-border-color);
}
.mdp-demo__code div[class*='language-'] {
margin: 0;
border-radius: 0;
}
.mdp-demo__code pre {
margin: 0;
}
.mdp-demo__code .shiki {
padding: 1rem;
}
</style>
</template>
2 changes: 1 addition & 1 deletion packages/vite-plugin-markdown-preview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function MarkdownPreview(options?: MarkdownPreviewOptions): Plugin {
path.resolve(__dirname, './components/style.css'),
'utf-8'
)

const config: MarkdownPreviewConfig = Object.assign(
{ component: 'CodePreview', type: 'vite' as const, root: '' },
options
Expand Down
12 changes: 5 additions & 7 deletions packages/vite-plugin-markdown-preview/src/remark.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { createHash } from 'node:crypto'

import type { Code, Parent } from 'mdast'
import { fromMarkdown } from 'mdast-util-from-markdown'
import { frontmatterFromMarkdown, frontmatterToMarkdown } from 'mdast-util-frontmatter'
import { toMarkdown } from 'mdast-util-to-markdown'
import { type Node, visit } from 'unist-util-visit'
import { visit } from 'unist-util-visit'

import { MarkdownPreviewConfig } from '.'

Expand All @@ -30,7 +29,7 @@ export function remarkDemoBlock(id: string, code: string, config: MarkdownPrevie

const blocks: Record<string, string> = {}

visit(tree as Node, 'code', (node: Code, index: number, parent: Parent) => {
visit(tree, 'code', (node, index , parent) => {
const lang = (node.lang || '').split(':')[0]
const meta = praseMeta(node.meta)
const preview = meta['preview']
Expand All @@ -39,9 +38,8 @@ export function remarkDemoBlock(id: string, code: string, config: MarkdownPrevie
const hash = getHash(node.value)
const name = `DemoBlockI${hash}`
blocks[name] = node.value

parent.children.splice(
index,
parent!.children.splice(
index!,
1,
{
type: 'html',
Expand All @@ -60,7 +58,7 @@ component="${typeof preview === 'string' ? preview : config.component}"
value: '\n</template></CodePreviewWrapper>',
}
)
return index + 3
return index! + 3
}
})
if (Object.keys(blocks).length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion playground/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"markdown-it-shiki": "^0.9.0",
"unplugin-vue-markdown": "^0.24.1",
"unplugin-vue-markdown": "^0.25.2",
"vite-plugin-markdown-preview": "workspace:*"
}
}
Loading

0 comments on commit 67a9f19

Please sign in to comment.