@prunellejs/content 0.7.4 → 0.7.7
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/llms.txt +1 -0
- package/package.json +2 -2
- package/src/markdown.ts +16 -0
package/llms.txt
CHANGED
|
@@ -35,6 +35,7 @@ Shared options:
|
|
|
35
35
|
- `col.paths(prefix?, locale?)`: URL list for `export const prerender = true; export const paths = () => col.paths('/blog')`.
|
|
36
36
|
- `col.clearCache()`: drops cached entries.
|
|
37
37
|
- `ContentEntry<TData>`: `slug`, `locale`, `file`, `data`, `body`, `html`, `headings` (`{ level, id, text }[]`), `wordCount`, `readingMinutes`, and `await entry.render()` (memoized).
|
|
38
|
+
- Markdown tables render with `scope="col"` header cells, the first cell of each body row as `<th scope="row">` when the table has two columns or more, and `style="text-align:…"` in place of `align` (RGAA 5.6, 5.7, 10.1).
|
|
38
39
|
|
|
39
40
|
## Plugin Setup (`content({ feeds?, collections? })`)
|
|
40
41
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prunellejs/content",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Zero-dependency Bun.markdown collections, YAML frontmatter, TOC, and RSS plugin for Prunelle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"directory": "packages/plugin-content"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"prunelle": "^0.7.
|
|
24
|
+
"prunelle": "^0.7.7"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/markdown.ts
CHANGED
|
@@ -24,6 +24,21 @@ function decodeHtmlEntities(text: string): string {
|
|
|
24
24
|
})
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
const MD_TABLE_RE = /<table>[\s\S]*?<\/table>/g
|
|
28
|
+
const HEADER_CELL_RE = /<th( align="\w+")?>/g
|
|
29
|
+
const FIRST_BODY_CELL_RE = /<tr><td( align="\w+")?>([\s\S]*?)<\/td>/g
|
|
30
|
+
const ALIGN_ATTR_RE = / align="(left|center|right)"/g
|
|
31
|
+
|
|
32
|
+
// Bun's GFM tables give bare `<th>` and an `align` attribute: RGAA 5.7 wants headers scoped, 5.6 the first column of a wider table as row headers, and 10.1 no presentation attribute.
|
|
33
|
+
function scopeTableHeaders(html: string): string {
|
|
34
|
+
return html.replace(MD_TABLE_RE, (table) => {
|
|
35
|
+
let out = table.replace(HEADER_CELL_RE, '<th scope="col"$1>')
|
|
36
|
+
if (out.indexOf('<th scope="col"') !== out.lastIndexOf('<th scope="col"'))
|
|
37
|
+
out = out.replace(FIRST_BODY_CELL_RE, '<tr><th scope="row"$1>$2</th>')
|
|
38
|
+
return out.replace(ALIGN_ATTR_RE, ' style="text-align:$1"')
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
27
42
|
function slugifyHeading(text: string): string {
|
|
28
43
|
return text
|
|
29
44
|
.replace(/<[^>]+>/g, '')
|
|
@@ -184,6 +199,7 @@ function renderMarkdownInternal(
|
|
|
184
199
|
// Runs before splicing developer-supplied highlight/component slots so custom components remain intact.
|
|
185
200
|
if (options.trusted !== true)
|
|
186
201
|
html = sanitizeMarkdownHtml(html, allowedSlotPrefixes)
|
|
202
|
+
html = scopeTableHeaders(html)
|
|
187
203
|
|
|
188
204
|
// 4. Image rewriting (explicit resolveImage or auto-wired @prunellejs/images; `false` disables)
|
|
189
205
|
const resolveImageFn = options.resolveImage === false
|