comment-block-transformer 0.5.7 → 0.6.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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.6.1](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.6.0...comment-block-transformer@0.6.1) (2026-01-19)
7
+
8
+ **Note:** Version bump only for package comment-block-transformer
9
+
10
+
11
+
12
+
13
+
14
+ # [0.6.0](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.5.7...comment-block-transformer@0.6.0) (2026-01-19)
15
+
16
+
17
+ ### Features
18
+
19
+ * **block-transformer:** add forceRemoveComments option ([7503338](https://github.com/DavidWells/markdown-magic/commit/7503338ee182a935b04e7162276fd3df072b59a9))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.5.7](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.5.6...comment-block-transformer@0.5.7) (2026-01-19)
7
26
 
8
27
  **Note:** Version bump only for package comment-block-transformer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-block-transformer",
3
- "version": "0.5.7",
3
+ "version": "0.6.1",
4
4
  "description": "Transform markdown blocks based on configured transforms",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "2bef6eae03b732f55673524c1e928ecff8b2c86c"
28
+ "gitHead": "e149a2e69992f108553ed3f84dc5cbd1db361987"
29
29
  }
package/src/index.js CHANGED
@@ -66,6 +66,7 @@ const CLOSE_WORD = '/block'
66
66
  * @property {Array<Middleware>} [beforeMiddleware=[]] - Middleware functions change inner block content before transforms.
67
67
  * @property {Array<Middleware>} [afterMiddleware=[]] - Middleware functions change inner block content after transforms.
68
68
  * @property {boolean} [removeComments=false] - Remove comments from the processed contents.
69
+ * @property {boolean} [forceRemoveComments=false] - Force remove comments even when srcPath === outputPath, strips comments directly in updatedContents.
69
70
  * @property {string} [srcPath] - The source path.
70
71
  * @property {string} [outputPath] - The output path.
71
72
  * @property {import('comment-block-parser').CustomPatterns} [customPatterns] - Custom regex patterns for open and close tags.
@@ -103,6 +104,7 @@ async function blockTransformer(inputText, config) {
103
104
  beforeMiddleware = [],
104
105
  afterMiddleware = [],
105
106
  removeComments = false,
107
+ forceRemoveComments = false,
106
108
  customPatterns
107
109
  } = opts
108
110
  // Don't default close - let undefined pass through to enable pattern mode in block-parser
@@ -285,15 +287,19 @@ async function blockTransformer(inputText, config) {
285
287
 
286
288
  const isNewPath = srcPath !== outputPath
287
289
 
288
- if (removeComments && !isNewPath) {
290
+ if (removeComments && !isNewPath && !forceRemoveComments) {
289
291
  throw new Error('"removeComments" can only be used if "outputPath" option is set. Otherwise this will break doc generation.')
290
292
  }
291
293
 
292
- const stripComments = isNewPath && removeComments
294
+ const stripComments = (isNewPath && removeComments) || forceRemoveComments
293
295
 
296
+ let finalContents = updatedContents
297
+ if (forceRemoveComments && openPattern && closePattern) {
298
+ finalContents = updatedContents.replace(openPattern, '').replace(closePattern, '')
299
+ }
294
300
 
295
301
  // console.log('inputText', inputText)
296
- // console.log('updatedContents', updatedContents)
302
+ // console.log('updatedContents', updatedContents)
297
303
  return {
298
304
  isChanged: inputText !== updatedContents,
299
305
  isNewPath,
@@ -303,12 +309,11 @@ async function blockTransformer(inputText, config) {
303
309
  transforms: transformsToRun,
304
310
  missingTransforms,
305
311
  originalContents: inputText,
306
- updatedContents,
312
+ updatedContents: finalContents,
307
313
  patterns: regexInfo,
308
314
  }
309
315
  }
310
316
 
311
-
312
317
  /** @typedef {BlockData & { sourceLocation?: string, transform?: string }} BlockDataExtended */
313
318
 
314
319
  function getDetails({
@@ -248,4 +248,44 @@ original content
248
248
  assert.ok(result.updatedContents.includes('original content'))
249
249
  })
250
250
 
251
+ test('forceRemoveComments bypasses safety check and strips comments from updatedContents', async () => {
252
+ const text = `
253
+ <!-- block test -->
254
+ content
255
+ <!-- /block -->
256
+ `
257
+ const result = await blockTransformer(text, {
258
+ srcPath: '/same/path.md',
259
+ outputPath: '/same/path.md',
260
+ forceRemoveComments: true,
261
+ transforms: {
262
+ test: (api) => 'transformed'
263
+ }
264
+ })
265
+
266
+ assert.is(result.stripComments, true)
267
+ assert.not.ok(result.updatedContents.includes('<!-- block'))
268
+ assert.not.ok(result.updatedContents.includes('<!-- /block'))
269
+ assert.ok(result.updatedContents.includes('transformed'))
270
+ })
271
+
272
+ test('forceRemoveComments works without outputPath', async () => {
273
+ const text = `
274
+ <!-- block test -->
275
+ content
276
+ <!-- /block -->
277
+ `
278
+ const result = await blockTransformer(text, {
279
+ forceRemoveComments: true,
280
+ transforms: {
281
+ test: (api) => 'transformed'
282
+ }
283
+ })
284
+
285
+ assert.is(result.stripComments, true)
286
+ assert.not.ok(result.updatedContents.includes('<!-- block'))
287
+ assert.not.ok(result.updatedContents.includes('<!-- /block'))
288
+ assert.ok(result.updatedContents.includes('transformed'))
289
+ })
290
+
251
291
  test.run()