markdown-magic 3.0.4 → 3.0.6
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 +5 -6
- package/cli.js +1 -0
- package/lib/process-contents.js +2 -0
- package/lib/process-file.js +2 -1
- package/lib/transforms/code.js +7 -3
- package/lib/transforms/index.js +5 -5
- package/package.json +1 -1
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
package/lib/process-contents.js
CHANGED
|
@@ -230,6 +230,8 @@ async function processContents(text, config) {
|
|
|
230
230
|
/* Strip block comments from output files */
|
|
231
231
|
const stripComments = isNewPath && removeComments
|
|
232
232
|
|
|
233
|
+
// console.log('srcPath', srcPath)
|
|
234
|
+
// console.log('outputPath', outputPath)
|
|
233
235
|
const result = {
|
|
234
236
|
/* Has markdown content changed? */
|
|
235
237
|
isChanged: text !== updatedContents,
|
package/lib/process-file.js
CHANGED
|
@@ -49,7 +49,8 @@ async function processFile(opts = {}) {
|
|
|
49
49
|
return result
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/* If it's changed or its a new file to write */
|
|
53
|
+
if (result.isChanged || result.isNewPath) {
|
|
53
54
|
let cleanContents = result.updatedContents
|
|
54
55
|
if (result.stripComments && patterns.openPattern && patterns.closePattern) {
|
|
55
56
|
cleanContents = result.updatedContents.replace(patterns.openPattern, '').replace(patterns.closePattern, '')
|
package/lib/transforms/code.js
CHANGED
|
@@ -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
|
|
100
|
-
const
|
|
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
|
|
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
|
package/lib/transforms/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const transforms = {
|
|
|
18
18
|
*
|
|
19
19
|
* **Example:**
|
|
20
20
|
* ```md
|
|
21
|
-
* <!-- doc-gen
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
* ```
|