markdown-magic 3.3.0 → 3.3.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 +7 -7
- package/cli.js +4 -3
- package/lib/argparse/README.md +11 -0
- package/lib/argparse/argparse.js +317 -0
- package/lib/argparse/argparse.test.js +370 -0
- package/lib/argparse/index.js +5 -0
- package/lib/argparse/splitOutsideQuotes.js +78 -0
- package/lib/argparse/splitOutsideQuotes.test.js +100 -0
- package/lib/block-parser.js +19 -4
- package/lib/cli.js +80 -192
- package/lib/cli.test.js +0 -387
- package/lib/globparse.js +170 -0
- package/lib/globparse.test.js +412 -0
- package/lib/index.js +51 -7
- package/lib/process-contents.js +14 -7
- package/lib/transforms/code/index.js +48 -5
- package/lib/transforms/file.js +4 -1
- package/lib/transforms/remote.js +1 -0
- package/lib/utils/remoteRequest.js +4 -0
- package/lib/utils/text.js +13 -7
- package/package.json +2 -3
package/lib/transforms/file.js
CHANGED
|
@@ -5,7 +5,6 @@ const isLocalPath = require('is-local-path')
|
|
|
5
5
|
module.exports = function FILE(api) {
|
|
6
6
|
/*
|
|
7
7
|
console.log('FILE API', api)
|
|
8
|
-
|
|
9
8
|
/** */
|
|
10
9
|
const { options, srcPath } = api
|
|
11
10
|
if (!options.src) {
|
|
@@ -19,6 +18,10 @@ module.exports = function FILE(api) {
|
|
|
19
18
|
// console.log('READFILE', resolvedFilePath)
|
|
20
19
|
fileContents = fs.readFileSync(resolvedFilePath, 'utf8')
|
|
21
20
|
} catch (e) {
|
|
21
|
+
// if demo path. Todo probably remove
|
|
22
|
+
if (options.src === './path/to/file') {
|
|
23
|
+
return api.content
|
|
24
|
+
}
|
|
22
25
|
console.log(`FILE NOT FOUND ${resolvedFilePath}`)
|
|
23
26
|
throw e
|
|
24
27
|
}
|
package/lib/transforms/remote.js
CHANGED
|
@@ -4,6 +4,7 @@ module.exports = async function REMOTE(api) {
|
|
|
4
4
|
// console.log('REMOTE api', api)
|
|
5
5
|
const { options, content, settings } = api
|
|
6
6
|
const { regex } = settings
|
|
7
|
+
|
|
7
8
|
// console.log('MAKE REMOTE REQUEST')
|
|
8
9
|
const remoteContent = await remoteRequest(options.url, settings, api.srcPath)
|
|
9
10
|
if (!remoteContent) {
|
|
@@ -26,6 +26,10 @@ function remoteRequestSync(url, settings = {}, srcPath) {
|
|
|
26
26
|
async function remoteRequest(url, settings = {}, srcPath) {
|
|
27
27
|
let body
|
|
28
28
|
const finalUrl = formatUrl(url)
|
|
29
|
+
// ignore demo url todo remove one day
|
|
30
|
+
if (finalUrl === 'http://url-to-raw-md-file.md') {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
29
33
|
try {
|
|
30
34
|
const res = await fetch(finalUrl)
|
|
31
35
|
body = await res.text()
|
package/lib/utils/text.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { match } = require('uvu/assert')
|
|
1
2
|
const { syntaxMap } = require('./syntax')
|
|
2
3
|
|
|
3
4
|
function getLines(str = '') {
|
|
@@ -77,7 +78,7 @@ function getTextBetweenLines(content, startLine, endLine) {
|
|
|
77
78
|
if (startDefined && !endDefined) {
|
|
78
79
|
return lines.slice(startLine - 1, startLine).join('')
|
|
79
80
|
}
|
|
80
|
-
if (
|
|
81
|
+
if (startLine && endLine && parseInt(startLine, 10) <= parseInt(endLine, 10)) {
|
|
81
82
|
return lines.slice(startLine - 1, endLine).join('\n')
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -119,7 +120,11 @@ function indentString(string, count = 1, options = {}) {
|
|
|
119
120
|
includeEmptyLines = false
|
|
120
121
|
} = options;
|
|
121
122
|
if (count === 0) return string
|
|
122
|
-
const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm
|
|
123
|
+
// const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm
|
|
124
|
+
const indentPattern = indent.repeat(count)
|
|
125
|
+
const regex = includeEmptyLines
|
|
126
|
+
? new RegExp(`^(?!${indentPattern})`, 'gm')
|
|
127
|
+
: new RegExp(`^(?!${indentPattern})(?!\\s*$)`, 'gm')
|
|
123
128
|
return string.replace(regex, indent.repeat(count))
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -133,14 +138,14 @@ function dedentString(str) {
|
|
|
133
138
|
str = str.replace(/^[ \t]*\r?\n/, ''); // remove leading blank line
|
|
134
139
|
var indent = /^[ \t]+/m.exec(str); // detected indent
|
|
135
140
|
if (indent) str = str.replace(new RegExp('^' + indent[0], 'gm'), ''); // remove indent
|
|
136
|
-
return str.replace(/(\r?\n)[ \t]+$/, '$1'); // remove
|
|
141
|
+
return str.replace(/(\r?\n)[ \t]+$/, '$1'); // remove trailing blank line
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
/**
|
|
140
145
|
* Strip out comment blocks
|
|
141
146
|
* @param {string} str
|
|
142
147
|
* @param {'md' | 'js'} syntax
|
|
143
|
-
* @returns {string} clean
|
|
148
|
+
* @returns {string} clean comment-less string
|
|
144
149
|
*/
|
|
145
150
|
function stripCommentBlockOld(str, syntax = 'md') {
|
|
146
151
|
const [ openPattern, closePattern ] = syntaxMap[syntax].pattern
|
|
@@ -177,7 +182,7 @@ function stripCommentBlockOld(str, syntax = 'md') {
|
|
|
177
182
|
* Strip out comment blocks
|
|
178
183
|
* @param {string} str
|
|
179
184
|
* @param {typeof import('../types')['syntaxType']} syntax
|
|
180
|
-
* @returns {string} clean
|
|
185
|
+
* @returns {string} clean comment-less string
|
|
181
186
|
*/
|
|
182
187
|
function stripComments(str, syntax = 'md') {
|
|
183
188
|
const syntaxData = syntaxMap[syntax]
|
|
@@ -204,6 +209,7 @@ function stripOutMultilineJsComments(str = '') {
|
|
|
204
209
|
})
|
|
205
210
|
}
|
|
206
211
|
|
|
212
|
+
|
|
207
213
|
// @TODO export as util to import into CODE
|
|
208
214
|
function stripHTMLComments(block, opts) {
|
|
209
215
|
const options = opts || {}
|
|
@@ -231,8 +237,8 @@ function stripHTMLComments(block, opts) {
|
|
|
231
237
|
console.log('trailingNewLine', trailingNewLine)
|
|
232
238
|
/** */
|
|
233
239
|
const newLineCount = (trailingNewLine || '').length
|
|
234
|
-
const trailing = (!trailingText && newLineCount
|
|
235
|
-
|
|
240
|
+
const trailing = (!trailingText && !leadingText && newLineCount >= 1) ? `${trailingNewLine || ''}` : ''
|
|
241
|
+
let leading = (leadingSpace) ? leadingSpace : ''
|
|
236
242
|
|
|
237
243
|
if (options.multilineOnly && comment.indexOf('\n') === -1) {
|
|
238
244
|
continue
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-magic",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Automatically update markdown files with content from external sources",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"test": "npm run test:lib && npm run test:test && echo 'tests done'",
|
|
22
22
|
"test:lib": "uvu lib '.test.([mc]js|[jt]sx?)$'",
|
|
23
23
|
"test:test": "uvu test '.test.([mc]js|[jt]sx?)$'",
|
|
24
|
-
"test:options": "uvu lib 'options-parser.test.([mc]js|[jt]sx?)$'",
|
|
25
24
|
"test:block": "uvu lib 'block-parser.test.([mc]js|[jt]sx?)$'",
|
|
26
25
|
"test:cli": "uvu lib 'cli.test.([mc]js|[jt]sx?)$'",
|
|
27
26
|
"test:md": "uvu lib 'md.test.([mc]js|[jt]sx?)$'",
|
|
@@ -54,7 +53,7 @@
|
|
|
54
53
|
"micro-mdx-parser": "^1.1.0",
|
|
55
54
|
"mri": "^1.2.0",
|
|
56
55
|
"node-fetch": "^2.7.0",
|
|
57
|
-
"oparser": "^3.0.
|
|
56
|
+
"oparser": "^3.0.22",
|
|
58
57
|
"smart-glob": "^1.0.2",
|
|
59
58
|
"sync-request": "^6.1.0"
|
|
60
59
|
},
|