anentrypoint-design 0.0.245 → 0.0.246

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/src/page-html.js CHANGED
@@ -28,6 +28,15 @@ export function inlineMd(s) {
28
28
  .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
29
29
  }
30
30
 
31
+ // GitHub-flavored heading slug: lowercase, strip non-word/non-space/non-hyphen,
32
+ // collapse whitespace to hyphens. Matches the fallback anchor target a hero/nav
33
+ // CTA's `#slug` href expects to resolve against a `## slug text` body heading.
34
+ export function slugify(s) {
35
+ return String(s || '').trim().toLowerCase()
36
+ .replace(/[^\w\s-]/g, '')
37
+ .replace(/\s+/g, '-');
38
+ }
39
+
31
40
  export function renderMarkdown(md) {
32
41
  const lines = String(md || '').split('\n');
33
42
  const out = [];
@@ -35,9 +44,9 @@ export function renderMarkdown(md) {
35
44
  for (const line of lines) {
36
45
  if (line.startsWith('```')) { if (inCode) { out.push('</pre>'); inCode = false; } else { out.push('<pre>'); inCode = true; } continue; }
37
46
  if (inCode) { out.push(escape(line)); continue; }
38
- if (line.startsWith('# ')) out.push(`<h1>${escape(line.slice(2))}</h1>`);
39
- else if (line.startsWith('## ')) out.push(`<h2>${escape(line.slice(3))}</h2>`);
40
- else if (line.startsWith('### ')) out.push(`<h3>${escape(line.slice(4))}</h3>`);
47
+ if (line.startsWith('# ')) { const t = line.slice(2); out.push(`<h1 id="${slugify(t)}">${escape(t)}</h1>`); }
48
+ else if (line.startsWith('## ')) { const t = line.slice(3); out.push(`<h2 id="${slugify(t)}">${escape(t)}</h2>`); }
49
+ else if (line.startsWith('### ')) { const t = line.slice(4); out.push(`<h3 id="${slugify(t)}">${escape(t)}</h3>`); }
41
50
  else if (line.startsWith('- ')) { if (!inList) { out.push('<ul>'); inList = true; } out.push(`<li>${inlineMd(escape(line.slice(2)))}</li>`); }
42
51
  else { if (inList) { out.push('</ul>'); inList = false; } if (line.trim()) out.push(`<p>${inlineMd(escape(line))}</p>`); }
43
52
  }
@@ -183,6 +192,7 @@ function sectionNode(sec, idx) {
183
192
  return h('div', { key: i, class: 'ds-feature' }, ...kids);
184
193
  });
185
194
  return C.Section({
195
+ id: sec.id || null,
186
196
  title: sec.name || sec.title || sec.id,
187
197
  children: [
188
198
  sec.lede ? h('p', { class: 'ds-lede' }, sec.lede) : null,
@@ -209,6 +219,7 @@ function examplesNode(examples) {
209
219
  }
210
220
 
211
221
  // minimal client-side markdown renderer matching server-side renderer (idempotent for already-html bodies)
222
+ function __slug(s) { return String(s || '').trim().toLowerCase().replace(/[^\\w\\s-]/g, '').replace(/\\s+/g, '-'); }
212
223
  function __md(md) {
213
224
  const lines = String(md || '').split('\\n');
214
225
  const out = []; let inCode = false, inList = false;
@@ -217,9 +228,9 @@ function __md(md) {
217
228
  for (const line of lines) {
218
229
  if (line.startsWith('\`\`\`')) { if (inCode) { out.push('</pre>'); inCode = false; } else { out.push('<pre>'); inCode = true; } continue; }
219
230
  if (inCode) { out.push(esc(line)); continue; }
220
- if (line.startsWith('# ')) out.push('<h1>' + esc(line.slice(2)) + '</h1>');
221
- else if (line.startsWith('## ')) out.push('<h2>' + esc(line.slice(3)) + '</h2>');
222
- else if (line.startsWith('### ')) out.push('<h3>' + esc(line.slice(4)) + '</h3>');
231
+ if (line.startsWith('# ')) { const t = line.slice(2); out.push('<h1 id="' + __slug(t) + '">' + esc(t) + '</h1>'); }
232
+ else if (line.startsWith('## ')) { const t = line.slice(3); out.push('<h2 id="' + __slug(t) + '">' + esc(t) + '</h2>'); }
233
+ else if (line.startsWith('### ')) { const t = line.slice(4); out.push('<h3 id="' + __slug(t) + '">' + esc(t) + '</h3>'); }
223
234
  else if (line.startsWith('- ')) { if (!inList) { out.push('<ul>'); inList = true; } out.push('<li>' + inl(esc(line.slice(2))) + '</li>'); }
224
235
  else { if (inList) { out.push('</ul>'); inList = false; } if (line.trim()) out.push('<p>' + inl(esc(line)) + '</p>'); }
225
236
  }