@clarusjs/content 0.4.1 → 0.5.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/dist/index.js +26 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -257,13 +257,37 @@ function renderer(options) {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
});
|
|
260
|
+
const VERSION = /\{((?:since|deprecated|removed)=\d+\.\d+\.\d+(?:\s+(?:since|deprecated|removed)=\d+\.\d+\.\d+)*)\}/g;
|
|
261
|
+
md.core.ruler.after('inline', 'cl_versions', (state) => {
|
|
262
|
+
for (const block of state.tokens) {
|
|
263
|
+
if (block.type !== 'inline' || !block.children)
|
|
264
|
+
continue;
|
|
265
|
+
block.children = block.children.flatMap((t) => {
|
|
266
|
+
if (t.type !== 'text' || !VERSION.test(t.content))
|
|
267
|
+
return [t];
|
|
268
|
+
VERSION.lastIndex = 0;
|
|
269
|
+
const out = [];
|
|
270
|
+
let at = 0;
|
|
271
|
+
for (const m of t.content.matchAll(VERSION)) {
|
|
272
|
+
out.push(Object.assign(new state.Token('text', '', 0), { content: t.content.slice(at, m.index) }));
|
|
273
|
+
const v = Object.fromEntries(m[1].split(/\s+/).map((kv) => kv.split('=')));
|
|
274
|
+
const label = v.since ? `Since ${v.since}` : v.deprecated ? `Deprecated in ${v.deprecated}${v.removed ? `, removed in ${v.removed}` : ''}` : `Removed in ${v.removed}`;
|
|
275
|
+
const kind = v.since ? 'since' : v.deprecated ? 'deprecated' : 'removed';
|
|
276
|
+
out.push(Object.assign(new state.Token('html_inline', '', 0), { content: `<span class="version" data-version="${kind}">${escapeHtml(label)}</span>` }));
|
|
277
|
+
at = m.index + m[0].length;
|
|
278
|
+
}
|
|
279
|
+
out.push(Object.assign(new state.Token('text', '', 0), { content: t.content.slice(at) }));
|
|
280
|
+
return out.filter((x) => x.type !== 'text' || x.content);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
260
284
|
md.core.ruler.push('cl_anchors', (state) => {
|
|
261
285
|
const used = new Set();
|
|
262
286
|
state.tokens.forEach((token, i) => {
|
|
263
287
|
if (token.type !== 'heading_open')
|
|
264
288
|
return;
|
|
265
289
|
const inline = state.tokens[i + 1];
|
|
266
|
-
const text = (inline.children ?? []).filter((t) => t.type === 'text' || t.type === 'code_inline').map((t) => t.content).join('');
|
|
290
|
+
const text = (inline.children ?? []).filter((t) => t.type === 'text' || t.type === 'code_inline').map((t) => t.content).join('').trim();
|
|
267
291
|
const base = slugify(text);
|
|
268
292
|
let id = base;
|
|
269
293
|
for (let n = 1; used.has(id); n++)
|
|
@@ -412,7 +436,7 @@ export default function markdown(options = {}) {
|
|
|
412
436
|
const headings = tokens.flatMap((t, i) => {
|
|
413
437
|
if (t.type !== 'heading_open' || (t.tag !== 'h2' && t.tag !== 'h3') || t.level !== 0)
|
|
414
438
|
return [];
|
|
415
|
-
const text = (tokens[i + 1].children ?? []).filter((c) => c.type === 'text' || c.type === 'code_inline').map((c) => c.content).join('');
|
|
439
|
+
const text = (tokens[i + 1].children ?? []).filter((c) => c.type === 'text' || c.type === 'code_inline').map((c) => c.content).join('').trim();
|
|
416
440
|
return [{ id: String(t.attrGet('id') ?? ''), text, level: t.tag === 'h2' ? 2 : 3 }];
|
|
417
441
|
});
|
|
418
442
|
const h1 = tokens.findIndex((t) => t.type === 'heading_open' && t.tag === 'h1');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarusjs/content",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Markdown pages for clarusjs: frontmatter, layouts, components in Markdown, rendered to static HTML at build time.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"clarusjs": "^0.
|
|
22
|
+
"clarusjs": "^0.16.0"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": "^22.12.0 || ^24.0.0 || >=26.0.0"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/markdown-it": "^14.2.0",
|
|
52
52
|
"@types/node": "^26.6.6",
|
|
53
|
-
"clarusjs": "^0.
|
|
53
|
+
"clarusjs": "^0.16.0",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
55
|
"vite": "^8.3.8",
|
|
56
56
|
"vitest": "^5.1.1"
|