@@ -15,6 +15,7 @@ import { findOffsets, illegalShorthandTailPattern } from "../util.js";
1515
1616/** @typedef {import("unist").Position } Position */
1717/** @typedef {import("mdast").Text } TextNode */
18+ /** @typedef {Parameters<import("../types.ts").MarkdownRuleDefinition['create']>[0]['sourceCode'] } sourceCode */
1819/**
1920 * @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }> }
2021 * NoInvalidLabelRuleDefinition
@@ -30,10 +31,12 @@ const labelPattern = /\]\[([^\]]+)\]/u;
3031/**
3132 * Finds missing references in a node.
3233 * @param {TextNode } node The node to check.
33- * @param {string } docText The text of the node .
34+ * @param {sourceCode } sourceCode The Markdown source code object .
3435 * @returns {Array<{label:string,position:Position}> } The missing references.
3536 */
36- function findInvalidLabelReferences ( node , docText ) {
37+ function findInvalidLabelReferences ( node , sourceCode ) {
38+ const nodeText = sourceCode . getText ( node ) ;
39+ const docText = sourceCode . text ;
3740 const invalid = [ ] ;
3841 let startIndex = 0 ;
3942 const offset = node . position . start . offset ;
@@ -47,8 +50,8 @@ function findInvalidLabelReferences(node, docText) {
4750 * It then moves the start index to the end of the label reference and
4851 * continues searching the text until the end of the text is found.
4952 */
50- while ( startIndex < node . value . length ) {
51- const value = node . value . slice ( startIndex ) ;
53+ while ( startIndex < nodeText . length ) {
54+ const value = nodeText . slice ( startIndex ) ;
5255 const match = value . match ( labelPattern ) ;
5356
5457 if ( ! match ) {
@@ -87,11 +90,11 @@ function findInvalidLabelReferences(node, docText) {
8790
8891 // find location of [ in the document text
8992 const { lineOffset : startLineOffset , columnOffset : startColumnOffset } =
90- findOffsets ( node . value , nodeMatchIndex + 1 ) ;
93+ findOffsets ( nodeText , nodeMatchIndex + 1 ) ;
9194
9295 // find location of [ in the document text
9396 const { lineOffset : endLineOffset , columnOffset : endColumnOffset } =
94- findOffsets ( node . value , nodeMatchIndex + match [ 0 ] . length ) ;
97+ findOffsets ( nodeText , nodeMatchIndex + match [ 0 ] . length ) ;
9598
9699 const startLine = nodeStartLine + startLineOffset ;
97100 const startColumn = nodeStartColumn + startColumnOffset ;
@@ -147,7 +150,7 @@ export default {
147150 text ( node ) {
148151 const invalidReferences = findInvalidLabelReferences (
149152 node ,
150- sourceCode . text ,
153+ sourceCode ,
151154 ) ;
152155
153156 for ( const invalidReference of invalidReferences ) {
0 commit comments