markdown-magic 3.0.5 → 3.0.7

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 CHANGED
@@ -273,7 +273,7 @@ Generate table of contents from markdown file
273
273
 
274
274
  **Example:**
275
275
  ```md
276
- <!-- doc-gen (TOC) -->
276
+ <!-- doc-gen TOC -->
277
277
  toc will be generated here
278
278
  <!-- end-doc-gen -->
279
279
  ```
@@ -299,13 +299,13 @@ Get code from file or URL and put in markdown
299
299
 
300
300
  **Example:**
301
301
  ```md
302
- <!-- doc-gen (CODE:src=./relative/path/to/code.js) -->
302
+ <!-- doc-gen CODE src="./relative/path/to/code.js" -->
303
303
  This content will be dynamically replaced with code from the file
304
304
  <!-- end-doc-gen -->
305
305
  ```
306
306
 
307
307
  ```md
308
- <!-- doc-gen (CODE:src=./relative/path/to/code.js&lines=22-44) -->
308
+ <!-- doc-gen CODE src="./relative/path/to/code.js" lines=22-44 -->
309
309
  This content will be dynamically replaced with code from the file lines 22 through 44
310
310
  <!-- end-doc-gen -->
311
311
  ```
@@ -328,7 +328,7 @@ Get local file contents.
328
328
 
329
329
  **Example:**
330
330
  ```md
331
- <!-- doc-gen (FILE:src=./path/to/file) -->
331
+ <!-- doc-gen FILE src=./path/to/file -->
332
332
  This content will be dynamically replaced from the local file
333
333
  <!-- end-doc-gen -->
334
334
  ```
@@ -351,7 +351,7 @@ Get any remote Data and put in markdown
351
351
 
352
352
  **Example:**
353
353
  ```md
354
- <!-- doc-gen (REMOTE:url=http://url-to-raw-md-file.md) -->
354
+ <!-- doc-gen REMOTE url=http://url-to-raw-md-file.md -->
355
355
  This content will be dynamically replaced from the remote url
356
356
  <!-- end-doc-gen -->
357
357
  ```
@@ -479,7 +479,6 @@ const config = {
479
479
  }).forEach((tag) => {
480
480
  const optionalText = tag.isOptional ? ' (optional) ' : ' '
481
481
  const defaultValueText = (typeof tag.defaultValue !== 'undefined') ? ` Default: \`${tag.defaultValue}\` ` : ' '
482
- console.log('tag', tag)
483
482
  table += `| \`${tag.name}\`${optionalText}`
484
483
  table += `| \`${tag.type.replace('|', 'or')}\` `
485
484
  table += `| ${tag.description.replace(/\.\s?$/, '')}.${defaultValueText}|\n`
package/cli.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  const mri = require('mri')
2
3
  const { runCli } = require('./lib/cli')
3
4
  const argv = process.argv.slice(2)
@@ -150,6 +150,7 @@ async function processContents(text, config) {
150
150
  // console.log('config', config)
151
151
 
152
152
  // console.log('returnedContent', returnedContent)
153
+ // process.exit(1)
153
154
 
154
155
  if (returnedContent) {
155
156
  tempContent = returnedContent
@@ -166,6 +167,10 @@ async function processContents(text, config) {
166
167
  }
167
168
  }
168
169
  }, md, afterMiddleware)
170
+ /*
171
+ console.log('afterContent', afterContent)
172
+ process.exit(1)
173
+ /** */
169
174
 
170
175
  if (debug) {
171
176
  console.log('afterContent', afterContent)
@@ -181,7 +186,11 @@ async function processContents(text, config) {
181
186
  // console.log('formattedNewContent', formattedNewContent)
182
187
  /* Remove any conflicting imported comments */
183
188
  const fix = removeConflictingComments(formattedNewContent, COMMENT_OPEN_REGEX, COMMENT_CLOSE_REGEX)
184
- // console.log('fix', fix)
189
+ /*
190
+ console.log('fix')
191
+ deepLog(fix)
192
+ process.exit(1)
193
+ /** */
185
194
  if (options.removeComments) {
186
195
  // console.log('removeComments', options.removeComments)
187
196
  }
@@ -194,10 +203,19 @@ async function processContents(text, config) {
194
203
  const indent = indentString(fix, preserveIndent)
195
204
  const newCont = `${openTag}${indent}${closeTag}`
196
205
  /* Replace original contents */
197
- const newContents = md.replace(block.value, newCont)
206
+ // Must use replacer function because strings get coearced to regex or something
207
+ const newContents = md.replace(block.value, () => newCont)
208
+ /*
209
+ deepLog(newContents)
210
+ process.exit(1)
211
+ /** */
198
212
  return Promise.resolve(newContents)
199
213
  }, Promise.resolve(text))
200
214
 
215
+ // console.log('updatedContents')
216
+ // deepLog(updatedContents)
217
+ // process.exit(1)
218
+
201
219
  // if (debug) {
202
220
  // console.log('Output Markdown')
203
221
  // console.log(updatedContents)
@@ -245,8 +263,11 @@ async function processContents(text, config) {
245
263
  originalContents: text,
246
264
  updatedContents,
247
265
  }
248
- // console.log('result')
249
- // deepLog(result)
266
+ /*
267
+ console.log('result')
268
+ deepLog(result)
269
+ process.exit(1)
270
+ /** */
250
271
  return result
251
272
  }
252
273
 
@@ -96,8 +96,11 @@ module.exports = function CODE(api) {
96
96
  /* Check for Id */
97
97
  if (id) {
98
98
  const lines = code.split("\n")
99
- const startLine = lines.findIndex(line => line.includes(`CODE_SECTION:${id}:START`)) ?? 0
100
- const endLine = lines.findIndex(line => line.includes(`CODE_SECTION:${id}:END`)) ?? lines.length - 1
99
+ const startLineIndex = lines.findIndex(line => line.includes(`CODE_SECTION:${id}:START`));
100
+ const startLine = startLineIndex !== -1 ? startLineIndex : 0;
101
+
102
+ const endLineIndex = lines.findIndex(line => line.includes(`CODE_SECTION:${id}:END`));
103
+ const endLine = endLineIndex !== -1 ? endLineIndex : lines.length - 1;
101
104
  // console.log('startLine', startLine)
102
105
  // console.log('endLineendLine', endLine)
103
106
  if (startLine === -1 && endLine === -1) {
@@ -106,7 +109,8 @@ module.exports = function CODE(api) {
106
109
 
107
110
  const selectedLines = lines.slice(startLine + 1, endLine)
108
111
 
109
- const trimBy = selectedLines[0]?.match(/^(\s*)/)?.[1]?.length
112
+ const firstMatch = selectedLines[0] && selectedLines[0].match(/^(\s*)/);
113
+ const trimBy = firstMatch && firstMatch[1] ? firstMatch[1].length : 0;
110
114
  const newValue = `${selectedLines.map(line => line.substring(trimBy).replace(/^\/\/ CODE_SECTION:INCLUDE /g, "")).join("\n")}`
111
115
  // console.log('newValue', newValue)
112
116
  code = newValue
@@ -18,7 +18,7 @@ const transforms = {
18
18
  *
19
19
  * **Example:**
20
20
  * ```md
21
- * <!-- doc-gen (TOC) -->
21
+ * <!-- doc-gen TOC -->
22
22
  * toc will be generated here
23
23
  * <!-- end-doc-gen -->
24
24
  * ```
@@ -44,13 +44,13 @@ const transforms = {
44
44
  *
45
45
  * **Example:**
46
46
  * ```md
47
- * <!-- doc-gen (CODE:src=./relative/path/to/code.js) -->
47
+ * <!-- doc-gen CODE src="./relative/path/to/code.js" -->
48
48
  * This content will be dynamically replaced with code from the file
49
49
  * <!-- end-doc-gen -->
50
50
  * ```
51
51
  *
52
52
  * ```md
53
- * <!-- doc-gen (CODE:src=./relative/path/to/code.js&lines=22-44) -->
53
+ * <!-- doc-gen CODE src="./relative/path/to/code.js" lines=22-44 -->
54
54
  * This content will be dynamically replaced with code from the file lines 22 through 44
55
55
  * <!-- end-doc-gen -->
56
56
  * ```
@@ -73,7 +73,7 @@ const transforms = {
73
73
  *
74
74
  * **Example:**
75
75
  * ```md
76
- * <!-- doc-gen (FILE:src=./path/to/file) -->
76
+ * <!-- doc-gen FILE src=./path/to/file -->
77
77
  * This content will be dynamically replaced from the local file
78
78
  * <!-- end-doc-gen -->
79
79
  * ```
@@ -96,7 +96,7 @@ const transforms = {
96
96
  *
97
97
  * **Example:**
98
98
  * ```md
99
- * <!-- doc-gen (REMOTE:url=http://url-to-raw-md-file.md) -->
99
+ * <!-- doc-gen REMOTE url=http://url-to-raw-md-file.md -->
100
100
  * This content will be dynamically replaced from the remote url
101
101
  * <!-- end-doc-gen -->
102
102
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Automatically update markdown files with content from external sources",
5
5
  "main": "lib/index.js",
6
6
  "bin": {