Skip to content

Commit 9a21857

Browse files
committed
Add cross-reference matching for docutils literal tt tags
1 parent 39966ed commit 9a21857

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/lib/utils/crossref.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function getCrossRefIndex(): Map<string, CrossRefTarget> {
9494
*
9595
* Handles:
9696
* - RST role syntax: :class:`ClassName`, :func:`function_name`, :meth:`method_name`
97+
* - Docutils literal code: ``ClassName`` (<tt class="docutils literal">)
9798
* - Plain backtick code: `ClassName`, `function_name`
9899
* - Title tag references from docutils: <cite>ClassName</cite>
99100
* - Single-quoted class names in text: 'ClassName'
@@ -132,7 +133,16 @@ export function processCrossRefs(
132133
return match;
133134
});
134135

135-
// 3. Handle inline code that matches known classes/functions
136+
// 3. Handle docutils literal inline code: <tt class="docutils literal">Name</tt>
137+
html = html.replace(/<tt class="docutils literal">([A-Z][a-zA-Z0-9_]*)<\/tt>/g, (match, name) => {
138+
const target = index.get(name);
139+
if (target && target.type === 'class') {
140+
return `<a href="${fullPath(target.path)}" class="crossref crossref-${target.type}">${name}</a>`;
141+
}
142+
return match;
143+
});
144+
145+
// 4. Handle inline code that matches known classes/functions
136146
// Be careful not to match code inside pre blocks or already-processed links
137147
html = html.replace(/<code>([A-Z][a-zA-Z0-9_]*)<\/code>/g, (match, name) => {
138148
// Skip if it looks like it's already part of a link
@@ -143,7 +153,7 @@ export function processCrossRefs(
143153
return match;
144154
});
145155

146-
// 4. Handle title attribute references (docutils)
156+
// 5. Handle title attribute references (docutils)
147157
html = html.replace(
148158
/<span class="[^"]*" title="([^"]+)">([^<]+)<\/span>/g,
149159
(match, title, text) => {
@@ -155,7 +165,7 @@ export function processCrossRefs(
155165
}
156166
);
157167

158-
// 5. Handle single-quoted class names in plain text: 'ClassName'
168+
// 6. Handle single-quoted class names in plain text: 'ClassName'
159169
// Only match PascalCase names (likely class names)
160170
html = html.replace(/'([A-Z][a-zA-Z0-9_]*)'/g, (match, name) => {
161171
const target = index.get(name);

0 commit comments

Comments
 (0)