comment-block-transformer 0.2.0 → 0.2.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.
- package/CHANGELOG.md +19 -0
- package/package.json +3 -3
- package/src/index.js +16 -2
- package/tsconfig.json +1 -1
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.2.2](https://github.com/DavidWells/markdown-magic/compare/comment-block-transformer@0.2.1...comment-block-transformer@0.2.2) (2025-11-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package comment-block-transformer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [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)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* replace the block by position instead of simple replace ([fd93c39](https://github.com/DavidWells/markdown-magic/commit/fd93c39fea3c4c03901babe6039243194624bdcd))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# 0.2.0 (2025-10-25)
|
|
7
26
|
|
|
8
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-block-transformer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Transform markdown blocks based on configured transforms",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"release:major": "pnpm run build && pnpm version major && pnpm publish"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"comment-block-parser": "1.1.
|
|
18
|
+
"comment-block-parser": "1.1.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"typescript": "^5.0.0",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "c67e6884103de807711ff608e100e1e0a211c2d8"
|
|
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 */
|
|
@@ -194,7 +197,6 @@ async function blockTransformer(inputText, config) {
|
|
|
194
197
|
tempContent = returnedContent
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
|
-
|
|
198
200
|
/* Apply trailing middleware */
|
|
199
201
|
const afterContent = await applyMiddleware({
|
|
200
202
|
...match,
|
|
@@ -260,10 +262,22 @@ async function blockTransformer(inputText, config) {
|
|
|
260
262
|
if (!context.isMultiline && fix.indexOf('\n') > -1) {
|
|
261
263
|
fixWrapper = '\n'
|
|
262
264
|
}
|
|
265
|
+
|
|
266
|
+
// console.log('updatedText', block.value)
|
|
263
267
|
|
|
264
268
|
const indent = addLeadingNewline + indentString(fix, preserveIndent) + addTrailingNewline
|
|
265
269
|
const newCont = `${openTag}${fixWrapper}${indent}${fixWrapper}${closeTag}`
|
|
266
|
-
|
|
270
|
+
|
|
271
|
+
// Use position-based replacement to handle duplicate block content
|
|
272
|
+
const adjustedStart = block.start + cumulativeOffset
|
|
273
|
+
const adjustedEnd = block.end + cumulativeOffset
|
|
274
|
+
const before = updatedText.substring(0, adjustedStart)
|
|
275
|
+
const after = updatedText.substring(adjustedEnd)
|
|
276
|
+
const newContents = before + newCont + after
|
|
277
|
+
|
|
278
|
+
// Update offset for next iteration
|
|
279
|
+
cumulativeOffset += (newCont.length - block.value.length)
|
|
280
|
+
|
|
267
281
|
return Promise.resolve(newContents)
|
|
268
282
|
}, Promise.resolve(inputText))
|
|
269
283
|
|
package/tsconfig.json
CHANGED