Spaces:
Running
Running
Make bare category/node topic cross-references clickable (#1)
Browse files- Make bare category/node topic cross-references clickable (db768b9206dd78dd9b10335e7dca70b4b60aaa61)
Co-authored-by: Thomas Wolf <thomwolf@users.noreply.huggingface.co>
- app.js +23 -0
- styles.css +8 -0
app.js
CHANGED
|
@@ -192,6 +192,29 @@ function setupMarked() {
|
|
| 192 |
renderer(tok) { return citationHTML(tok.id); },
|
| 193 |
}],
|
| 194 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
marked.setOptions({ gfm: true, breaks: false });
|
| 196 |
}
|
| 197 |
|
|
|
|
| 192 |
renderer(tok) { return citationHTML(tok.id); },
|
| 193 |
}],
|
| 194 |
});
|
| 195 |
+
// Cross-references between topics are authored as bare `category/node` code
|
| 196 |
+
// spans (e.g. `preference-data/ai-feedback-data`) rather than markdown links.
|
| 197 |
+
// Turn each into a live hop to that topic — but only when the page exists, so
|
| 198 |
+
// genuine code spans (`preference/DPO`, planned-but-unwritten nodes) stay plain.
|
| 199 |
+
// (Markdown-link cross-refs are handled separately by rewriteInternalLinks;
|
| 200 |
+
// this href is already a `#/` route, so that pass leaves it untouched.)
|
| 201 |
+
marked.use({
|
| 202 |
+
renderer: {
|
| 203 |
+
// marked@13 hands codespan the already-HTML-escaped code text as a plain
|
| 204 |
+
// string (the {text} token arg is a marked-v16 API) — so read it directly
|
| 205 |
+
// and don't re-escape, or every cross-ref silently falls through to plain.
|
| 206 |
+
codespan(code) {
|
| 207 |
+
const m = /^([a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*)$/.exec(code);
|
| 208 |
+
if (m) {
|
| 209 |
+
const path = `topics/${m[1]}.md`;
|
| 210 |
+
if (state.pages.some(p => p.path === path)) {
|
| 211 |
+
return `<a class="xref" href="#/topic/${encodeURIComponent(path)}" title="Topic: ${m[1]}"><code>${code}</code></a>`;
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
return false; // fall back to marked's default code-span rendering
|
| 215 |
+
},
|
| 216 |
+
},
|
| 217 |
+
});
|
| 218 |
marked.setOptions({ gfm: true, breaks: false });
|
| 219 |
}
|
| 220 |
|
styles.css
CHANGED
|
@@ -312,6 +312,14 @@ a:hover { color: var(--accent-deep); }
|
|
| 312 |
font-size: 12.8px; line-height: 1.55;
|
| 313 |
}
|
| 314 |
.prose pre code { background: none; border: none; padding: 0; font-size: inherit; color: var(--ink-2); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
/* blockquote */
|
| 317 |
.prose blockquote {
|
|
|
|
| 312 |
font-size: 12.8px; line-height: 1.55;
|
| 313 |
}
|
| 314 |
.prose pre code { background: none; border: none; padding: 0; font-size: inherit; color: var(--ink-2); }
|
| 315 |
+
/* cross-reference: a `category/node` code span linked to its topic page */
|
| 316 |
+
.prose a.xref { border-bottom: none; text-decoration: none; }
|
| 317 |
+
.prose a.xref code {
|
| 318 |
+
background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep);
|
| 319 |
+
cursor: pointer; transition: background .12s, color .12s;
|
| 320 |
+
}
|
| 321 |
+
.prose a.xref:hover code { background: var(--accent); color: #fff; }
|
| 322 |
+
[data-theme="dark"] .prose a.xref:hover code { color: #0b1220; }
|
| 323 |
|
| 324 |
/* blockquote */
|
| 325 |
.prose blockquote {
|