@markuplint/parser-utils 4.6.7 → 4.7.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.
- package/CHANGELOG.md +10 -3
- package/lib/get-location.d.ts +4 -0
- package/lib/get-location.js +22 -0
- package/lib/parser.js +2 -21
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,21 +3,28 @@
|
|
|
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
|
-
|
|
6
|
+
# [4.7.0](https://github.com/markuplint/markuplint/compare/@markuplint/parser-utils@4.6.8...@markuplint/parser-utils@4.7.0) (2024-10-15)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @markuplint/parser-utils
|
|
9
8
|
|
|
9
|
+
### Features
|
|
10
10
|
|
|
11
|
+
* **parser-utils:** expose `getOffsetsFromCode` function ([8ef7aec](https://github.com/markuplint/markuplint/commit/8ef7aec26d3198328c86ebeffaa0bd9c879a1f0e))
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [4.6.8](https://github.com/markuplint/markuplint/compare/@markuplint/parser-utils@4.6.7...@markuplint/parser-utils@4.6.8) (2024-10-14)
|
|
15
18
|
|
|
16
19
|
**Note:** Version bump only for package @markuplint/parser-utils
|
|
17
20
|
|
|
21
|
+
## [4.6.7](https://github.com/markuplint/markuplint/compare/@markuplint/parser-utils@4.6.6...@markuplint/parser-utils@4.6.7) (2024-09-23)
|
|
18
22
|
|
|
23
|
+
**Note:** Version bump only for package @markuplint/parser-utils
|
|
19
24
|
|
|
25
|
+
## [4.6.6](https://github.com/markuplint/markuplint/compare/@markuplint/parser-utils@4.6.5...@markuplint/parser-utils@4.6.6) (2024-09-02)
|
|
20
26
|
|
|
27
|
+
**Note:** Version bump only for package @markuplint/parser-utils
|
|
21
28
|
|
|
22
29
|
## [4.6.5](https://github.com/markuplint/markuplint/compare/@markuplint/parser-utils@4.6.4...@markuplint/parser-utils@4.6.5) (2024-06-25)
|
|
23
30
|
|
package/lib/get-location.d.ts
CHANGED
|
@@ -12,3 +12,7 @@ export declare function getPosition(rawCodeFragment: string, startOffset: number
|
|
|
12
12
|
};
|
|
13
13
|
export declare function getEndLine(rawCodeFragment: string, startLine: number): number;
|
|
14
14
|
export declare function getEndCol(rawCodeFragment: string, startCol: number): number;
|
|
15
|
+
export declare function getOffsetsFromCode(rawCode: string, startLine: number, startCol: number, endLine: number, endCol: number): {
|
|
16
|
+
offset: number;
|
|
17
|
+
endOffset: number;
|
|
18
|
+
};
|
package/lib/get-location.js
CHANGED
|
@@ -27,3 +27,25 @@ export function getEndCol(rawCodeFragment, startCol) {
|
|
|
27
27
|
const lastLine = lines.pop();
|
|
28
28
|
return lineCount > 1 ? lastLine.length + 1 : startCol + rawCodeFragment.length;
|
|
29
29
|
}
|
|
30
|
+
export function getOffsetsFromCode(rawCode, startLine, startCol, endLine, endCol) {
|
|
31
|
+
const lines = rawCode.split('\n');
|
|
32
|
+
let offset = 0;
|
|
33
|
+
let endOffset = 0;
|
|
34
|
+
for (let i = 0; i < startLine - 1; i++) {
|
|
35
|
+
const line = lines[i];
|
|
36
|
+
if (line == null) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
offset += line.length + 1;
|
|
40
|
+
}
|
|
41
|
+
offset += startCol - 1;
|
|
42
|
+
for (let i = 0; i < endLine - 1; i++) {
|
|
43
|
+
const line = lines[i];
|
|
44
|
+
if (line == null) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
endOffset += line.length + 1;
|
|
48
|
+
}
|
|
49
|
+
endOffset += endCol - 1;
|
|
50
|
+
return { offset, endOffset };
|
|
51
|
+
}
|
package/lib/parser.js
CHANGED
|
@@ -17,7 +17,7 @@ import { defaultSpaces } from './const.js';
|
|
|
17
17
|
import { domLog } from './debug.js';
|
|
18
18
|
import { detectElementType } from './detect-element-type.js';
|
|
19
19
|
import { AttrState, TagState } from './enums.js';
|
|
20
|
-
import { getEndCol, getEndLine, getPosition } from './get-location.js';
|
|
20
|
+
import { getEndCol, getEndLine, getOffsetsFromCode, getPosition } from './get-location.js';
|
|
21
21
|
import { ignoreBlock, restoreNode } from './ignore-block.js';
|
|
22
22
|
import { ignoreFrontMatter } from './ignore-front-matter.js';
|
|
23
23
|
import { ParserError } from './parser-error.js';
|
|
@@ -587,26 +587,7 @@ export class Parser {
|
|
|
587
587
|
};
|
|
588
588
|
}
|
|
589
589
|
getOffsetsFromCode(startLine, startCol, endLine, endCol) {
|
|
590
|
-
|
|
591
|
-
let offset = 0;
|
|
592
|
-
let endOffset = 0;
|
|
593
|
-
for (let i = 0; i < startLine - 1; i++) {
|
|
594
|
-
const line = lines[i];
|
|
595
|
-
if (line == null) {
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
offset += line.length + 1;
|
|
599
|
-
}
|
|
600
|
-
offset += startCol - 1;
|
|
601
|
-
for (let i = 0; i < endLine - 1; i++) {
|
|
602
|
-
const line = lines[i];
|
|
603
|
-
if (line == null) {
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
endOffset += line.length + 1;
|
|
607
|
-
}
|
|
608
|
-
endOffset += endCol - 1;
|
|
609
|
-
return { offset, endOffset };
|
|
590
|
+
return getOffsetsFromCode(this.rawCode, startLine, startCol, endLine, endCol);
|
|
610
591
|
}
|
|
611
592
|
walk(nodeList, walker, depth = 0) {
|
|
612
593
|
for (const node of nodeList) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/parser-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Utility module for markuplint parser plugin",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"clean": "tsc --build --clean"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@markuplint/ml-ast": "4.4.
|
|
32
|
-
"@markuplint/ml-spec": "4.7.
|
|
33
|
-
"@markuplint/types": "4.6.
|
|
31
|
+
"@markuplint/ml-ast": "4.4.6",
|
|
32
|
+
"@markuplint/ml-spec": "4.7.2",
|
|
33
|
+
"@markuplint/types": "4.6.2",
|
|
34
34
|
"@types/uuid": "10.0.0",
|
|
35
35
|
"debug": "4.3.7",
|
|
36
|
-
"espree": "10.
|
|
36
|
+
"espree": "10.2.0",
|
|
37
37
|
"type-fest": "4.26.1",
|
|
38
38
|
"uuid": "10.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@typescript-eslint/typescript-estree": "8.
|
|
41
|
+
"@typescript-eslint/typescript-estree": "8.9.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "c8c82d36c2e48d191091cbc22ca1b99ed0704b9f"
|
|
44
44
|
}
|