markdown-magic 3.3.0 → 3.3.2

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.
@@ -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
  }
@@ -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
@@ -77,7 +77,7 @@ function getTextBetweenLines(content, startLine, endLine) {
77
77
  if (startDefined && !endDefined) {
78
78
  return lines.slice(startLine - 1, startLine).join('')
79
79
  }
80
- if ((startLine) && (endLine) && parseInt(startLine, 10) <= parseInt(endLine, 10)) {
80
+ if (startLine && endLine && parseInt(startLine, 10) <= parseInt(endLine, 10)) {
81
81
  return lines.slice(startLine - 1, endLine).join('\n')
82
82
  }
83
83
  }
@@ -119,7 +119,11 @@ function indentString(string, count = 1, options = {}) {
119
119
  includeEmptyLines = false
120
120
  } = options;
121
121
  if (count === 0) return string
122
- const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm
122
+ // const regex = includeEmptyLines ? /^/gm : /^(?!\s*$)/gm
123
+ const indentPattern = indent.repeat(count)
124
+ const regex = includeEmptyLines
125
+ ? new RegExp(`^(?!${indentPattern})`, 'gm')
126
+ : new RegExp(`^(?!${indentPattern})(?!\\s*$)`, 'gm')
123
127
  return string.replace(regex, indent.repeat(count))
124
128
  }
125
129
 
@@ -133,14 +137,14 @@ function dedentString(str) {
133
137
  str = str.replace(/^[ \t]*\r?\n/, ''); // remove leading blank line
134
138
  var indent = /^[ \t]+/m.exec(str); // detected indent
135
139
  if (indent) str = str.replace(new RegExp('^' + indent[0], 'gm'), ''); // remove indent
136
- return str.replace(/(\r?\n)[ \t]+$/, '$1'); // remove trailling blank line
140
+ return str.replace(/(\r?\n)[ \t]+$/, '$1'); // remove trailing blank line
137
141
  }
138
142
 
139
143
  /**
140
144
  * Strip out comment blocks
141
145
  * @param {string} str
142
146
  * @param {'md' | 'js'} syntax
143
- * @returns {string} clean commentless string
147
+ * @returns {string} clean comment-less string
144
148
  */
145
149
  function stripCommentBlockOld(str, syntax = 'md') {
146
150
  const [ openPattern, closePattern ] = syntaxMap[syntax].pattern
@@ -177,7 +181,7 @@ function stripCommentBlockOld(str, syntax = 'md') {
177
181
  * Strip out comment blocks
178
182
  * @param {string} str
179
183
  * @param {typeof import('../types')['syntaxType']} syntax
180
- * @returns {string} clean commentless string
184
+ * @returns {string} clean comment-less string
181
185
  */
182
186
  function stripComments(str, syntax = 'md') {
183
187
  const syntaxData = syntaxMap[syntax]
@@ -204,6 +208,7 @@ function stripOutMultilineJsComments(str = '') {
204
208
  })
205
209
  }
206
210
 
211
+
207
212
  // @TODO export as util to import into CODE
208
213
  function stripHTMLComments(block, opts) {
209
214
  const options = opts || {}
@@ -231,8 +236,8 @@ function stripHTMLComments(block, opts) {
231
236
  console.log('trailingNewLine', trailingNewLine)
232
237
  /** */
233
238
  const newLineCount = (trailingNewLine || '').length
234
- const trailing = (!trailingText && newLineCount > 1) ? `${trailingNewLine || ''}` : ''
235
- const leading = (leadingSpace) ? leadingSpace.slice(1) : ''
239
+ const trailing = (!trailingText && !leadingText && newLineCount >= 1) ? `${trailingNewLine || ''}` : ''
240
+ let leading = (leadingSpace) ? leadingSpace : ''
236
241
 
237
242
  if (options.multilineOnly && comment.indexOf('\n') === -1) {
238
243
  continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
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.13",
56
+ "oparser": "^3.0.22",
58
57
  "smart-glob": "^1.0.2",
59
58
  "sync-request": "^6.1.0"
60
59
  },