markdown-magic 3.0.0 → 3.0.1
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.
- package/README.md +43 -29
- package/lib/block-parser-js.test.js +148 -156
- package/lib/block-parser.js +255 -262
- package/lib/block-parser.test.js +43 -6
- package/lib/cli.js +30 -19
- package/lib/cli.test.js +73 -73
- package/lib/globals.d.ts +66 -0
- package/lib/index.js +43 -9
- package/lib/process-contents.js +80 -39
- package/lib/process-file.js +4 -1
- package/lib/transforms/code.js +4 -10
- package/lib/transforms/file.js +7 -10
- package/lib/transforms/index.js +0 -0
- package/lib/transforms/remote.js +2 -3
- package/lib/transforms/sectionToc.js +18 -0
- package/lib/transforms/toc.js +10 -335
- package/lib/types.js +11 -0
- package/lib/utils/fs.js +21 -19
- package/lib/utils/fs.test.js +4 -5
- package/lib/utils/logs.js +7 -2
- package/lib/utils/md/filters.js +5 -5
- package/lib/utils/md/find-code-blocks.js +16 -8
- package/lib/utils/md/find-frontmatter.js +11 -13
- package/lib/utils/md/find-frontmatter.test.js +2 -2
- package/lib/utils/md/find-html-tags.js +1 -1
- package/lib/utils/md/find-images-md.js +27 -0
- package/lib/utils/md/find-images.js +39 -34
- package/lib/utils/md/find-links.js +72 -54
- package/lib/utils/md/find-unmatched-html-tags.js +1 -2
- package/lib/utils/md/fixtures/file-with-links.md +10 -0
- package/lib/utils/md/md.test.js +72 -4
- package/lib/utils/md/parse.js +91 -67
- package/lib/utils/regex-timeout.js +2 -1
- package/lib/utils/regex.js +3 -2
- package/lib/utils/remoteRequest.js +1 -0
- package/lib/utils/syntax.js +3 -0
- package/lib/utils/text.js +71 -3
- package/lib/utils/text.test.js +3 -9
- package/lib/utils/toc.js +315 -0
- package/package.json +7 -3
- package/lib/options-parser.js +0 -498
- package/lib/options-parser.test.js +0 -1237
- package/lib/utils/html-to-json/compat.js +0 -42
- package/lib/utils/html-to-json/format.js +0 -64
- package/lib/utils/html-to-json/index.js +0 -37
- package/lib/utils/html-to-json/lexer.js +0 -345
- package/lib/utils/html-to-json/parser.js +0 -146
- package/lib/utils/html-to-json/stringify.js +0 -37
- package/lib/utils/html-to-json/tags.js +0 -171
package/lib/block-parser.test.js
CHANGED
|
@@ -32,6 +32,9 @@ nice
|
|
|
32
32
|
lol
|
|
33
33
|
<\!-- XYZ:END -->
|
|
34
34
|
|
|
35
|
+
<!-- XYZ:START funky-key-here kldskjfjslfjs -->
|
|
36
|
+
lol
|
|
37
|
+
<!-- XYZ:END -->
|
|
35
38
|
|
|
36
39
|
<\!-- xyz:start (lowerCase) foo=['one', 'two'] heading=false -->
|
|
37
40
|
nice
|
|
@@ -185,6 +188,7 @@ test('verify parser', () => {
|
|
|
185
188
|
/*
|
|
186
189
|
console.log('parsedValue')
|
|
187
190
|
deepLog(parsedValue)
|
|
191
|
+
// process.exit(1)
|
|
188
192
|
/** */
|
|
189
193
|
assert.equal(typeof parsedValue, 'object')
|
|
190
194
|
assert.equal(parsedValue.blocks.length, 11)
|
|
@@ -391,7 +395,12 @@ Very nice
|
|
|
391
395
|
|
|
392
396
|
<!-- DOCS:START(TOC) foo={{ rad: 'orange' }} ------>
|
|
393
397
|
ok
|
|
394
|
-
<!-- DOCS:END
|
|
398
|
+
<!-- DOCS:END -->
|
|
399
|
+
|
|
400
|
+
<!-- DOCS:START (CODE:src=./relative/path/to/code.js&lines=22-44) -->
|
|
401
|
+
This content will be dynamically replaced with code from the file lines 22 through 44
|
|
402
|
+
<!-- DOCS:END -->
|
|
403
|
+
`
|
|
395
404
|
|
|
396
405
|
test('Parse md blocks', () => {
|
|
397
406
|
const parsedValue = parseBlocks(mdText, defaultOpts)
|
|
@@ -405,22 +414,50 @@ test('Parse md blocks', () => {
|
|
|
405
414
|
open: {
|
|
406
415
|
value: "<!-- DOCS:START(TOC) foo={{ rad: 'orange' }} ------>\n",
|
|
407
416
|
start: 12,
|
|
408
|
-
end:
|
|
417
|
+
end: 65
|
|
409
418
|
},
|
|
410
|
-
content: { value: 'ok', start:
|
|
411
|
-
close: { value: '\n<!-- DOCS:END -->', start:
|
|
419
|
+
content: { value: 'ok', start: 65, end: 67, indentation: 0 },
|
|
420
|
+
close: { value: '\n<!-- DOCS:END -->', start: 67, end: 85 },
|
|
412
421
|
block: {
|
|
413
422
|
indentation: '',
|
|
414
423
|
lines: [ 4, 6 ],
|
|
415
424
|
start: 12,
|
|
416
425
|
end: 85,
|
|
417
|
-
rawType: '(TOC)',
|
|
418
426
|
rawArgs: "foo={{ rad: 'orange' }}",
|
|
419
|
-
rawContent: '
|
|
427
|
+
rawContent: 'ok',
|
|
420
428
|
value: "<!-- DOCS:START(TOC) foo={{ rad: 'orange' }} ------>\n" +
|
|
421
429
|
'ok\n' +
|
|
422
430
|
'<!-- DOCS:END -->'
|
|
423
431
|
}
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
index: 2,
|
|
435
|
+
type: 'CODE',
|
|
436
|
+
options: { src: './relative/path/to/code.js', lines: '22-44' },
|
|
437
|
+
context: { isMultiline: true, isLegacy: true },
|
|
438
|
+
open: {
|
|
439
|
+
value: '<!-- DOCS:START (CODE:src=./relative/path/to/code.js&lines=22-44) -->\n',
|
|
440
|
+
start: 87,
|
|
441
|
+
end: 157
|
|
442
|
+
},
|
|
443
|
+
content: {
|
|
444
|
+
value: 'This content will be dynamically replaced with code from the file lines 22 through 44',
|
|
445
|
+
start: 157,
|
|
446
|
+
end: 242,
|
|
447
|
+
indentation: 0
|
|
448
|
+
},
|
|
449
|
+
close: { value: '\n<!-- DOCS:END -->', start: 242, end: 260 },
|
|
450
|
+
block: {
|
|
451
|
+
indentation: '',
|
|
452
|
+
lines: [ 8, 10 ],
|
|
453
|
+
start: 87,
|
|
454
|
+
end: 260,
|
|
455
|
+
rawArgs: 'src=./relative/path/to/code.js&lines=22-44',
|
|
456
|
+
rawContent: 'This content will be dynamically replaced with code from the file lines 22 through 44',
|
|
457
|
+
value: '<!-- DOCS:START (CODE:src=./relative/path/to/code.js&lines=22-44) -->\n' +
|
|
458
|
+
'This content will be dynamically replaced with code from the file lines 22 through 44\n' +
|
|
459
|
+
'<!-- DOCS:END -->'
|
|
460
|
+
}
|
|
424
461
|
}
|
|
425
462
|
], 'Array contains details')
|
|
426
463
|
})
|
package/lib/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ const isValidFilePath = require('is-valid-path')
|
|
|
5
5
|
const { loadConfig } = require('./utils/load-config')
|
|
6
6
|
const { findUp } = require('./utils/fs')
|
|
7
7
|
const { markdownMagic } = require('./')
|
|
8
|
-
const {
|
|
8
|
+
const { parse } = require('oparser')
|
|
9
9
|
const { deepLog } = require('./utils/logs')
|
|
10
10
|
const { REGEX_REGEX, escapeRegexString } = require('./utils/regex')
|
|
11
11
|
const { getFirstCharacter, isUpperCase } = require('./utils/text')
|
|
@@ -13,7 +13,18 @@ const argv = process.argv.slice(2)
|
|
|
13
13
|
const cwd = process.cwd()
|
|
14
14
|
const defaultConfigPath = 'md.config.js'
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const ARRAY_REGEX = /^\[(.*)\]$/
|
|
17
|
+
|
|
18
|
+
/** @type {BUILD_VERSION} */
|
|
19
|
+
const x = 'f'
|
|
20
|
+
|
|
21
|
+
function isArrayLike(str) {
|
|
22
|
+
if (typeof str !== 'string') return false
|
|
23
|
+
return Boolean(ARRAY_REGEX.test(str))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function getBaseDir(opts = {}) {
|
|
27
|
+
const { currentDir = cwd } = opts
|
|
17
28
|
const gitDir = await findUp(currentDir, '.git')
|
|
18
29
|
return (gitDir) ? path.dirname(gitDir) : currentDir
|
|
19
30
|
}
|
|
@@ -45,15 +56,15 @@ function removeNodeModules(value = '') {
|
|
|
45
56
|
|
|
46
57
|
function coerceStringToRegex(str) {
|
|
47
58
|
const isRegex = str.match(REGEX_REGEX)
|
|
48
|
-
if (isRegex) {
|
|
49
|
-
|
|
50
|
-
return new RegExp(escapeRegexString(pattern, flags))
|
|
59
|
+
if (!isRegex) {
|
|
60
|
+
return str
|
|
51
61
|
}
|
|
52
|
-
|
|
62
|
+
const [ _match, pattern, flags ] = isRegex
|
|
63
|
+
return new RegExp(escapeRegexString(pattern), flags)
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
function convertToArray(str = '') {
|
|
56
|
-
const { fixedArray } =
|
|
67
|
+
const { fixedArray } = parse(`fixedArray=${str}`)
|
|
57
68
|
return (fixedArray || [])
|
|
58
69
|
}
|
|
59
70
|
|
|
@@ -74,12 +85,12 @@ node ./cli.js test/fixtures/md/**.md debug --transform test/fixtures/md/transfor
|
|
|
74
85
|
*/
|
|
75
86
|
function getGlobGroupsFromArgs(args, opts = {}) {
|
|
76
87
|
const globKeys = opts.globKeys || []
|
|
77
|
-
let
|
|
88
|
+
let preceding = ['', '']
|
|
78
89
|
let collection = []
|
|
79
90
|
let globGroups = []
|
|
80
91
|
let reserved = []
|
|
81
92
|
let otherOpts = []
|
|
82
|
-
let cacheKey = ''
|
|
93
|
+
let /** @type {string|undefined} */ cacheKey = ''
|
|
83
94
|
for (let i = 0; i < args.length; i++) {
|
|
84
95
|
const isLastArg = (args.length - 1) === i
|
|
85
96
|
const arg = args[i]
|
|
@@ -95,7 +106,7 @@ function getGlobGroupsFromArgs(args, opts = {}) {
|
|
|
95
106
|
} else if (arg.match(/^-+/)) {
|
|
96
107
|
cacheKey = arg
|
|
97
108
|
if (collection.length) {
|
|
98
|
-
const val = getValue(
|
|
109
|
+
const val = getValue(preceding)
|
|
99
110
|
reserved.push(val)
|
|
100
111
|
globGroups.push({
|
|
101
112
|
key: trimLeadingDashes(val),
|
|
@@ -104,7 +115,7 @@ function getGlobGroupsFromArgs(args, opts = {}) {
|
|
|
104
115
|
})
|
|
105
116
|
collection = []
|
|
106
117
|
}
|
|
107
|
-
|
|
118
|
+
preceding = [ prevArg, arg ]
|
|
108
119
|
} else if (cacheKey && arg.match(/=/)) {
|
|
109
120
|
// console.log('FOOO', arg)
|
|
110
121
|
cacheKey = undefined
|
|
@@ -131,7 +142,7 @@ function getGlobGroupsFromArgs(args, opts = {}) {
|
|
|
131
142
|
}
|
|
132
143
|
|
|
133
144
|
if (isLastArg && collection.length) {
|
|
134
|
-
const val = getValue(
|
|
145
|
+
const val = getValue(preceding)
|
|
135
146
|
reserved.push(val)
|
|
136
147
|
globGroups.push({
|
|
137
148
|
key: trimLeadingDashes(val),
|
|
@@ -148,9 +159,6 @@ function getGlobGroupsFromArgs(args, opts = {}) {
|
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
|
|
151
|
-
// const unique = Array.from(new Set(dismiss.concat(nodeSlug)))
|
|
152
|
-
|
|
153
|
-
|
|
154
162
|
async function runCli(options = {}) {
|
|
155
163
|
let configFile
|
|
156
164
|
let opts = {}
|
|
@@ -165,10 +173,11 @@ async function runCli(options = {}) {
|
|
|
165
173
|
// options.glob = argv[0]
|
|
166
174
|
// }
|
|
167
175
|
const globParse = getGlobGroupsFromArgs(argv, {
|
|
168
|
-
|
|
176
|
+
/* CLI args that should be glob keys */
|
|
169
177
|
globKeys: ['files', 'file']
|
|
170
178
|
})
|
|
171
179
|
const { globGroups, otherOpts } = globParse
|
|
180
|
+
console.log('globGroups', globGroups)
|
|
172
181
|
// deepLog(globParse)
|
|
173
182
|
// console.log('globParse', globParse)
|
|
174
183
|
if (globGroups.length) {
|
|
@@ -194,11 +203,13 @@ async function runCli(options = {}) {
|
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
/* Parse for weird CLI inputs */
|
|
197
|
-
const extraParse =
|
|
206
|
+
const extraParse = parse(otherOpts.join(' '))
|
|
198
207
|
|
|
199
208
|
/*
|
|
200
|
-
console.log('otherOpts', otherOpts)
|
|
201
|
-
console.log('
|
|
209
|
+
// console.log('otherOpts', otherOpts)
|
|
210
|
+
console.log('nicely handed CLI args')
|
|
211
|
+
console.log(extraParse)
|
|
212
|
+
process.exit(1)
|
|
202
213
|
/** */
|
|
203
214
|
|
|
204
215
|
delete options._
|
package/lib/cli.test.js
CHANGED
|
@@ -19,83 +19,83 @@ test('Exports API', () => {
|
|
|
19
19
|
assert.equal(typeof getGlobGroupsFromArgs, 'function', 'undefined val')
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const longArgs = [
|
|
23
|
+
'test/fixtures/md/basic.md',
|
|
24
|
+
'test/fixtures/md/error-missing-transforms-two.md',
|
|
25
|
+
'test/fixtures/md/error-missing-transforms.md',
|
|
26
|
+
'test/fixtures/md/error-no-block-transform-defined.md',
|
|
27
|
+
'test/fixtures/md/error-unbalanced.md',
|
|
28
|
+
'test/fixtures/md/format-inline.md',
|
|
29
|
+
'test/fixtures/md/format-with-wacky-indentation.md',
|
|
30
|
+
'test/fixtures/md/inline-two.md',
|
|
31
|
+
'test/fixtures/md/inline.md',
|
|
32
|
+
'test/fixtures/md/missing-transform.md',
|
|
33
|
+
'test/fixtures/md/mixed.md',
|
|
34
|
+
'test/fixtures/md/no-transforms.md',
|
|
35
|
+
'test/fixtures/md/string.md',
|
|
36
|
+
'test/fixtures/md/syntax-legacy-colon.md',
|
|
37
|
+
'test/fixtures/md/syntax-legacy-query.md',
|
|
38
|
+
'test/fixtures/md/transform-code.md',
|
|
39
|
+
'test/fixtures/md/transform-custom.md',
|
|
40
|
+
'test/fixtures/md/transform-file.md',
|
|
41
|
+
'test/fixtures/md/transform-remote.md',
|
|
42
|
+
'test/fixtures/md/transform-toc.md',
|
|
43
|
+
'test/fixtures/md/transform-wordCount.md',
|
|
44
|
+
'debug',
|
|
45
|
+
'--transform',
|
|
46
|
+
'test/fixtures/md/transform-code.md',
|
|
47
|
+
'test/fixtures/md/transform-custom.md',
|
|
48
|
+
'test/fixtures/md/transform-file.md',
|
|
49
|
+
'test/fixtures/md/transform-remote.md',
|
|
50
|
+
'test/fixtures/md/transform-toc.md',
|
|
51
|
+
'test/fixtures/md/transform-wordCount.md',
|
|
52
|
+
'1233535235',
|
|
53
|
+
'=',
|
|
54
|
+
'hahah',
|
|
55
|
+
'funky=hi',
|
|
56
|
+
'--ignore',
|
|
57
|
+
'test/fixtures/output/basic.md',
|
|
58
|
+
'test/fixtures/output/block-no-transform.md',
|
|
59
|
+
'test/fixtures/output/error-missing-transforms-two.md',
|
|
60
|
+
'test/fixtures/output/error-missing-transforms.md',
|
|
61
|
+
'test/fixtures/output/fixture-code.md',
|
|
62
|
+
'test/fixtures/output/format-inline.md',
|
|
63
|
+
'test/fixtures/output/format-with-wacky-indentation.md',
|
|
64
|
+
'test/fixtures/output/go-simple.md',
|
|
65
|
+
'test/fixtures/output/inline-two.md',
|
|
66
|
+
'test/fixtures/output/inline.md',
|
|
67
|
+
'test/fixtures/output/missing-transform.md',
|
|
68
|
+
'test/fixtures/output/mixed.md',
|
|
69
|
+
'test/fixtures/output/params.md',
|
|
70
|
+
'test/fixtures/output/remote.md',
|
|
71
|
+
'test/fixtures/output/toc.md',
|
|
72
|
+
'test/fixtures/output/transform-code.md',
|
|
73
|
+
'test/fixtures/output/transform-custom.md',
|
|
74
|
+
'test/fixtures/output/transform-file.md',
|
|
75
|
+
'test/fixtures/output/transform-remote.md',
|
|
76
|
+
'test/fixtures/output/transform-toc.md',
|
|
77
|
+
'test/fixtures/output/transform-wordCount.md',
|
|
78
|
+
'test/fixtures/output/with-wacky-indentation.md',
|
|
79
|
+
'--lol',
|
|
80
|
+
'--whatever',
|
|
81
|
+
'test/fixtures/md/syntax-legacy-colon.md',
|
|
82
|
+
'test/fixtures/md/syntax-legacy-query.md',
|
|
83
|
+
'--foo=bar',
|
|
84
|
+
'--fun',
|
|
85
|
+
'lol.md',
|
|
86
|
+
'what=no.md',
|
|
87
|
+
'x',
|
|
88
|
+
'xno.md',
|
|
89
|
+
'what'
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
test('getGlobGroupsFromArgs returns globs', () => {
|
|
23
93
|
/* CLI command with list of files already passed in
|
|
24
94
|
node ./cli.js test/fixtures/md/**.md debug --transform test/fixtures/md/transform-**.md 1233535235 = hahah funky=hi --ignore test/fixtures/output/**.md --lol --whatever test/fixtures/md/syntax-**.md --foo=bar --fun lol.md what=no.md x 'xno.md' what
|
|
25
95
|
*/
|
|
26
|
-
const
|
|
27
|
-
'test/fixtures/md/basic.md',
|
|
28
|
-
'test/fixtures/md/error-missing-transforms-two.md',
|
|
29
|
-
'test/fixtures/md/error-missing-transforms.md',
|
|
30
|
-
'test/fixtures/md/error-no-block-transform-defined.md',
|
|
31
|
-
'test/fixtures/md/error-unbalanced.md',
|
|
32
|
-
'test/fixtures/md/format-inline.md',
|
|
33
|
-
'test/fixtures/md/format-with-wacky-indentation.md',
|
|
34
|
-
'test/fixtures/md/inline-two.md',
|
|
35
|
-
'test/fixtures/md/inline.md',
|
|
36
|
-
'test/fixtures/md/missing-transform.md',
|
|
37
|
-
'test/fixtures/md/mixed.md',
|
|
38
|
-
'test/fixtures/md/no-transforms.md',
|
|
39
|
-
'test/fixtures/md/string.md',
|
|
40
|
-
'test/fixtures/md/syntax-legacy-colon.md',
|
|
41
|
-
'test/fixtures/md/syntax-legacy-query.md',
|
|
42
|
-
'test/fixtures/md/transform-code.md',
|
|
43
|
-
'test/fixtures/md/transform-custom.md',
|
|
44
|
-
'test/fixtures/md/transform-file.md',
|
|
45
|
-
'test/fixtures/md/transform-remote.md',
|
|
46
|
-
'test/fixtures/md/transform-toc.md',
|
|
47
|
-
'test/fixtures/md/transform-wordCount.md',
|
|
48
|
-
'debug',
|
|
49
|
-
'--transform',
|
|
50
|
-
'test/fixtures/md/transform-code.md',
|
|
51
|
-
'test/fixtures/md/transform-custom.md',
|
|
52
|
-
'test/fixtures/md/transform-file.md',
|
|
53
|
-
'test/fixtures/md/transform-remote.md',
|
|
54
|
-
'test/fixtures/md/transform-toc.md',
|
|
55
|
-
'test/fixtures/md/transform-wordCount.md',
|
|
56
|
-
'1233535235',
|
|
57
|
-
'=',
|
|
58
|
-
'hahah',
|
|
59
|
-
'funky=hi',
|
|
60
|
-
'--ignore',
|
|
61
|
-
'test/fixtures/output/basic.md',
|
|
62
|
-
'test/fixtures/output/block-no-transform.md',
|
|
63
|
-
'test/fixtures/output/error-missing-transforms-two.md',
|
|
64
|
-
'test/fixtures/output/error-missing-transforms.md',
|
|
65
|
-
'test/fixtures/output/fixture-code.md',
|
|
66
|
-
'test/fixtures/output/format-inline.md',
|
|
67
|
-
'test/fixtures/output/format-with-wacky-indentation.md',
|
|
68
|
-
'test/fixtures/output/go-simple.md',
|
|
69
|
-
'test/fixtures/output/inline-two.md',
|
|
70
|
-
'test/fixtures/output/inline.md',
|
|
71
|
-
'test/fixtures/output/missing-transform.md',
|
|
72
|
-
'test/fixtures/output/mixed.md',
|
|
73
|
-
'test/fixtures/output/params.md',
|
|
74
|
-
'test/fixtures/output/remote.md',
|
|
75
|
-
'test/fixtures/output/toc.md',
|
|
76
|
-
'test/fixtures/output/transform-code.md',
|
|
77
|
-
'test/fixtures/output/transform-custom.md',
|
|
78
|
-
'test/fixtures/output/transform-file.md',
|
|
79
|
-
'test/fixtures/output/transform-remote.md',
|
|
80
|
-
'test/fixtures/output/transform-toc.md',
|
|
81
|
-
'test/fixtures/output/transform-wordCount.md',
|
|
82
|
-
'test/fixtures/output/with-wacky-indentation.md',
|
|
83
|
-
'--lol',
|
|
84
|
-
'--whatever',
|
|
85
|
-
'test/fixtures/md/syntax-legacy-colon.md',
|
|
86
|
-
'test/fixtures/md/syntax-legacy-query.md',
|
|
87
|
-
'--foo=bar',
|
|
88
|
-
'--fun',
|
|
89
|
-
'lol.md',
|
|
90
|
-
'what=no.md',
|
|
91
|
-
'x',
|
|
92
|
-
'xno.md',
|
|
93
|
-
'what'
|
|
94
|
-
]
|
|
95
|
-
|
|
96
|
-
const globData = getGlobGroupsFromArgs(rawArgv)
|
|
96
|
+
const globData = getGlobGroupsFromArgs(longArgs)
|
|
97
97
|
//*
|
|
98
|
-
logInput(
|
|
98
|
+
logInput(longArgs)
|
|
99
99
|
deepLogger(globData)
|
|
100
100
|
/** */
|
|
101
101
|
assert.equal(globData.globGroups, [
|
package/lib/globals.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export {}
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
const BUILD_VERSION: string;
|
|
5
|
+
interface TestGlob {
|
|
6
|
+
greeting: string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
color?: string;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export type TinyProps = {
|
|
15
|
+
message: string;
|
|
16
|
+
count: number;
|
|
17
|
+
disabled: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
declare var Age: number;
|
|
21
|
+
|
|
22
|
+
declare function greetTwo(greeting: string): void;
|
|
23
|
+
|
|
24
|
+
interface GreetingSettings {
|
|
25
|
+
greeting: string;
|
|
26
|
+
duration?: number;
|
|
27
|
+
color?: string;
|
|
28
|
+
}
|
|
29
|
+
declare function greet(setting: GreetingSettings): void;
|
|
30
|
+
|
|
31
|
+
export namespace testFnTypes {
|
|
32
|
+
type input = boolean | Function;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Use namespaces to organize types.
|
|
36
|
+
// Ref like GreetingLib.LogOptions
|
|
37
|
+
export declare namespace GreetingLib {
|
|
38
|
+
interface LogOptions {
|
|
39
|
+
verbose?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface AlertOptions {
|
|
42
|
+
modal: boolean;
|
|
43
|
+
title?: string;
|
|
44
|
+
color?: string;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export declare namespace Xyz.Options {
|
|
49
|
+
// Refer to via Xyz.Options.Log
|
|
50
|
+
interface Log {
|
|
51
|
+
verbose?: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface Alert {
|
|
54
|
+
modal: boolean;
|
|
55
|
+
title?: string;
|
|
56
|
+
color?: string;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export namespace Dotted {
|
|
61
|
+
type Name = number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export declare class A {
|
|
65
|
+
static foo(): void;
|
|
66
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -3,31 +3,63 @@ const { glob, globWithGit } = require('smart-glob')
|
|
|
3
3
|
const codeTransform = require('./transforms/code')
|
|
4
4
|
const fileTransform = require('./transforms/file')
|
|
5
5
|
const tocTransform = require('./transforms/toc')
|
|
6
|
+
const sectionTocTransform = require('./transforms/sectionToc')
|
|
6
7
|
const wordCountTransform = require('./transforms/wordCount')
|
|
7
8
|
const remoteTransform = require('./transforms/remote')
|
|
8
|
-
const { deepLog, success, error, info } = require('./utils/logs')
|
|
9
9
|
const { getSyntaxInfo } = require('./utils/syntax')
|
|
10
10
|
const { onlyUnique, getCodeLocation, pluralize } = require('./utils')
|
|
11
11
|
const { writeFile, resolveOutputPath, resolveFlatPath } = require('./utils/fs')
|
|
12
12
|
const { processFile } = require('./process-file')
|
|
13
13
|
const { processContents } = require('./process-contents')
|
|
14
|
-
const { getBlockRegex } = require('./block-parser')
|
|
15
|
-
const { OPEN_WORD, CLOSE_WORD, DEFAULT_GLOB_PATTERN } = require('./defaults')
|
|
16
14
|
const { parseMarkdown } = require('./utils/md/parse')
|
|
17
|
-
|
|
18
|
-
const
|
|
15
|
+
const { deepLog, success, error, info } = require('./utils/logs')
|
|
16
|
+
const { OPEN_WORD, CLOSE_WORD, DEFAULT_GLOB_PATTERN } = require('./defaults')
|
|
17
|
+
// const { getBlockRegex } = require('./block-parser')
|
|
19
18
|
// const diff = require('../misc/old-test/utils/diff')
|
|
20
19
|
|
|
20
|
+
const LINE = '────────────────────────────────'
|
|
21
|
+
|
|
21
22
|
const defaultTransforms = {
|
|
22
23
|
CODE: codeTransform,
|
|
23
24
|
FILE: fileTransform,
|
|
24
25
|
TOC: tocTransform,
|
|
26
|
+
sectionToc: sectionTocTransform,
|
|
25
27
|
wordCount: wordCountTransform,
|
|
26
28
|
remote: remoteTransform
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Allowed file syntaxes
|
|
33
|
+
* @typedef {'md' | 'js' | 'yml' | 'yaml'} SyntaxType
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for markdown magic
|
|
38
|
+
*
|
|
39
|
+
* Below is the main config for markdown magic
|
|
40
|
+
*
|
|
41
|
+
* @typedef {object} MarkdownMagicOptions
|
|
42
|
+
* @property {Array} [transforms = defaultTransforms] - Custom commands to transform block contents, see transforms & custom transforms sections below.
|
|
43
|
+
* @property {string} [outputDir] - Change output path of new content. Default behavior is replacing the original file
|
|
44
|
+
* @property {SyntaxType} [syntax = 'md'] - Syntax to parse
|
|
45
|
+
* @property {boolean} [outputFlatten] - Flatten files that are output
|
|
46
|
+
* @property {function} [handleOutputPath] - Custom function for altering output paths
|
|
47
|
+
* @property {boolean} [useGitGlob] - Use git glob for LARGE file directories
|
|
48
|
+
* @property {boolean} [dryRun = false] - See planned execution of matched blocks
|
|
49
|
+
* @property {boolean} [debug = false] - See debug details
|
|
50
|
+
* @property {boolean} [failOnMissingTransforms = false] - Fail if transform functions are missing. Default skip blocks.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Markdown Magic
|
|
55
|
+
* @param {string|MarkdownMagicOptions} globOrOpts - Files to process or config. Uses [globby patterns](https://github.com/sindresorhus/multimatch/blob/master/test.js)
|
|
56
|
+
* @param {MarkdownMagicOptions} options - Markdown magic config
|
|
57
|
+
* @returns
|
|
58
|
+
* @example
|
|
59
|
+
markdownMagic(filePath, config)
|
|
60
|
+
*/
|
|
29
61
|
async function markdownMagic(globOrOpts, options = {}) {
|
|
30
|
-
let opts = {}
|
|
62
|
+
let opts = options || {}
|
|
31
63
|
let globPat
|
|
32
64
|
if (typeof globOrOpts === 'string' || Array.isArray(globOrOpts)) {
|
|
33
65
|
opts = options
|
|
@@ -35,8 +67,9 @@ async function markdownMagic(globOrOpts, options = {}) {
|
|
|
35
67
|
} else if (typeof globOrOpts === 'object') {
|
|
36
68
|
opts = globOrOpts
|
|
37
69
|
}
|
|
38
|
-
const {
|
|
70
|
+
const {
|
|
39
71
|
transforms,
|
|
72
|
+
// open,
|
|
40
73
|
outputDir,
|
|
41
74
|
outputFlatten = false,
|
|
42
75
|
handleOutputPath,
|
|
@@ -44,6 +77,7 @@ async function markdownMagic(globOrOpts, options = {}) {
|
|
|
44
77
|
failOnMissingTransforms = false,
|
|
45
78
|
dryRun = false,
|
|
46
79
|
debug = true,
|
|
80
|
+
syntax = 'md',
|
|
47
81
|
} = opts
|
|
48
82
|
|
|
49
83
|
let open = OPEN_WORD
|
|
@@ -84,7 +118,7 @@ async function markdownMagic(globOrOpts, options = {}) {
|
|
|
84
118
|
|
|
85
119
|
info(`Running Markdown Magic:`)
|
|
86
120
|
logCommentBlockSyntax({
|
|
87
|
-
syntax:
|
|
121
|
+
syntax: syntax,
|
|
88
122
|
open,
|
|
89
123
|
close
|
|
90
124
|
})
|
|
@@ -265,7 +299,7 @@ async function markdownMagic(globOrOpts, options = {}) {
|
|
|
265
299
|
console.log(`Invalid transforms: ${missingTotal} / ${total}`)
|
|
266
300
|
console.log('Syntax:')
|
|
267
301
|
logCommentBlockSyntax({
|
|
268
|
-
syntax:
|
|
302
|
+
syntax: syntax,
|
|
269
303
|
open,
|
|
270
304
|
close
|
|
271
305
|
})
|