comment-block-transformer 0.5.5 → 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,44 @@
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
+
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)
26
+
27
+ **Note:** Version bump only for package comment-block-transformer
28
+
29
+
30
+
31
+
32
+
33
+ ## [0.5.6](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.5.5...comment-block-transformer@0.5.6) (2026-01-19)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * enable pattern mode for custom open tags ([904d4dc](https://github.com/DavidWells/markdown-magic/commit/904d4dc391a36848d5bb142d54835423df0b9d05))
39
+
40
+
41
+
42
+
43
+
6
44
  ## [0.5.5](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.5.4...comment-block-transformer@0.5.5) (2026-01-19)
7
45
 
8
46
  **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.5",
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": "3d60211919bdc910870a92270b64a7aeed5e44fc"
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.
@@ -98,14 +99,16 @@ async function blockTransformer(inputText, config) {
98
99
  srcPath,
99
100
  outputPath,
100
101
  open = OPEN_WORD,
101
- close = CLOSE_WORD,
102
102
  syntax = SYNTAX,
103
103
  transforms = {},
104
104
  beforeMiddleware = [],
105
105
  afterMiddleware = [],
106
106
  removeComments = false,
107
+ forceRemoveComments = false,
107
108
  customPatterns
108
109
  } = opts
110
+ // Don't default close - let undefined pass through to enable pattern mode in block-parser
111
+ const close = opts.close !== undefined ? opts.close : (opts.open ? undefined : CLOSE_WORD)
109
112
 
110
113
  let foundBlocks = {}
111
114
  try {
@@ -284,15 +287,19 @@ async function blockTransformer(inputText, config) {
284
287
 
285
288
  const isNewPath = srcPath !== outputPath
286
289
 
287
- if (removeComments && !isNewPath) {
290
+ if (removeComments && !isNewPath && !forceRemoveComments) {
288
291
  throw new Error('"removeComments" can only be used if "outputPath" option is set. Otherwise this will break doc generation.')
289
292
  }
290
293
 
291
- const stripComments = isNewPath && removeComments
294
+ const stripComments = (isNewPath && removeComments) || forceRemoveComments
292
295
 
296
+ let finalContents = updatedContents
297
+ if (forceRemoveComments && openPattern && closePattern) {
298
+ finalContents = updatedContents.replace(openPattern, '').replace(closePattern, '')
299
+ }
293
300
 
294
301
  // console.log('inputText', inputText)
295
- // console.log('updatedContents', updatedContents)
302
+ // console.log('updatedContents', updatedContents)
296
303
  return {
297
304
  isChanged: inputText !== updatedContents,
298
305
  isNewPath,
@@ -302,7 +309,7 @@ async function blockTransformer(inputText, config) {
302
309
  transforms: transformsToRun,
303
310
  missingTransforms,
304
311
  originalContents: inputText,
305
- updatedContents,
312
+ updatedContents: finalContents,
306
313
  patterns: regexInfo,
307
314
  }
308
315
  }
@@ -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()