@writedocs/generator 0.22.0 → 0.22.1
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/astro.config.mjs
CHANGED
|
@@ -44,6 +44,7 @@ import { readMovedApiPages } from './src/lib/moved-api-pages.js';
|
|
|
44
44
|
import { rehypeImageLoading } from './src/lib/rehype-image-loading.js';
|
|
45
45
|
import { rehypeBasePath } from './src/lib/rehype-base-path.js';
|
|
46
46
|
import { rehypeTaskLists } from './src/lib/rehype-task-lists.js';
|
|
47
|
+
import { rehypeTableScroll } from './src/lib/rehype-table-scroll.js';
|
|
47
48
|
import { gitLastModified, newestDate } from './src/lib/last-modified.js';
|
|
48
49
|
import { readSpecPaths } from './src/lib/project-files.js';
|
|
49
50
|
import { protectedPages } from './src/lib/protected-sections.js';
|
|
@@ -540,10 +541,13 @@ export default defineConfig({
|
|
|
540
541
|
// lib/rehype-image-loading.js.
|
|
541
542
|
// rehypeTaskLists: `- [ ] item` boxes a reader can tick - see
|
|
542
543
|
// lib/rehype-task-lists.js.
|
|
544
|
+
// rehypeTableScroll: every table in a scrolling wrapper, so a wide one
|
|
545
|
+
// scrolls sideways instead of spilling over the table of contents -
|
|
546
|
+
// see lib/rehype-table-scroll.js.
|
|
543
547
|
// rehypeBasePath: the basePath in front of the content's own links and
|
|
544
548
|
// pictures (lib/rehype-base-path.js) - last, since rehypeImageLoading
|
|
545
549
|
// finds an image's file by the address as written.
|
|
546
|
-
rehypePlugins: [rehypeMermaid, rehypeKatex, [rehypeImageLoading, { contentDir }], rehypeTaskLists, [rehypeBasePath, { base: basePath }]],
|
|
550
|
+
rehypePlugins: [rehypeMermaid, rehypeKatex, [rehypeImageLoading, { contentDir }], rehypeTaskLists, rehypeTableScroll, [rehypeBasePath, { base: basePath }]],
|
|
547
551
|
}),
|
|
548
552
|
shikiConfig: {
|
|
549
553
|
themes: codeblockTheme,
|
package/package.json
CHANGED
|
@@ -5,13 +5,14 @@ import { extraClasses } from './class-names';
|
|
|
5
5
|
// that live-filters rows by their own text content - "let users filter
|
|
6
6
|
// the content inside the wrapper" per the request that spawned this.
|
|
7
7
|
//
|
|
8
|
-
// A markdown table
|
|
9
|
-
//
|
|
8
|
+
// A markdown table normally lands at the top level of .wd-article (in
|
|
9
|
+
// the writedocs generator, inside a .wd-table-wrap scroll box - see
|
|
10
|
+
// [...slug].astro's own comment on this at its `<style is:global>`
|
|
10
11
|
// block), which is what its own global table CSS rule
|
|
11
|
-
// (`.wd-article > table`) deliberately targets - once
|
|
12
|
-
// component's own .wd-searchbar-content div, that table is
|
|
13
|
-
//
|
|
14
|
-
// matching it. Rather than loosening that combinator sitewide (it's
|
|
12
|
+
// (`.wd-article > .wd-table-wrap > table`) deliberately targets - once
|
|
13
|
+
// wrapped in this component's own .wd-searchbar-content div, that table is
|
|
14
|
+
// no longer at the top level of .wd-article, so that rule's ">" combinators
|
|
15
|
+
// stop matching it. Rather than loosening that combinator sitewide (it's
|
|
15
16
|
// intentionally direct-child-only - see its own comment for why), the
|
|
16
17
|
// exact same declarations are duplicated here, scoped to
|
|
17
18
|
// .wd-searchbar-content instead, so a wrapped table still renders
|
|
@@ -81,8 +82,9 @@ const { placeholder = "Search..." } = Astro.props as Props;
|
|
|
81
82
|
outline: none;
|
|
82
83
|
border-color: var(--wd-primary);
|
|
83
84
|
}
|
|
84
|
-
/* Matches .wd-article > table's own global styling
|
|
85
|
-
file's own top comment for why it has to be
|
|
85
|
+
/* Matches .wd-article > .wd-table-wrap > table's own global styling
|
|
86
|
+
exactly (see this file's own top comment for why it has to be
|
|
87
|
+
duplicated here rather
|
|
86
88
|
than reused directly) - width/border-collapse/font-size on the
|
|
87
89
|
table itself, cell padding/border/alignment on th and td, and the
|
|
88
90
|
muted uppercase treatment on th. :global() throughout since slot
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Wide tables scroll sideways inside their own box.
|
|
2
|
+
//
|
|
3
|
+
// A <table> can't scroll by itself without losing its table layout (with
|
|
4
|
+
// `display: block` it stops filling the column), and left alone a table wider
|
|
5
|
+
// than the article spills out over the table of contents beside it. So every
|
|
6
|
+
// table in a page is wrapped in `<div class="wd-table-wrap">`, which has
|
|
7
|
+
// `overflow-x: auto` ([...slug].astro's global styles): a table that fits
|
|
8
|
+
// still fills the column, one that doesn't scrolls inside the wrapper.
|
|
9
|
+
//
|
|
10
|
+
// Both kinds of table are wrapped: a Markdown one (a hast `table` element) and
|
|
11
|
+
// one written as JSX in an .mdx page (`<table>` - an `mdxJsxFlowElement`).
|
|
12
|
+
// A table already directly inside a wrapper isn't wrapped again.
|
|
13
|
+
|
|
14
|
+
export const TABLE_WRAP_CLASS = 'wd-table-wrap';
|
|
15
|
+
|
|
16
|
+
const isTable = (node) =>
|
|
17
|
+
(node?.type === 'element' && node.tagName === 'table') ||
|
|
18
|
+
(node?.type === 'mdxJsxFlowElement' && node.name === 'table');
|
|
19
|
+
|
|
20
|
+
const isWrap = (node) =>
|
|
21
|
+
node?.type === 'element' && node.tagName === 'div' && [].concat(node.properties?.className ?? []).includes(TABLE_WRAP_CLASS);
|
|
22
|
+
|
|
23
|
+
export function rehypeTableScroll() {
|
|
24
|
+
return (tree) => {
|
|
25
|
+
const visit = (node) => {
|
|
26
|
+
if (!Array.isArray(node.children)) return;
|
|
27
|
+
node.children = node.children.map((child) => {
|
|
28
|
+
visit(child);
|
|
29
|
+
if (!isTable(child) || isWrap(node)) return child;
|
|
30
|
+
return { type: 'element', tagName: 'div', properties: { className: [TABLE_WRAP_CLASS] }, children: [child] };
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
visit(tree);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -1440,10 +1440,22 @@ const components = {
|
|
|
1440
1440
|
.wd-article blockquote p {
|
|
1441
1441
|
margin: 0.7rem 0;
|
|
1442
1442
|
}
|
|
1443
|
-
.wd-
|
|
1443
|
+
/* Every table in a page sits in a .wd-table-wrap (lib/rehype-table-
|
|
1444
|
+
scroll.js): a table wider than the column scrolls sideways inside it
|
|
1445
|
+
instead of spilling over the table of contents. A table that fits still
|
|
1446
|
+
fills the column (width: 100%). Only the wrapper of a top-level table
|
|
1447
|
+
gets the spacing and the table styles - a table inside a component
|
|
1448
|
+
keeps that component's own (Searchbar's, for one). */
|
|
1449
|
+
.wd-article .wd-table-wrap {
|
|
1450
|
+
max-width: 100%;
|
|
1451
|
+
overflow-x: auto;
|
|
1452
|
+
}
|
|
1453
|
+
.wd-article > .wd-table-wrap {
|
|
1454
|
+
margin: 1.25rem 0;
|
|
1455
|
+
}
|
|
1456
|
+
.wd-article > .wd-table-wrap > table {
|
|
1444
1457
|
width: 100%;
|
|
1445
1458
|
border-collapse: collapse;
|
|
1446
|
-
margin: 1.25rem 0;
|
|
1447
1459
|
font-size: 0.9rem;
|
|
1448
1460
|
}
|
|
1449
1461
|
.wd-article th,
|