markdown-magic 3.2.0 → 3.3.0

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.
@@ -3,7 +3,7 @@ const path = require('path')
3
3
  const { remoteRequest } = require('../../utils/remoteRequest')
4
4
  const { isLocalPath } = require('../../utils/fs')
5
5
  const { deepLog } = require('../../utils/logs')
6
- const { getLineCount, getTextBetweenLines, stripOutMultiLineDoubleDashComments } = require('../../utils/text')
6
+ const { getLineCount, getTextBetweenLines, stripMultiLineDoubleDashComments, stripHTMLComments } = require('../../utils/text')
7
7
  const { resolveGithubContents, isGithubLink } = require('./resolve-github-file')
8
8
 
9
9
  const GITHUB_LINK = /https:\/\/github\.com\/([^/\s]*)\/([^/\s]*)\/blob\//
@@ -133,6 +133,9 @@ module.exports = async function CODE(api) {
133
133
  }
134
134
  }
135
135
 
136
+ /* Ensure lowercase on syntax */
137
+ syntax = (syntax || '').toLowerCase()
138
+
136
139
  /* Check for Id */
137
140
  if (id) {
138
141
  const lines = code.split("\n")
@@ -163,9 +166,13 @@ module.exports = async function CODE(api) {
163
166
  if (options.header) {
164
167
  header = `\n${options.header}`
165
168
  }
166
-
169
+
167
170
  if (options.trimDeadCode) {
168
- code = stripOutMultiLineDoubleDashComments(code)
171
+ if (syntax === 'js' || syntax === 'ts' || syntax === 'javascript' || syntax === 'typescript') {
172
+ code = stripMultiLineDoubleDashComments(code)
173
+ } else if (syntax === 'html') {
174
+ code = stripHTMLComments(code, { multilineOnly: true })
175
+ }
169
176
  }
170
177
 
171
178
  return `\`\`\`${syntax}${header}
package/lib/utils/text.js CHANGED
@@ -193,7 +193,7 @@ function stripComments(str, syntax = 'md') {
193
193
 
194
194
 
195
195
  // https://regex101.com/r/nCnt2J/1
196
- function stripOutMultiLineDoubleDashComments(str = '') {
196
+ function stripMultiLineDoubleDashComments(str = '') {
197
197
  return str.replace(/(?:\n\s*\/\/.*){2,}/g, '')
198
198
  }
199
199
 
@@ -205,7 +205,8 @@ function stripOutMultilineJsComments(str = '') {
205
205
  }
206
206
 
207
207
  // @TODO export as util to import into CODE
208
- function stripAllHTMLComments(block) {
208
+ function stripHTMLComments(block, opts) {
209
+ const options = opts || {}
209
210
  // ([^\s]*)?([ \t]*)?(\/\*{1,}[\n\*]*(\s?[\s\S]*?)?\*\/)([^\s<]*)?(\n{1,2})?
210
211
  // https://regex101.com/r/WSioZ7/1
211
212
  const pattern = new RegExp(`([^\\s]*)?([ \\t]*)?(<!-{2,}(\\s?[\\s\\S]*?)?-{2,}>)([^\\s<]*)?(\n{1,2})?`, 'gi')
@@ -232,6 +233,10 @@ function stripAllHTMLComments(block) {
232
233
  const newLineCount = (trailingNewLine || '').length
233
234
  const trailing = (!trailingText && newLineCount > 1) ? `${trailingNewLine || ''}` : ''
234
235
  const leading = (leadingSpace) ? leadingSpace.slice(1) : ''
236
+
237
+ if (options.multilineOnly && comment.indexOf('\n') === -1) {
238
+ continue
239
+ }
235
240
  remove.push(`${leading}${comment}${trailing}`)
236
241
  }
237
242
  return remove.reduce((acc, curr) => {
@@ -341,7 +346,8 @@ module.exports = {
341
346
  dedentString,
342
347
  stripComments,
343
348
  convertCommentSyntax,
344
- stripOutMultiLineDoubleDashComments,
349
+ stripMultiLineDoubleDashComments,
350
+ stripHTMLComments,
345
351
  // stripCommentBlockJS,
346
352
  trimString,
347
353
  // future https://github.com/junfengliang/autowrap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-magic",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Automatically update markdown files with content from external sources",
5
5
  "main": "lib/index.js",
6
6
  "bin": {