@clarusjs/content 0.4.2 → 0.6.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.d.ts +4 -1
- package/dist/index.js +35 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ import type { Source } from 'clarusjs/vite';
|
|
|
4
4
|
* @see https://clarusjs.com/reference/content#markdown
|
|
5
5
|
*/
|
|
6
6
|
export type MarkdownOptions = {
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The layout every page renders in, root-relative (`/src/layouts/docs.tscl`), inside the page's folder and config
|
|
9
|
+
* layouts. Frontmatter `layout` overrides it; `layout: false` there renders the page with no layout at all.
|
|
10
|
+
*/
|
|
8
11
|
layout?: string | false;
|
|
9
12
|
/**
|
|
10
13
|
* Render `::: tip` blocks (and alerts) through your own component: `<tag [type]="'tip'">`, with a custom title in its
|
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++)
|
|
@@ -280,10 +304,14 @@ function renderer(options) {
|
|
|
280
304
|
});
|
|
281
305
|
return md;
|
|
282
306
|
}
|
|
283
|
-
function pageHead(data, title) {
|
|
307
|
+
function pageHead(data, title, bare = false) {
|
|
284
308
|
const tags = [];
|
|
285
309
|
if (data.titleTemplate === false && title !== undefined)
|
|
286
310
|
tags.push(`<title>${escapeHtml(title)}</title>`);
|
|
311
|
+
else if (bare && title !== undefined)
|
|
312
|
+
tags.push(`<title data-cl-template>${escapeHtml(title)}</title>`);
|
|
313
|
+
if (bare && typeof data.description === 'string')
|
|
314
|
+
tags.push(`<meta name="description" content="${escapeHtml(data.description)}">`);
|
|
287
315
|
if (data.sitemap === false)
|
|
288
316
|
tags.push('<meta name="sitemap" content="false">');
|
|
289
317
|
const lastmod = data.lastmod instanceof Date ? data.lastmod.toISOString().slice(0, 10) : typeof data.lastmod === 'string' ? data.lastmod : undefined;
|
|
@@ -412,14 +440,16 @@ export default function markdown(options = {}) {
|
|
|
412
440
|
const headings = tokens.flatMap((t, i) => {
|
|
413
441
|
if (t.type !== 'heading_open' || (t.tag !== 'h2' && t.tag !== 'h3') || t.level !== 0)
|
|
414
442
|
return [];
|
|
415
|
-
const text = (tokens[i + 1].children ?? []).filter((c) => c.type === 'text' || c.type === 'code_inline').map((c) => c.content).join('');
|
|
443
|
+
const text = (tokens[i + 1].children ?? []).filter((c) => c.type === 'text' || c.type === 'code_inline').map((c) => c.content).join('').trim();
|
|
416
444
|
return [{ id: String(t.attrGet('id') ?? ''), text, level: t.tag === 'h2' ? 2 : 3 }];
|
|
417
445
|
});
|
|
418
446
|
const h1 = tokens.findIndex((t) => t.type === 'heading_open' && t.tag === 'h1');
|
|
419
447
|
const firstHeading = h1 === -1 ? undefined : (tokens[h1 + 1].children ?? []).filter((t) => t.type === 'text' || t.type === 'code_inline').map((t) => t.content).join('');
|
|
420
448
|
const title = typeof data.title === 'string' ? data.title : firstHeading;
|
|
421
|
-
const
|
|
422
|
-
const
|
|
449
|
+
const layout = data.layout === false ? undefined : typeof data.layout === 'string' ? data.layout : options.layout;
|
|
450
|
+
const html = pageHead(data, title, !layout) + tags.restore(staticHtml(md.renderer.render(tokens, md.options, env)));
|
|
451
|
+
if (data.layout === false)
|
|
452
|
+
return ['@layout none', ...imports, html].join('\n');
|
|
423
453
|
if (!layout)
|
|
424
454
|
return [...imports, html].join('\n');
|
|
425
455
|
const props = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarusjs/content",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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.17.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.17.0",
|
|
54
54
|
"typescript": "^7.0.2",
|
|
55
55
|
"vite": "^8.3.8",
|
|
56
56
|
"vitest": "^5.1.1"
|