UNPKG

1.55 kBJavaScriptView Raw
1const fs = require('fs')
2const path = require('path')
3const markdownMagic = require('../index') // 'markdown-magic'
4
5const config = {
6 matchWord: 'MD-MAGIC-EXAMPLE', // default matchWord is AUTO-GENERATED-CONTENT
7 transforms: {
8 /* Match <!-- AUTO-GENERATED-CONTENT:START (customTransform:optionOne=hi&optionOne=DUDE) --> */
9 customTransform(content, options) {
10 console.log('original content in comment block', content)
11 console.log('options defined on transform', options)
12 // options = { optionOne: hi, optionOne: DUDE}
13 return `This will replace all the contents of inside the comment ${options.optionOne}`
14 },
15 /* Match <!-- AUTO-GENERATED-CONTENT:START (RENDERDOCS:path=../file.js) --> */
16 RENDERDOCS(content, options) {
17 const fileContents = fs.readFileSync(options.path, 'utf8')
18 const docBlocs = require('doxxx').parseComments(fileContents, { raw: true, skipSingleStar: true })
19 let updatedContent = ''
20 docBlocs.forEach((data) => {
21 updatedContent += `${data.description.full}\n\n`
22 })
23 return updatedContent.replace(/^\s+|\s+$/g, '')
24 },
25 /* Match <!-- AUTO-GENERATED-CONTENT:START (pluginExample) --> */
26 pluginExample: require('./plugin-example')({ addNewLine: true }),
27 /* Plugins from npm */
28 // count: require('markdown-magic-wordcount'),
29 // github: require('markdown-magic-github-contributors')
30 }
31}
32
33const markdownPath = path.join(__dirname, '..', 'README.md')
34markdownMagic(markdownPath, config, () => {
35 console.log('Docs ready')
36})