markdown-magic 3.0.3 → 3.0.5

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.
Files changed (39) hide show
  1. package/README.md +295 -101
  2. package/cli.js +4 -1
  3. package/lib/block-parser.js +32 -28
  4. package/lib/block-parser.test.js +2 -0
  5. package/lib/cli.js +101 -19
  6. package/lib/cli.test.js +12 -12
  7. package/lib/index.js +418 -119
  8. package/lib/process-contents.js +61 -23
  9. package/lib/process-file.js +40 -4
  10. package/lib/transforms/code.js +33 -10
  11. package/lib/transforms/file.js +4 -2
  12. package/lib/transforms/index.js +114 -0
  13. package/lib/transforms/sectionToc.js +2 -2
  14. package/lib/transforms/toc.js +22 -4
  15. package/lib/transforms/wordCount.js +2 -2
  16. package/lib/utils/fs.js +8 -172
  17. package/lib/utils/fs.test.js +4 -162
  18. package/lib/utils/hash-file.js +28 -0
  19. package/lib/utils/logs.js +16 -2
  20. package/lib/utils/syntax.js +1 -0
  21. package/lib/utils/text.js +1 -1
  22. package/lib/utils/toposort.js +131 -0
  23. package/package.json +4 -3
  24. package/lib/utils/md/filters.js +0 -20
  25. package/lib/utils/md/find-code-blocks.js +0 -88
  26. package/lib/utils/md/find-date.js +0 -32
  27. package/lib/utils/md/find-frontmatter.js +0 -92
  28. package/lib/utils/md/find-frontmatter.test.js +0 -17
  29. package/lib/utils/md/find-html-tags.js +0 -105
  30. package/lib/utils/md/find-images-md.js +0 -27
  31. package/lib/utils/md/find-images.js +0 -107
  32. package/lib/utils/md/find-links.js +0 -220
  33. package/lib/utils/md/find-unmatched-html-tags.js +0 -32
  34. package/lib/utils/md/fixtures/2022-01-22-date-in-filename.md +0 -14
  35. package/lib/utils/md/fixtures/file-with-frontmatter.md +0 -32
  36. package/lib/utils/md/fixtures/file-with-links.md +0 -153
  37. package/lib/utils/md/md.test.js +0 -105
  38. package/lib/utils/md/parse.js +0 -146
  39. package/lib/utils/md/utils.js +0 -19
package/lib/utils/fs.js CHANGED
@@ -57,180 +57,17 @@ async function escalade(start, callback) {
57
57
  }
58
58
  }
59
59
 
60
- // https://github.com/lukeed/totalist
61
- async function totalist(dir, callback, pre='') {
62
- dir = resolve('.', dir)
63
- await readdir(dir).then(arr => {
64
- return Promise.all(arr.map((str) => {
65
- let abs = join(dir, str)
66
- return stat(abs).then(stats => {
67
- return stats.isDirectory() ? totalist(abs, callback, join(pre, str)) : callback(join(pre, str), abs, stats)
68
- })
69
- }))
70
- })
71
- }
72
-
73
- function combineRegexes(patterns = []) {
74
- const string = patterns.map((pat) => {
75
- if (isRegex(pat)) {
76
- return pat.source
77
- } else if (typeof pat === 'string' && REGEX_REGEX.test(pat)) {
78
- const regexInfo = pat.match(REGEX_REGEX)
79
- console.log('regexInfo', regexInfo)
80
- if (regexInfo && regexInfo[1]) {
81
- // escapeRegexString
82
- return regexInfo[1]
83
- }
84
- } else if (isGlob(pat)) {
85
- console.log('pat', pat)
86
- const result = globrex(pat, { globstar: true, extended: true })
87
- console.log('result', result)
88
- return result.regex.source
89
- }
90
- return pat
91
- }).join('|')
92
- console.log('xxxstring', string)
93
- return new RegExp(string)
94
- }
95
-
96
60
  // alt https://github.com/duniul/clean-modules/blob/33b66bcfb7825e1fa1eb1e296e523ddba374f1ae/src/utils/filesystem.ts#L92
97
61
  // Alt https://github.com/AvianFlu/ncp
98
- async function getFilePaths(dirName, {
99
- patterns = [],
100
- ignore = [],
101
- excludeGitIgnore = false,
102
- excludeHidden = false
103
- }) {
104
- let findPattern
105
- let ignorePattern
106
- let filePaths = []
107
- let gitIgnoreFiles = []
108
- let gitIgnoreGlobs = []
109
-
110
- if (patterns && patterns.length) {
111
- findPattern = combineRegexes(patterns)
112
- console.log('findPatternfindPatternfindPattern', patterns)
113
- }
114
- if (ignore && ignore.length) {
115
- ignorePattern = combineRegexes(ignore)
116
- }
117
-
118
- if (excludeGitIgnore) {
119
- const gitIgnoreContents = await getGitignoreContents()
120
- for (let index = 0; index < gitIgnoreContents.length; index++) {
121
- const ignoreItem = gitIgnoreContents[index]
122
- // console.log('ignoreItem', ignoreItem)
123
- if (isGlob(ignoreItem)) {
124
- gitIgnoreGlobs.push(ignoreItem)
125
- } else {
126
- gitIgnoreFiles.push(
127
- ignoreItem.replace(/^\.\//, '') // normalize relative paths
128
- )
129
- }
130
- }
131
- }
132
-
133
- //*
134
- console.log('findPattern', findPattern)
135
- console.log('ignorePattern', ignorePattern)
136
- console.log('gitIgnoreFiles', gitIgnoreFiles)
137
- console.log('gitIgnoreGlobs', gitIgnoreGlobs)
138
- // process.exit(1)
139
- /** */
140
-
141
- await totalist(dirName, (relativePath, abs, stats) => {
142
- const absolutePath = `${dirName}/${relativePath}`
143
- const topLevelDir = relativePath.substring(0, relativePath.indexOf('/'))
144
- //console.log('absolutePath', absolutePath)
145
- // console.log('relativePath', relativePath)
146
- // console.log('topLevelDir', topLevelDir)
147
-
148
- /* Remove hidden files */
149
- if (excludeHidden && IS_HIDDEN_FILE.test(relativePath)) {
150
- return
151
- }
152
-
153
- /* Remove files in git ignore */
154
- if (excludeGitIgnore && gitIgnoreFiles.length) {
155
- if (gitIgnoreFiles.includes(relativePath)) return
156
- if (gitIgnoreFiles.includes(path.basename(relativePath))) return
157
- //* // slow
158
- if (gitIgnoreFiles.some((ignore) => {
159
- // console.log('ignore', ignore)
160
- // return relativePath.indexOf(ignore) > -1
161
- // return relativePath.split('/')[0] === ignore
162
- return topLevelDir === ignore || relativePath === ignore
163
- })) {
164
- return
165
- }
166
- /** */
167
- }
62
+ // Moved to https://www.npmjs.com/package/glob-monster
63
+ // async function getFilePaths(dirName, {
64
+ // patterns = [],
65
+ // ignore = [],
66
+ // excludeGitIgnore = false,
67
+ // excludeHidden = false
68
+ // }) {
168
69
 
169
- /* Remove files in ignore array */
170
- if (ignorePattern && ignorePattern.test(relativePath)) {
171
- // Alt checker https://github.com/axtgr/wildcard-match
172
- return
173
- }
174
-
175
- /* If no patterns supplied add all files */
176
- if (!findPattern) {
177
- filePaths.push(absolutePath)
178
- return
179
- }
180
-
181
- /* If pattern match add file! */
182
- // Alt match https://github.com/micromatch/picomatch
183
- if (findPattern.test(absolutePath)) {
184
- // console.log('Match absolutePath', absolutePath)
185
- filePaths.push(absolutePath)
186
- return
187
- }
188
-
189
- /* If pattern match add file! */
190
- if (findPattern.test(relativePath)) {
191
- // console.log('Match relativePath', relativePath)
192
- filePaths.push(absolutePath)
193
- return
194
- }
195
-
196
- /*
197
- let ignored = false
198
- for (let index = 0; index < ignore.length; index++) {
199
- const pattern = ignore[index]
200
- if (pattern.test(absolutePath)) {
201
- ignored = true
202
- }
203
- }
204
- if (!ignored) {
205
- filePaths.push(absolutePath)
206
- }
207
- /** */
208
- })
209
-
210
- if (gitIgnoreGlobs && gitIgnoreGlobs.length) {
211
- console.log('gitIgnoreGlobs', gitIgnoreGlobs)
212
- let removeFiles = []
213
- for (let index = 0; index < gitIgnoreGlobs.length; index++) {
214
- const glob = gitIgnoreGlobs[index]
215
- const result = globrex(glob) // alt lib https://github.com/axtgr/wildcard-match
216
- // console.log('result', result)
217
- for (let n = 0; n < filePaths.length; n++) {
218
- const file = filePaths[n]
219
- if (result.regex.test(file)) {
220
- removeFiles.push(file)
221
- }
222
- }
223
- }
224
- /* Remove files that match glob pattern */
225
- if (removeFiles.length) {
226
- filePaths = filePaths.filter(function(el) {
227
- return removeFiles.indexOf(el) < 0
228
- })
229
- }
230
- }
231
-
232
- return filePaths
233
- }
70
+ // }
234
71
 
235
72
  function convertToRelativePath(file, cwd) {
236
73
  return file.replace(cwd, '').replace(/^\//, '')
@@ -333,7 +170,6 @@ module.exports = {
333
170
  writeFile,
334
171
  readFile,
335
172
  findUp,
336
- getFilePaths,
337
173
  resolveOutputPath,
338
174
  resolveFlatPath,
339
175
  resolveCommonParent,
@@ -3,7 +3,7 @@ const { test } = require('uvu')
3
3
  const assert = require('uvu/assert')
4
4
  const { glob, globWithGit } = require('smart-glob')
5
5
  const GREEN = '\x1b[32m%s\x1b[0m';
6
- const { findUp, getFilePaths, getGitignoreContents, convertToRelativePath } = require('./fs')
6
+ const { findUp, getGitignoreContents, convertToRelativePath } = require('./fs')
7
7
 
8
8
  const ROOT_DIR = path.resolve(__dirname, '../../')
9
9
 
@@ -25,170 +25,11 @@ test('Finds file from dir', async () => {
25
25
  assert.equal(path.basename(file || ''), 'README.md')
26
26
  })
27
27
 
28
- test('getFilePaths /\.test\.js?$/', async () => {
29
- const files = await getFilePaths(ROOT_DIR, {
30
- patterns: [
31
- /\.test\.js?$/,
32
- ],
33
- ignore: [
34
- /node_modules/,
35
- ],
36
- })
37
- const foundFiles = convertToRelative(files, ROOT_DIR)
38
- console.log('foundFiles', foundFiles)
39
- assert.is(Array.isArray(files), true)
40
- assert.equal(foundFiles, [
41
- 'lib/block-parser-js.test.js',
42
- 'lib/block-parser.test.js',
43
- 'lib/cli.test.js',
44
- 'lib/index.test.js',
45
- 'lib/utils/fs.test.js',
46
- "lib/utils/md/find-frontmatter.test.js",
47
- "lib/utils/md/md.test.js",
48
- "lib/utils/text.test.js",
49
- 'test/errors.test.js',
50
- 'test/transforms.test.js'
51
- ])
52
- })
53
-
54
- test('getFilePaths /\.mdx?$/, /\.test\.js?$/', async () => {
55
- const files = await getFilePaths(ROOT_DIR, {
56
- patterns: [
57
- /fixtures\/md\/(.*)\.mdx?$/,
58
- // /\.js$/,
59
- /\.test\.js?$/,
60
- ],
61
- ignore: [
62
- // /^node_modules\//,
63
- /node_modules/,
64
- // /\.git/,
65
- // /NOTES\.md/
66
- ],
67
- //excludeGitIgnore: true,
68
- excludeHidden: true,
69
- })
70
- const foundFiles = convertToRelative(files, ROOT_DIR)
71
- //console.log('foundFiles', foundFiles)
72
- assert.is(Array.isArray(files), true)
73
- assert.equal(foundFiles, [
74
- 'lib/block-parser-js.test.js',
75
- 'lib/block-parser.test.js',
76
- 'lib/cli.test.js',
77
- 'lib/index.test.js',
78
- 'lib/utils/fs.test.js',
79
- "lib/utils/md/find-frontmatter.test.js",
80
- "lib/utils/md/md.test.js",
81
- "lib/utils/text.test.js",
82
- 'test/errors.test.js',
83
- 'test/fixtures/md/basic.md',
84
- "test/fixtures/md/broken-inline.md",
85
- 'test/fixtures/md/error-missing-transforms-two.md',
86
- 'test/fixtures/md/error-missing-transforms.md',
87
- 'test/fixtures/md/error-no-block-transform-defined.md',
88
- 'test/fixtures/md/error-unbalanced.md',
89
- 'test/fixtures/md/format-inline.md',
90
- 'test/fixtures/md/format-with-wacky-indentation.md',
91
- 'test/fixtures/md/inline-two.md',
92
- 'test/fixtures/md/inline.md',
93
- 'test/fixtures/md/mdx-file.mdx',
94
- 'test/fixtures/md/missing-transform.md',
95
- 'test/fixtures/md/mixed.md',
96
- 'test/fixtures/md/nested/nested.md',
97
- 'test/fixtures/md/no-transforms.md',
98
- 'test/fixtures/md/string.md',
99
- 'test/fixtures/md/syntax-legacy-colon.md',
100
- 'test/fixtures/md/syntax-legacy-query.md',
101
- 'test/fixtures/md/syntax-mixed.md',
102
- 'test/fixtures/md/transform-code.md',
103
- 'test/fixtures/md/transform-custom.md',
104
- 'test/fixtures/md/transform-file.md',
105
- 'test/fixtures/md/transform-remote.md',
106
- 'test/fixtures/md/transform-toc.md',
107
- 'test/fixtures/md/transform-wordCount.md',
108
- 'test/transforms.test.js'
109
- ])
110
- })
111
-
112
- test('getFilePaths glob', async () => {
113
- /*
114
- const x = await glob('**.md')
115
- console.log(x)
116
- process.exit(1)
117
- /** */
118
-
119
- const files = await getFilePaths(ROOT_DIR, {
120
- patterns: [
121
- /\.test\.js?$/,
122
- // /(.*)\.mdx?$/,
123
- 'test/fixtures/md/**.{md,mdx}'
124
- // /^[^\/]+\.md?$/,
125
- // '**.json',
126
- // '**/**.js',
127
- // '**.md',
128
- //'/(.*).md$/',
129
- // '/^test/',
130
- // 'test/**'
131
- ///(.*)\.md/g
132
- ],
133
- ignore: [
134
- // /^node_modules\//,
135
- /node_modules/,
136
- // /(.*)\.js$/,
137
- // /\.git/,
138
- // /NOTES\.md/
139
- ],
140
- excludeGitIgnore: true,
141
- excludeHidden: true,
142
- })
143
- const foundFiles = convertToRelative(files, ROOT_DIR)
144
- console.log('foundFiles', foundFiles)
145
- /*
146
- aggregateReports()
147
- process.exit(1)
148
- /** */
149
- assert.is(Array.isArray(files), true)
150
- assert.equal(foundFiles, [
151
- 'lib/block-parser-js.test.js',
152
- 'lib/block-parser.test.js',
153
- 'lib/cli.test.js',
154
- 'lib/index.test.js',
155
- 'lib/utils/fs.test.js',
156
- "lib/utils/md/find-frontmatter.test.js",
157
- "lib/utils/md/md.test.js",
158
- 'lib/utils/text.test.js',
159
- // 'misc/old-test/main.test.js',
160
- 'test/errors.test.js',
161
- 'test/fixtures/md/basic.md',
162
- "test/fixtures/md/broken-inline.md",
163
- 'test/fixtures/md/error-missing-transforms-two.md',
164
- 'test/fixtures/md/error-missing-transforms.md',
165
- 'test/fixtures/md/error-no-block-transform-defined.md',
166
- 'test/fixtures/md/error-unbalanced.md',
167
- 'test/fixtures/md/format-inline.md',
168
- 'test/fixtures/md/format-with-wacky-indentation.md',
169
- 'test/fixtures/md/inline-two.md',
170
- 'test/fixtures/md/inline.md',
171
- 'test/fixtures/md/mdx-file.mdx',
172
- 'test/fixtures/md/missing-transform.md',
173
- 'test/fixtures/md/mixed.md',
174
- 'test/fixtures/md/no-transforms.md',
175
- 'test/fixtures/md/string.md',
176
- 'test/fixtures/md/syntax-legacy-colon.md',
177
- 'test/fixtures/md/syntax-legacy-query.md',
178
- 'test/fixtures/md/syntax-mixed.md',
179
- 'test/fixtures/md/transform-code.md',
180
- 'test/fixtures/md/transform-custom.md',
181
- 'test/fixtures/md/transform-file.md',
182
- 'test/fixtures/md/transform-remote.md',
183
- 'test/fixtures/md/transform-toc.md',
184
- 'test/fixtures/md/transform-wordCount.md',
185
- 'test/transforms.test.js'
186
- ])
187
- })
188
-
189
28
  test('getGitignoreContents', async () => {
190
29
  const files = await getGitignoreContents()
30
+ /*
191
31
  console.log('files', files)
32
+ /** */
192
33
  assert.is(Array.isArray(files), true)
193
34
  assert.equal(files, [
194
35
  'logs',
@@ -200,6 +41,7 @@ test('getGitignoreContents', async () => {
200
41
  '_out.md',
201
42
  'misc',
202
43
  'misc/**/**.js',
44
+ "__misc",
203
45
  '**/old-test/cool.md',
204
46
  'pids',
205
47
  '*.pid',
@@ -0,0 +1,28 @@
1
+ const crypto = require('crypto')
2
+ const { ReadStream } = require('fs')
3
+
4
+ function hashFile(filename, algorithm = 'sha1') {
5
+ return new Promise((resolve, reject) => {
6
+ // Algorithm depends on availability of OpenSSL on platform
7
+ // Another algorithms: 'sha1', 'md5', 'sha256', 'sha512' ...
8
+ let shasum = crypto.createHash(algorithm)
9
+ try {
10
+ let s = ReadStream(filename)
11
+ s.on('data', (data) => {
12
+ shasum.update(data)
13
+ })
14
+ // making digest
15
+ s.on('end', () => {
16
+ const hash = shasum.digest('hex')
17
+ return resolve(hash)
18
+ })
19
+ } catch (error) {
20
+ console.log(error)
21
+ return reject(new Error('calc fail'))
22
+ }
23
+ })
24
+ }
25
+
26
+ module.exports = {
27
+ hashFile
28
+ }
package/lib/utils/logs.js CHANGED
@@ -2,6 +2,19 @@ const util = require('util')
2
2
  const ansi = require('ansi-styles') // https://github.com/chalk/ansi-styles/blob/main/index.js
3
3
  const process = require('process')
4
4
 
5
+ function convertHrtime(hrtime) {
6
+ const nanoseconds = hrtime;
7
+ const number = Number(nanoseconds);
8
+ const milliseconds = number / 1000000;
9
+ const seconds = number / 1000000000;
10
+
11
+ return {
12
+ seconds: Math.round(seconds * 100) / 100,
13
+ milliseconds,
14
+ nanoseconds,
15
+ };
16
+ }
17
+
5
18
  // via https://github.com/sindresorhus/is-unicode-supported/blob/main/index.js
6
19
  function isUnicodeSupported() {
7
20
  if (process.platform !== 'win32') return process.env.TERM !== 'linux' // Linux console (kernel)
@@ -47,13 +60,13 @@ const ERROR = allowed ? '✖' : '×'
47
60
 
48
61
  const colors = {
49
62
  default: ['white', ''],
50
- success: ['greenBright', `${SUCCESS}${SPACES}`],
63
+ success: ['greenBright', ` ${SUCCESS}${SPACES}`],
51
64
  info: ['cyanBright', `${INFO}${SPACES}`],
52
65
  warning: ['yellowBright', `${WARNING}${SPACES}`],
53
66
  error: ['redBright', `${ERROR}${SPACES}`]
54
67
  }
55
68
 
56
- function log(type, msg, customPrefix, noLog) {
69
+ function log(type, msg, noLog, customPrefix) {
57
70
  const [color, prefix] = colors[type] || colors.default
58
71
  const finalPrefix = typeof customPrefix !== 'undefined' ? customPrefix : prefix
59
72
  const logMsg = `${styles[color].open}${finalPrefix}${msg}${styles[color].close}`
@@ -86,6 +99,7 @@ error('Error: Oh no!')
86
99
  /**/
87
100
 
88
101
  module.exports = {
102
+ convertHrtime,
89
103
  deepLog,
90
104
  success,
91
105
  info,
@@ -61,6 +61,7 @@ const syntaxMap = {
61
61
  html: html,
62
62
  // /* x */
63
63
  js: js,
64
+ json: js,
64
65
  // {/* x */}
65
66
  jsx: jsx,
66
67
  mdx: jsx,
package/lib/utils/text.js CHANGED
@@ -177,7 +177,7 @@ function stripComments(str, syntax = 'md') {
177
177
  const OR = (syntaxData.singleLine) ? `|\\s?[ \\t]*${syntaxData.singleLine}` : ''
178
178
  const CONTENT = syntaxData.content || '[\\s\\S]*?'
179
179
  const pattern = new RegExp(`\\s?[ \\t]*${openPattern}(${CONTENT})?${closePattern}${OR}`, 'gim')
180
- console.log('pattern', pattern)
180
+ // console.log('pattern', pattern)
181
181
  return str.replace(pattern, '')
182
182
  // https://regex101.com/r/XKHU18/5
183
183
  return str.replace(/\s?[ \t]*\/\*[\s\S]*?\*\/|\s?[ \t]*\/\/.*$|\/\*{1,}[\n\*]*(\s?[\s\S]*?)?\*+\//gm, '')
@@ -0,0 +1,131 @@
1
+
2
+ // https://github.com/marcelklehr/toposort/tree/master
3
+ /**
4
+ * Topological sorting function
5
+ *
6
+ * @param {Array} edges
7
+ * @returns {Array}
8
+ */
9
+
10
+ module.exports = function(edges) {
11
+ return toposort(uniqueNodes(edges), edges)
12
+ }
13
+
14
+ module.exports.array = toposort
15
+
16
+ function toposort(nodes, edges) {
17
+ var cursor = nodes.length
18
+ , sorted = new Array(cursor)
19
+ , visited = {}
20
+ , i = cursor
21
+ // Better data structures make algorithm much faster.
22
+ , outgoingEdges = makeOutgoingEdges(edges)
23
+ , nodesHash = makeNodesHash(nodes)
24
+
25
+ // check for unknown nodes
26
+ edges.forEach(function(edge) {
27
+ if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
28
+ throw new Error('Unknown node. There is an unknown node in the supplied edges.')
29
+ }
30
+ })
31
+
32
+ while (i--) {
33
+ if (!visited[i]) visit(nodes[i], i, new Set())
34
+ }
35
+
36
+ return sorted
37
+
38
+ function visit(node, i, predecessors) {
39
+ if(predecessors.has(node)) {
40
+ var nodeRep
41
+ try {
42
+ nodeRep = ", node was:" + JSON.stringify(node)
43
+ } catch(e) {
44
+ nodeRep = ""
45
+ }
46
+ throw new Error('Cyclic dependency' + nodeRep)
47
+ }
48
+
49
+ if (!nodesHash.has(node)) {
50
+ throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
51
+ }
52
+
53
+ if (visited[i]) return;
54
+ visited[i] = true
55
+
56
+ var outgoing = outgoingEdges.get(node) || new Set()
57
+ outgoing = Array.from(outgoing)
58
+
59
+ if (i = outgoing.length) {
60
+ predecessors.add(node)
61
+ do {
62
+ var child = outgoing[--i]
63
+ visit(child, nodesHash.get(child), predecessors)
64
+ } while (i)
65
+ predecessors.delete(node)
66
+ }
67
+
68
+ sorted[--cursor] = node
69
+ }
70
+ }
71
+
72
+ function uniqueNodes(arr){
73
+ var res = new Set()
74
+ for (var i = 0, len = arr.length; i < len; i++) {
75
+ var edge = arr[i]
76
+ res.add(edge[0])
77
+ res.add(edge[1])
78
+ }
79
+ return Array.from(res)
80
+ }
81
+
82
+ function makeOutgoingEdges(arr){
83
+ var edges = new Map()
84
+ for (var i = 0, len = arr.length; i < len; i++) {
85
+ var edge = arr[i]
86
+ if (!edges.has(edge[0])) edges.set(edge[0], new Set())
87
+ if (!edges.has(edge[1])) edges.set(edge[1], new Set())
88
+ edges.get(edge[0]).add(edge[1])
89
+ }
90
+ return edges
91
+ }
92
+
93
+ function makeNodesHash(arr){
94
+ var res = new Map()
95
+ for (var i = 0, len = arr.length; i < len; i++) {
96
+ res.set(arr[i], i)
97
+ }
98
+ return res
99
+ }
100
+
101
+
102
+ function topoSortOld(arr) {
103
+ var map = {} // Creates key value pair of name and object
104
+ var result = [] // the result array
105
+ var visited = {} // takes a note of the traversed dependency
106
+
107
+ arr.forEach(function(obj) { // build the map
108
+ map[obj.name] = obj
109
+ })
110
+
111
+ arr.forEach(function(obj) { // Traverse array
112
+ if (!visited[obj.name]) { // check for visited object
113
+ sort_util(obj)
114
+ }
115
+ })
116
+
117
+ // On visiting object, check for its dependencies and visit them recursively
118
+ function sort_util(obj) {
119
+ if (!obj) return;
120
+ // console.log('obj', obj)
121
+ visited[obj.name] = true
122
+ obj.dependencies.forEach(function(dep){
123
+ if (!visited[dep]) {
124
+ sort_util(map[dep])
125
+ }
126
+ })
127
+ result.push(obj)
128
+ }
129
+
130
+ console.log(result);
131
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Automatically update markdown files with content from external sources",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -44,6 +44,7 @@
44
44
  "url": "https://github.com/DavidWells/markdown-magic"
45
45
  },
46
46
  "dependencies": {
47
+ "@davidwells/md-utils": "^0.0.40",
47
48
  "@technote-space/doctoc": "2.4.7",
48
49
  "globrex": "^0.1.2",
49
50
  "gray-matter": "^4.0.3",
@@ -52,14 +53,14 @@
52
53
  "is-valid-path": "^0.1.1",
53
54
  "micro-mdx-parser": "^1.1.0",
54
55
  "mri": "^1.2.0",
55
- "oparser": "^2.1.1",
56
+ "oparser": "^3.0.13",
56
57
  "smart-glob": "^1.0.2",
57
58
  "sync-request": "^6.1.0"
58
59
  },
59
60
  "devDependencies": {
60
61
  "ansi-styles": "^4.2.1",
61
62
  "concordance": "^5.0.1",
62
- "doxxx": "^2.0.1",
63
+ "doxxx": "^2.0.7",
63
64
  "rimraf": "^3.0.2",
64
65
  "safe-chalk": "^1.0.0",
65
66
  "typescript": "^5.0.2",
@@ -1,20 +0,0 @@
1
- const IMAGE_POSTFIX_REGEX = /\.(png|apng|jpe?g|gif|webp|svg|avif)$/
2
- const RELATIVE_LINK_REGEX = /^(?!(?:(?:https?|ftp):\/\/|data:))((?:\.\.?\/)*)*([\w\d\-_./?=#%:+&]+)/
3
-
4
- function onlyUnique(value, index, self) {
5
- return self.indexOf(value) === index
6
- }
7
-
8
- function isImage(link = '') {
9
- return link.match(IMAGE_POSTFIX_REGEX)
10
- }
11
-
12
- function isRelative(filepath = '') {
13
- return RELATIVE_LINK_REGEX.test(filepath)
14
- }
15
-
16
- module.exports = {
17
- onlyUnique,
18
- isImage,
19
- isRelative
20
- }