markdown-magic 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,217 @@
1
+ const { test } = require('uvu')
2
+ const assert = require('uvu/assert')
3
+ const weirdParse = require('./weird-parse')
4
+
5
+
6
+ const bigExample = `width={999} 
7
+ height={{111}}
8
+ numberAsString="12345" 
9
+ great={["scoot", "sco ot", 'scooo ttt']} 
10
+ nice={{ value: nice, cool: "true" }}
11
+ soclose=[jdjdjd, hdhfhfhffh]
12
+ rad="boss"
13
+ cool=true notCool=false
14
+ nooooo={[one, two, 3, 4]}
15
+ numberZero=0,
16
+ xyz=999,
17
+ nope=false,
18
+ // comment
19
+ yes={true}
20
+ isWhat,
21
+ /* comment */
22
+ foo={{ rad: ["whatever", "man"], cool: { beans: 'here' } }}
23
+ # other comment
24
+ what='xnxnx'
25
+ isLoading 
26
+ whatever={{ chill: "https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna", pill: ['yo']}}
27
+ href="https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna"
28
+ src="https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg"
29
+ deep={{ rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }}`
30
+
31
+
32
+ test('Multi line', () => {
33
+ const parsedValue = weirdParse(bigExample)
34
+ // console.log('parsedValue', parsedValue)
35
+ assert.equal(parsedValue, {
36
+ width: 999,
37
+ height: 111,
38
+ numberAsString: "12345", 
39
+ great: [ 'scoot', 'sco ot', 'scooo ttt' ],
40
+ nice: { value: 'nice', cool: 'true' },
41
+ soclose: [ 'jdjdjd', 'hdhfhfhffh' ],
42
+ rad: 'boss',
43
+ cool: true,
44
+ notCool: false,
45
+ nooooo: [ 'one', 'two', 3, 4 ],
46
+ numberZero: 0,
47
+ xyz: 999,
48
+ nope: false,
49
+ yes: true,
50
+ isWhat: true,
51
+ foo: { rad: [ 'whatever', 'man' ], cool: { beans: 'here' } },
52
+ what: 'xnxnx',
53
+ isLoading: true,
54
+ whatever: {
55
+ chill: 'https://app.netlify.com/start/deploy?repositoryhttps://github.com/netlify/netlify-faunadb-example&stackfauna',
56
+ pill: [ 'yo' ]
57
+ },
58
+ href: 'https://fooo.com/start/deploy?repositoryhttps://github.com/netlify/netlify-faunadb-example&stackfauna',
59
+ src: 'https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg',
60
+ deep: { rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }
61
+ }, 'matches original')
62
+ })
63
+
64
+ const testSpacing = `width={999} 
65
+ height={{111}}
66
+ numberAsString="12345" 
67
+ great={["scoot", "sco ot", 'scooo ttt']} 
68
+ nope=false,
69
+ // comment
70
+ yes={true}
71
+ isWhat,
72
+ /* comment */
73
+ foo={{ rad: ["whatever", "man"], cool: { beans: 'here' } }}
74
+ # other comment
75
+ what='xnxnx'
76
+ isLoading 
77
+ href="https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna"
78
+ src="https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg"
79
+ deep={{ rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }}
80
+ `
81
+
82
+ // Verify indentation doesnt matter
83
+ test('Multi line indent', () => {
84
+ const parsedValue = weirdParse(testSpacing)
85
+ // console.log('parsedValue', parsedValue)
86
+ assert.equal(parsedValue, {
87
+ width: 999,
88
+ height: 111,
89
+ numberAsString: '12345',
90
+ great: [ 'scoot', 'sco ot', 'scooo ttt' ],
91
+ nope: false,
92
+ yes: true,
93
+ isWhat: true,
94
+ foo: { rad: [ 'whatever', 'man' ], cool: { beans: 'here' } },
95
+ what: 'xnxnx',
96
+ isLoading: true,
97
+ href: 'https://fooo.com/start/deploy?repositoryhttps://github.com/netlify/netlify-faunadb-example&stackfauna',
98
+ src: 'https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg',
99
+ deep: { rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }
100
+ }, 'matches original')
101
+ })
102
+
103
+ test('Single line', () => {
104
+ const parsedValue = weirdParse(`width={999} height={{111}} numberAsString="12345" great={["scoot", "sco ot", 'scooo ttt']} nice={{ value: nice, cool: "true" }} soclose=[jdjdjd, hdhfhfhffh] rad="boss" cool=true isCool notCool=false nooooo={[one, two, 3, 4]}`)
105
+ console.log('parsedValue', parsedValue)
106
+ assert.equal(parsedValue, {
107
+ width: 999,
108
+ height: 111,
109
+ numberAsString: '12345',
110
+ great: [ 'scoot', 'sco ot', 'scooo ttt' ],
111
+ nice: { value: 'nice', cool: 'true' },
112
+ soclose: [ 'jdjdjd', 'hdhfhfhffh' ],
113
+ rad: 'boss',
114
+ cool: true,
115
+ isCool: true,
116
+ notCool: false,
117
+ nooooo: [ 'one', 'two', 3, 4 ]
118
+ }, 'matches original')
119
+ })
120
+
121
+ test('Simple string equal (single quotes)', () => {
122
+ const parsedValue = weirdParse(`bob='cool'`)
123
+ assert.equal(parsedValue, {
124
+ bob: 'cool',
125
+ })
126
+ })
127
+
128
+ test('Simple string equal (double quotes)', () => {
129
+ const parsedValue = weirdParse(`bob="cool"`)
130
+ assert.equal(parsedValue, {
131
+ bob: 'cool',
132
+ })
133
+ })
134
+
135
+ test('Simple string equal (no quotes)', () => {
136
+ const parsedValue = weirdParse(`bob=cool`)
137
+ // console.log('parsedValue', parsedValue)
138
+ assert.equal(parsedValue, {
139
+ bob: 'cool',
140
+ })
141
+ })
142
+
143
+ test('Simple string equal (no quotes with spaces)', () => {
144
+ const answer = { bob: 'cool' }
145
+ const one = weirdParse(`bob = cool`)
146
+ const two = weirdParse(`bob= cool`)
147
+ const three = weirdParse(`bob =cool`)
148
+ // console.log('parsedValue', parsedValue)
149
+ assert.equal(one, answer)
150
+ assert.equal(two, answer)
151
+ assert.equal(three, answer)
152
+ })
153
+
154
+ test('Simple boolean', () => {
155
+ const answer = { isCool: true }
156
+ const one = weirdParse(`isCool`)
157
+ const two = weirdParse(`isCool = true`)
158
+ const three = weirdParse(`isCool =true`)
159
+ const four = weirdParse(`isCool=true`)
160
+ const fourx = weirdParse(`isCool={true}`)
161
+ const foury = weirdParse(`isCool={{true}}`)
162
+
163
+ assert.equal(one, answer)
164
+ assert.equal(two, answer)
165
+ assert.equal(three, answer)
166
+ assert.equal(four, answer)
167
+ assert.equal(fourx, answer)
168
+ assert.equal(foury, answer)
169
+
170
+ const answerTwo = { isNotCool: false }
171
+ const five = weirdParse(`isNotCool=false`)
172
+ const six = weirdParse(`isNotCool = false`)
173
+ const seven = weirdParse(`isNotCool =false`)
174
+ const eight = weirdParse(`isNotCool=false`)
175
+ const nine = weirdParse(`isNotCool= false`)
176
+ const ten = weirdParse(`isNotCool={false}`)
177
+ const eleven = weirdParse(`isNotCool={{false}}`)
178
+
179
+ assert.equal(five, answerTwo, 'five')
180
+ assert.equal(six, answerTwo, 'six')
181
+ assert.equal(seven, answerTwo, 'seven')
182
+ assert.equal(eight, answerTwo, 'eight')
183
+ assert.equal(nine, answerTwo, 'nine')
184
+ assert.equal(ten, answerTwo, 'ten')
185
+ assert.equal(eleven, answerTwo, 'eleven')
186
+ })
187
+
188
+ test('Simple object', () => {
189
+ const a = { key: { a: 'b' }}
190
+ assert.equal(a, weirdParse(`key={{ "a": "b" }}`))
191
+ assert.equal(a, weirdParse(`key={{ "a": b }}`))
192
+ assert.equal(a, weirdParse(`key={{ a: "b" }}`))
193
+ assert.equal(a, weirdParse(`key={{ a: b }}`))
194
+ assert.equal(a, weirdParse(`key={ a : b }`), 'single {')
195
+
196
+ const answer = { nice: { value: 'nice', cool: 'true', awesome: false } }
197
+ const one = weirdParse(`nice={{ value: nice, cool: "true", awesome: false }}`)
198
+ assert.equal(one, answer)
199
+ })
200
+
201
+ test('Simple array', () => {
202
+ const x = { key: [ 1, 2, 3 ] }
203
+ const y = weirdParse(`key=[ 1, 2, 3 ]`)
204
+ assert.equal(x, y)
205
+
206
+ const z = weirdParse(`key=[ "1", "2", "3" ]`)
207
+ assert.equal(z, { key: [ "1", "2", "3" ] })
208
+
209
+ const a = weirdParse(`key=[ one, two, three ]`)
210
+ assert.equal(a, { key: [ "one", "two", "three" ] })
211
+
212
+ const answer = { great: [ 'scoot', 'sco ot', 'scooo ttt', 'one', 'two', 3, 4, true ] }
213
+ const one = weirdParse(`great={["scoot", "sco ot", 'scooo ttt', one, two, 3, 4, true]} `)
214
+ assert.equal(one, answer)
215
+ })
216
+
217
+ test.run()
package/package.json CHANGED
@@ -1,14 +1,23 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "Automatically update markdown files with content from external sources",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "markdown": "./cli.js",
8
8
  "md-magic": "./cli.js"
9
9
  },
10
+ "files": [
11
+ "README.md",
12
+ "package.json",
13
+ "index.js",
14
+ "cli.js",
15
+ "cli-utils.js",
16
+ "/lib"
17
+ ],
10
18
  "scripts": {
11
19
  "docs": "node examples/generate-readme.js",
20
+ "uvu": "uvu lib '.test.([mc]js|[jt]sx?)$'",
12
21
  "test": "ava --verbose",
13
22
  "test:watch": "ava --verbose --watch",
14
23
  "cli": "node ./cli.js --path 'README.md' --config ./markdown.config.js",
@@ -32,6 +41,7 @@
32
41
  "find-up": "^5.0.0",
33
42
  "globby": "^10.0.2",
34
43
  "is-local-path": "^0.1.6",
44
+ "json-alexander": "^0.1.8",
35
45
  "mkdirp": "^1.0.4",
36
46
  "sync-request": "^6.1.0"
37
47
  },
@@ -39,7 +49,11 @@
39
49
  "ava": "^3.15.0",
40
50
  "doxxx": "^1.0.0",
41
51
  "rimraf": "^3.0.2",
42
- "sinon": "^11.1.1"
52
+ "sinon": "^11.1.1",
53
+ "uvu": "^0.5.1",
54
+ "ansi-styles": "^4.2.1",
55
+ "concordance": "^5.0.1",
56
+ "safe-chalk": "^1.0.0"
43
57
  },
44
58
  "ava": {
45
59
  "files": [
@@ -1 +0,0 @@
1
- github: [davidwells]
@@ -1,40 +0,0 @@
1
- name: Test
2
- on:
3
- push:
4
- pull_request:
5
- env:
6
- FORCE_COLOR: 2
7
- jobs:
8
- full:
9
- name: Node.js 15 Full
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Checkout the repository
13
- uses: actions/checkout@v2
14
- - name: Install Node.js
15
- uses: actions/setup-node@v2
16
- with:
17
- node-version: 15
18
- - name: Install dependencies
19
- uses: bahmutov/npm-install@v1
20
- - name: Run tests
21
- run: npm test
22
- short:
23
- runs-on: ubuntu-latest
24
- strategy:
25
- matrix:
26
- node-version:
27
- - 14
28
- - 12
29
- name: Node.js ${{ matrix.node-version }} Quick
30
- steps:
31
- - name: Checkout the repository
32
- uses: actions/checkout@v2
33
- - name: Install Node.js ${{ matrix.node-version }}
34
- uses: actions/setup-node@v2
35
- with:
36
- node-version: ${{ matrix.node-version }}
37
- - name: Install dependencies
38
- uses: bahmutov/npm-install@v1
39
- - name: Run unit tests
40
- run: npm test
package/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: node_js
2
- sudo: false
3
- node_js:
4
- - 8
5
-
6
- install:
7
- - npm install
8
-
9
- script:
10
- - npm test
@@ -1,5 +0,0 @@
1
- import path from 'path'
2
- import markdownMagic from 'markdown-magic'
3
-
4
- const markdownPath = path.join(__dirname, 'README.md')
5
- markdownMagic(markdownPath)
@@ -1,37 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const markdownMagic = require('../index')
4
- // const markdownMagic = require('markdown-magic')
5
-
6
- const config = {
7
- matchWord: 'MD-MAGIC-EXAMPLE', // default matchWord is AUTO-GENERATED-CONTENT
8
- transforms: {
9
- /* Match <!-- AUTO-GENERATED-CONTENT:START (customTransform:optionOne=hi&optionOne=DUDE) --> */
10
- customTransform(content, options) {
11
- console.log('original content in comment block', content)
12
- console.log('options defined on transform', options)
13
- // options = { optionOne: hi, optionOne: DUDE}
14
- return `This will replace all the contents of inside the comment ${options.optionOne}`
15
- },
16
- /* Match <!-- AUTO-GENERATED-CONTENT:START (RENDERDOCS:path=../file.js) --> */
17
- RENDERDOCS(content, options) {
18
- const fileContents = fs.readFileSync(options.path, 'utf8')
19
- const docBlocs = require('doxxx').parseComments(fileContents, { raw: true, skipSingleStar: true })
20
- let updatedContent = ''
21
- docBlocs.forEach((data) => {
22
- updatedContent += `${data.description.full}\n\n`
23
- })
24
- return updatedContent.replace(/^\s+|\s+$/g, '')
25
- },
26
- /* Match <!-- AUTO-GENERATED-CONTENT:START (pluginExample) --> */
27
- pluginExample: require('./plugin-example')({ addNewLine: true }),
28
- /* Include plugins from NPM */
29
- // count: require('markdown-magic-wordcount'),
30
- // github: require('markdown-magic-github-contributors')
31
- }
32
- }
33
-
34
- const markdownPath = path.join(__dirname, '..', 'README.md')
35
- markdownMagic(markdownPath, config, () => {
36
- console.log('Docs ready')
37
- })
@@ -1,14 +0,0 @@
1
- {
2
- "name": "markdown-magic-usage-example",
3
- "version": "1.0.0",
4
- "description": "Usage example",
5
- "main": "example.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "David Wells",
10
- "license": "MIT",
11
- "dependencies": {
12
- "dox": "^0.9.0"
13
- }
14
- }
@@ -1,16 +0,0 @@
1
- /* Custom Transform Plugin example */
2
- const merge = require('deepmerge')
3
- module.exports = function customPlugin(pluginOptions) {
4
- // set plugin defaults
5
- const defaultOptions = {
6
- addNewLine: false
7
- }
8
- const userOptions = pluginOptions || {}
9
- const pluginConfig = merge(defaultOptions, userOptions)
10
- // return the transform function
11
- return function myCustomTransform (content, options) {
12
- const newLine = (pluginConfig.addNewLine) ? '\n' : ''
13
- const updatedContent = content + newLine
14
- return updatedContent
15
- }
16
- }
@@ -1,13 +0,0 @@
1
- /* CLI markdown.config.js file example */
2
- module.exports = {
3
- matchWord: 'MD-MAGIC-EXAMPLE',
4
- transforms: {
5
- /* Match <!-- AUTO-GENERATED-CONTENT:START (LOLZ) --> */
6
- LOLZ(content, options) {
7
- return `This section was generated by the cli config markdown.config.js file`
8
- }
9
- },
10
- callback: function () {
11
- console.log('markdown processing done')
12
- }
13
- }
@@ -1,21 +0,0 @@
1
- # Test Fixture
2
-
3
- This is normal text in markdown. Keep it.
4
-
5
- <!-- AUTO-GENERATED-CONTENT:START (CODE:src=./local-code-file.js&syntax=js) -->
6
- THIS CONTENT GETS AUTO GENERATED. Don't directly edit it
7
- <!-- AUTO-GENERATED-CONTENT:END -->
8
-
9
- <!-- AUTO-GENERATED-CONTENT:START (CODE:src=./local-code-file-lines.js&syntax=js&lines=4-5) -->
10
- THIS CONTENT GETS AUTO GENERATED. Don't directly edit it
11
- <!-- AUTO-GENERATED-CONTENT:END -->
12
-
13
- <!-- AUTO-GENERATED-CONTENT:START (CODE:src=https://raw.githubusercontent.com/DavidWells/markdown-magic/master/examples/generate-readme.js) -->
14
- Remote code block will go here
15
- <!-- AUTO-GENERATED-CONTENT:END -->
16
-
17
- <!-- AUTO-GENERATED-CONTENT:START (CODE:src=https://raw.githubusercontent.com/DavidWells/markdown-magic/master/examples/package.json&lines=9-10) -->
18
- Remote code block will go here
19
- <!-- AUTO-GENERATED-CONTENT:END -->
20
-
21
- This is normal text in markdown. Keep it.
@@ -1,9 +0,0 @@
1
- # Custom Async Transform
2
-
3
- This is normal text in markdown. Keep it.
4
-
5
- <!-- AUTO-GENERATED-CONTENT:START (customAsync:optionOne=hi) -->
6
- will be transformed
7
- <!-- AUTO-GENERATED-CONTENT:END -->
8
-
9
- This is normal text in markdown. Keep it.
@@ -1,9 +0,0 @@
1
- # Custom Transform
2
-
3
- This is normal text in markdown. Keep it.
4
-
5
- <!-- AUTO-GENERATED-CONTENT:START (customTransform) -->
6
- xyz
7
- <!-- AUTO-GENERATED-CONTENT:END -->
8
-
9
- This is normal text in markdown. Keep it.
@@ -1,12 +0,0 @@
1
- # Remote Transform
2
-
3
- This is normal text in markdown. Keep it.
4
-
5
- <!-- AUTO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/DavidWells/markdown-magic/master/README.md) - Do not remove or modify this section -->
6
-
7
- All of this content will be replaced with remote content from https://raw.githubusercontent.com/DavidWells/markdown-magic/master/README.md
8
-
9
- via the `REMOTE` transform
10
- <!-- AUTO-GENERATED-CONTENT:END -->
11
-
12
- This is normal text in markdown. Keep it.
@@ -1,39 +0,0 @@
1
- # Test for TOC
2
-
3
- <!-- AUTO-GENERATED-CONTENT:START (TOC) - Test #1: without option and the content with empty line -->
4
-
5
- <!-- AUTO-GENERATED-CONTENT:END -->
6
-
7
- <!-- AUTO-GENERATED-CONTENT:START (TOC:collapse=true&collapseText=Click Me) - Test #2: with collapse options and the content with 'aaaaaaaaa' -->
8
- aaaaaaaaa
9
- <!-- AUTO-GENERATED-CONTENT:END -->
10
-
11
- <!-- AUTO-GENERATED-CONTENT:START (TOC:collapse=true&collapseText=Click Me=I have the power) - Test #3: with collapseText contains character '=' -->
12
-
13
- <!-- AUTO-GENERATED-CONTENT:END -->
14
-
15
- <!-- AUTO-GENERATED-CONTENT:START (TOC) - Test #4: without option and the content is empty -->
16
- <!-- AUTO-GENERATED-CONTENT:END -->
17
-
18
- <!-- AUTO-GENERATED-CONTENT:START (TOC) - Test #5: without option and tags with same line --><!-- AUTO-GENERATED-CONTENT:END -->
19
-
20
-
21
- ## Title A
22
-
23
- Text A
24
-
25
- ### Subtitle z
26
-
27
- Text Z
28
-
29
- ### Subtitle x
30
-
31
- Text X
32
-
33
- ## Title B
34
-
35
- Text B
36
-
37
- ## Title C
38
-
39
- Text B
@@ -1,9 +0,0 @@
1
- # Test Changing Comment MatchWord
2
-
3
- The comments in this markdown file use `YOLO:START` instead of the default match word
4
-
5
- <!-- YOLO:START (CODE:src=./local-code-file.js&syntax=js) -->
6
- THIS CONTENT GETS AUTO GENERATED. Don't directly edit it
7
- <!-- YOLO:END -->
8
-
9
- This is normal text in markdown. Keep it.
@@ -1,6 +0,0 @@
1
-
2
-
3
- if (foo = bar) {
4
- const baz = 'foobar'
5
- console.log(`Hello ${baz}`)
6
- }
@@ -1,6 +0,0 @@
1
-
2
-
3
- module.exports.run = () => {
4
- const time = new Date()
5
- console.log(`Your cron ran ${time}`)
6
- }
@@ -1,9 +0,0 @@
1
- # Nested File
2
-
3
- This is normal text in markdown. Keep it.
4
-
5
- <!-- AUTO-GENERATED-CONTENT:START (REMOTE:url=https://raw.githubusercontent.com/DavidWells/markdown-magic/master/README.md) - Do not remove or modify this section -->
6
- test
7
- <!-- AUTO-GENERATED-CONTENT:END -->
8
-
9
- This is normal text in markdown. Keep it.