Skip to content

Commit

Permalink
Mode.RAW -> Mode.MARKDOWN
Browse files Browse the repository at this point in the history
  • Loading branch information
hmsk committed Feb 27, 2023
1 parent 458da13 commit ee5ae9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ console.log(attributes) //=> { title: 'Awesome Title', description: 'Describe th
### Options

```ts
mode?: ('html' | 'toc' | 'react' | 'vue' | 'raw')[]
mode?: ('html' | 'markdown' | 'toc' | 'react' | 'vue')[]
markdown?: (body: string) => string
markdownIt?: MarkdownIt | MarkdownIt.Options
```
Expand All @@ -65,10 +65,10 @@ Enum for `mode` is provided as `Mode`
import { Mode } from 'vite-plugin-markdown'

console.log(Mode.HTML) //=> 'html'
console.log(Mode.MARKDOWN) //=> 'markdown'
console.log(Mode.TOC) //=> 'toc'
console.log(Mode.REACT) //=> 'react'
console.log(Mode.VUE) //=> 'vue'
console.log(Mode.RAW) //=> 'raw'
```

"Mode" enables you to import markdown file in various formats (HTML, ToC, React/Vue Component)
Expand All @@ -92,15 +92,15 @@ console.log(html) //=> "<h1>This is awesome</h1><p>ite is an opinionated web dev

</details>

#### `Mode.RAW`
#### `Mode.MARKDOWN`

<details>
<summary>Import the raw Markdown content</summary>

```js
import { raw } from './contents/the-doc.md'
import { markdown } from './contents/the-doc.md'

console.log(raw) //=> "# This is awesome \n Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production."
console.log(markdown) //=> "# This is awesome \n Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production."
```
</details>

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum Mode {
HTML = 'html',
REACT = 'react',
VUE = 'vue',
RAW = 'raw',
MARKDOWN = 'markdown',
}

export interface PluginOptions {
Expand Down Expand Up @@ -63,9 +63,9 @@ const tf = (code: string, id: string, options: PluginOptions): TransformResult =
content.addExporting('html')
}

if (options.mode?.includes(Mode.RAW)) {
content.addContext(`const raw = ${JSON.stringify(fm.body)}`)
content.addExporting('raw')
if (options.mode?.includes(Mode.MARKDOWN)) {
content.addContext(`const markdown = ${JSON.stringify(fm.body)}`)
content.addExporting('markdown')
}

if (options.mode?.includes(Mode.TOC)) {
Expand Down

0 comments on commit ee5ae9d

Please sign in to comment.