Skip to content

Commit

Permalink
feat: 实现 preWrapper 插件
Browse files Browse the repository at this point in the history
  • Loading branch information
c0dedance committed Oct 19, 2023
1 parent 2060632 commit 0f2b2d4
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 84 deletions.
6 changes: 5 additions & 1 deletion e2e/playground/basic/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ title: 'island'

## Autolink

literals www.example.com, https://example.com, and contact@example.com.
literals www.example.com, https://example.com, and contact@example.com.

```js
console.log(2)
```
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@commitlint/config-conventional": "^17.7.0",
"@playwright/test": "^1.26.1",
"@types/fs-extra": "^11.0.2",
"@types/hast": "^2.3.4",
"@types/node": "^20.8.4",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
Expand All @@ -45,6 +46,7 @@
"tsup": "^7.2.0",
"tsx": "^3.13.0",
"typescript": "^5.2.2",
"unist-util-visit": "^4.1.1",
"vitest": "^0.34.6"
},
"dependencies": {
Expand All @@ -59,14 +61,14 @@
"react-router-dom": "6.4.3",
"rehype-autolink-headings": "^7.0.0",
"rehype-slug": "^6.0.0",
"rehype-stringify": "^10.0.0",
"rehype-stringify": "^9.0.3",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-mdx-frontmatter": "^3.0.0",
"remark-parse": "^11.0.0",
"remark-parse": "^10.0.1",
"remark-rehype": "^11.0.0",
"rollup": "^4.0.2",
"unified": "^11.0.3",
"unified": "^10.1.2",
"vite": "^4.4.11"
}
}
141 changes: 64 additions & 77 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/node/__test__/md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { describe, test, expect } from 'vitest'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import { rehypePluginPreWrapper } from '../plugin-mdx/rehypePlugins/preWrapper'

describe('Markdown compile cases', () => {
// 初始化 processor
const processor = unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypePluginPreWrapper)
.use(rehypeStringify)

test('Compile title', async () => {
Expand All @@ -24,4 +26,12 @@ describe('Markdown compile cases', () => {
'"<p>I am using <code>Island.js</code></p>"'
)
})
test('Compile code block', async () => {
const mdContent = '```js\nconsole.log(123)\n```'
const result = processor.processSync(mdContent)
expect(result.value).toMatchInlineSnapshot(`
"<div class=\\"language-js\\"><span class=\\"lang\\">js</span><pre><code class=\\"\\">console.log(123)
</code></pre></div>"
`)
})
})
4 changes: 2 additions & 2 deletions src/node/__test__/plugin-routes/RouteService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('RouteService', async () => {
},
{
"absolutePath": "TEST_DIR/guide/index.tsx",
"routePath": "/guide",
"routePath": "/guide/",
},
]
`)
Expand All @@ -39,7 +39,7 @@ describe('RouteService', async () => {
export const routes = [
{ \\"path\\": '/b', \\"element\\": React.createElement(Route0)},
{ \\"path\\": '/guide/a', \\"element\\": React.createElement(Route1)},
{ \\"path\\": '/guide', \\"element\\": React.createElement(Route2)},
{ \\"path\\": '/guide/', \\"element\\": React.createElement(Route2)},
]
"
`)
Expand Down

0 comments on commit 0f2b2d4

Please sign in to comment.