comment-block-transformer 0.2.0 → 0.2.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 +11 -0
- package/package.json +2 -2
- package/src/index.js +16 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.2.1](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.2.0...comment-block-transformer@0.2.1) (2025-11-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* replace the block by position instead of simple replace ([fd93c39](https://github.com/DavidWells/markdown-magic/commit/fd93c39fea3c4c03901babe6039243194624bdcd))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 0.2.0 (2025-10-25)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-block-transformer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Transform markdown blocks based on configured transforms",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "ddedd0639200db28f1b1d0e3b805603ffaa234ee"
|
|
28
28
|
}
|
package/src/index.js
CHANGED
|
@@ -143,6 +143,9 @@ async function blockTransformer(inputText, config) {
|
|
|
143
143
|
const transformsToRun = sortTransforms(blocksWithTransforms, transforms)
|
|
144
144
|
|
|
145
145
|
let missingTransforms = []
|
|
146
|
+
// Track cumulative offset changes as we modify the text
|
|
147
|
+
let cumulativeOffset = 0
|
|
148
|
+
|
|
146
149
|
let updatedContents = await transformsToRun.reduce(async (contentPromise, originalMatch) => {
|
|
147
150
|
const updatedText = await contentPromise
|
|
148
151
|
/* Apply leading middleware */
|
|
@@ -261,9 +264,21 @@ async function blockTransformer(inputText, config) {
|
|
|
261
264
|
fixWrapper = '\n'
|
|
262
265
|
}
|
|
263
266
|
|
|
267
|
+
// console.log('updatedText', block.value)
|
|
268
|
+
|
|
264
269
|
const indent = addLeadingNewline + indentString(fix, preserveIndent) + addTrailingNewline
|
|
265
270
|
const newCont = `${openTag}${fixWrapper}${indent}${fixWrapper}${closeTag}`
|
|
266
|
-
|
|
271
|
+
|
|
272
|
+
// Use position-based replacement to handle duplicate block content
|
|
273
|
+
const adjustedStart = block.start + cumulativeOffset
|
|
274
|
+
const adjustedEnd = block.end + cumulativeOffset
|
|
275
|
+
const before = updatedText.substring(0, adjustedStart)
|
|
276
|
+
const after = updatedText.substring(adjustedEnd)
|
|
277
|
+
const newContents = before + newCont + after
|
|
278
|
+
|
|
279
|
+
// Update offset for next iteration
|
|
280
|
+
cumulativeOffset += (newCont.length - block.value.length)
|
|
281
|
+
|
|
267
282
|
return Promise.resolve(newContents)
|
|
268
283
|
}, Promise.resolve(inputText))
|
|
269
284
|
|