GithubHelp home page GithubHelp logo

buptsteve / markdown-it-vuese Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 8.0 487 KB

📖 Vuese plugin for markdown-it markdown parser

Home Page: https://buptsteve.github.io/markdown-it-vuese

License: MIT License

JavaScript 88.62% Vue 11.38%
markdown markdown-it markdown-plugin vuese documentation

markdown-it-vuese's Introduction

markdown-it-vuese

Build Status Coverage Status dependencies Downloads per month Version License

English | 简体中文

Vuese plugin for markdown-it markdown parser.

With this plugin, you can use Vuese to automatically generate documents while importing existing *.vue files via following syntax.

<[vuese](@/filePath)

The default value of @ is process.cwd().

Please click here to see the demo

Install

$ npm i -S markdown-it-vuese
# OR
$ yarn add markdown-it-vuese

Usage

const md = require('markdown-it')()
    .use(require('markdown-it-vuese') [, options])

Options

const md = require('markdown-it')()
    .use(require('markdown-it-vuese'), {
        root: 'some path',
        vueseRe: /your regexp/,
        useParser: parserRes => parserRes.name,
        useRender: (vueseRender) => {
            const renderRes = vueseRender.render()
            const markdownRes = vueseRender.renderMarkdown()

            return 'something'
        },
        useAll: ({ ... }) => {
            return 'something'
        },
    })

root

  • Type: String
  • Default: process.cwd()

Root Directory, this value will replace the @ in file path.

vueseRe

  • Type: RegExp
  • Default: /<\[vuese\]\((.+)\)/i

Regular expression, you can customize it as you like.

ruleName

  • Type: String
  • Default: vuese

Rule name, it will be used by markdown-it, so be careful not to duplicate existing rules.

Use it with vueseRe, we can use different rules in the same document to render different results.

const vuese = require('markdown-it-vuese')

const md = require('markdown-it')()
    // default
    // <[vuese](filePath)
    .use(vuese)
    // <[vuese-h3](filePath)
    // No title, `Props` and other attributes should be changed from `<h2>` to `<h3>`
    .use(vuese, {
        vueseRe: /<\[vuese-h3\]\((.+)\)/i,
        ruleName: 'vuese-h3',
        useRender: (vueseRender) => {
            const renderRes = vueseRender.render()
            const genMd = key => `### ${key}\n${renderRes[key]}\n`

            return Object.keys(renderRes).map(genMd).join('')
        },
    })

useParser

  • Type: Function
  • Default: null

It takes @vuese/parser ParserResult as a parameter.

If useParser exists, it returns the result directly after running, otherwise try running useRender.

useRender

  • Type: Function
  • Default: null

It takes @vuese/markdown-render Render Class as a parameter.

If useRender exists, it returns the result directly after running, otherwise try running useAll.

For example, you can call the following methods to generate objects and markdown documents, respectively.

  • render: will generate renderRes
  • renderMarkdown: will generate markdownRes

useAll

  • Type: Function
  • Default: null

It takes an object as parameters with there attributes: content(source file content), parserRes, renderRes, markdownRes.

Return markdownRes.content by default, if useAll does not exist.

const md = require('markdown-it')()
    .use(require('markdown-it-vuese'), {
        useAll: ({
            content,
            parserRes,
            renderRes,
            markdownRes,
        }) => {
            return 'something'
        },
    })

parserOptions

  • Type: Object
  • Default: {}

It passes @vuese/parser options

renderOptions

  • Type: Object
  • Default: {}

It passes @vuese/markdown-render options

License

MIT

Copyright (c) StEve Young

markdown-it-vuese's People

Contributors

buptsteve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

markdown-it-vuese's Issues

bug: lose hoistedTags

Describe the bug

when you use it in Vuepress after some hoistedTags like <script>, we will lose them...

To Reproduce
Steps to reproduce the behavior:

  1. write a <script> before it
  2. use it

Expected behavior

works well

bug: TypeError: Cannot read property 'references' of undefined

Version
Version 0.3.0

Describe the bug

TypeError: Cannot read property 'references' of undefined
at Array.link (xxx/node_modules/markdown-it/lib/rules_inline/link.js:102:26)
at ParserInline.tokenize (xxx/node_modules/markdown-it/lib/parser_inline.js:135:22)
at ParserInline.parse (xxx/node_modules/markdown-it/lib/parser_inline.js:163:8)
at Array.inline (xxx/node_modules/markdown-it/lib/rules_core/inline.js:10:23)
at Core.process (xxx/node_modules/markdown-it/lib/parser_core.js:51:13)
at MarkdownIt.parse (xxx/node_modules/markdown-it/lib/index.js:523:13)
at Array.<anonymous> (xxx/node_modules/markdown-it-vuese/dist/index.cjs.js:47:28)
at Core.process (xxx/node_modules/markdown-it/lib/parser_core.js:51:13)
at MarkdownIt.parse (xxx/node_modules/markdown-it/lib/index.js:523:13)
at module.exports (xxx/node_modules/@vuepress/shared-utils/lib/extractHeaders.js:22:23)
at Page.process (xxx/node_modules/@vuepress/core/lib/prepare/Page.js:115:25)

Additional context
https://github.com/markdown-it/markdown-it/blob/master/lib/index.js#L516

bug: source file and html are out of sync

Version
Version 0.2.2

Describe the bug
After modifying the source file, the content of the page does not refresh.

The temporary solution is to save the corresponding markdown file.

To Reproduce
Steps to reproduce the behavior:

  1. use it with vuepress
  2. run vuepress dev
  3. modify source file, like foo.vue, and save it
  4. out of sync

Expected behavior
After modifying the source file, we should get a new content.

Additional context
It's the same problem with Import Code Snippets

vuejs/vuepress#1309

feat: english docs

Is your feature request related to a problem? Please describe.
add english readme and docs

无法正确编译

版本
Version [0.4.0]

描述一下 bug

image

复现 bug
复现的步骤:

  1. 配置
  markdown: {
    lineNumbers: true,
    extendMarkdown: (md) => {
      md.use(require('markdown-it-vuese'), {
        vueseRe: /<\[vuese-h3\]\((.+)\)/i,
        ruleName: 'vuese-h3',
        useRender: (vueseRender) => {
          const renderRes = vueseRender.render()
          const genMd = key => `### ${key}\n${renderRes[key]}\n`

          return Object.keys(renderRes).map(genMd).join('')
        },
      })
    }
  }
  1. 看到了错误

Error: Cannot find module '/Users/codeman/working/gitee/eh-ui/node_modules/@vuese/parser/dist/lib/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:328:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:689:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1016:27)
at Function.Module._load (internal/modules/cjs/loader.js:898:27)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at Object. (/Users/codeman/working/gitee/eh-ui/node_modules/markdown-it-vuese/dist/index.cjs.js:8:16)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at extendMarkdown (/Users/codeman/working/gitee/eh-ui/docs/.vuepress/config.js:45:14)
at afterInstantiate (/Users/codeman/.nvm/versions/node/v14.4.0/lib/node_modules/vuepress/node_modules/@vuepress/core/lib/node/createMarkdown.js:23:23)
at module.exports (/Users/codeman/.nvm/versions/node/v14.4.0/lib/node_modules/vuepress/node_modules/@vuepress/markdown/index.js:124:23)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.