@brillout/docpress 0.15.10 → 0.15.11-commit-e615832
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/Layout.tsx +3 -0
- package/autoScrollNav.ts +3 -3
- package/code-blocks/components/CodeSnippets.css +74 -0
- package/code-blocks/components/CodeSnippets.tsx +51 -0
- package/code-blocks/components/Pre.css +51 -0
- package/code-blocks/components/Pre.tsx +70 -0
- package/code-blocks/hooks/useMDXComponents.tsx +13 -0
- package/code-blocks/hooks/useSelectCodeLang.ts +74 -0
- package/code-blocks/rehypeMetaToProps.ts +69 -0
- package/code-blocks/remarkDetype.ts +192 -0
- package/code-blocks/shikiTransformerAutoLinks.ts +61 -0
- package/css/button.css +23 -0
- package/css/code.css +3 -21
- package/css/tooltip.css +10 -2
- package/dist/+config.js +1 -1
- package/dist/NavItemComponent.js +38 -46
- package/dist/code-blocks/rehypeMetaToProps.d.ts +35 -0
- package/dist/code-blocks/rehypeMetaToProps.js +62 -0
- package/dist/code-blocks/remarkDetype.d.ts +4 -0
- package/dist/code-blocks/remarkDetype.js +164 -0
- package/dist/code-blocks/shikiTransformerAutoLinks.d.ts +8 -0
- package/dist/code-blocks/shikiTransformerAutoLinks.js +51 -0
- package/dist/components/CodeBlockTransformer.js +2 -3
- package/dist/components/Comment.js +1 -2
- package/dist/components/FileRemoved.js +4 -6
- package/dist/components/HorizontalLine.js +1 -2
- package/dist/components/ImportMeta.js +2 -3
- package/dist/components/Link.js +34 -50
- package/dist/components/Note.js +17 -29
- package/dist/components/P.js +1 -12
- package/dist/components/RepoLink.js +7 -9
- package/dist/determineNavItemsColumnLayout.js +48 -63
- package/dist/parseMarkdownMini.js +5 -17
- package/dist/parsePageSections.js +41 -82
- package/dist/renderer/usePageContext.js +6 -7
- package/dist/resolvePageContext.js +103 -110
- package/dist/utils/Emoji/Emoji.js +13 -21
- package/dist/utils/assert.js +14 -16
- package/dist/utils/cls.js +1 -1
- package/dist/utils/determineSectionUrlHash.js +5 -5
- package/dist/utils/filter.js +2 -2
- package/dist/utils/getGlobalObject.js +3 -3
- package/dist/vite.config.js +17 -7
- package/index.ts +16 -14
- package/package.json +7 -2
- package/resolvePageContext.ts +19 -15
- package/tsconfig.json +2 -1
- package/vite.config.ts +14 -4
package/dist/utils/assert.js
CHANGED
|
@@ -2,8 +2,8 @@ export { assert };
|
|
|
2
2
|
export { assertUsage };
|
|
3
3
|
export { assertWarning };
|
|
4
4
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const devModeKey = '__docpress_dev_mode';
|
|
6
|
+
const globalObject = getGlobalObject('utils/assert.ts', {
|
|
7
7
|
alreadyLogged: new Set(),
|
|
8
8
|
});
|
|
9
9
|
if (isBrowser()) {
|
|
@@ -18,7 +18,7 @@ if (isBrowser()) {
|
|
|
18
18
|
.join(' '));
|
|
19
19
|
}
|
|
20
20
|
if (isDevMode()) {
|
|
21
|
-
window.onerror =
|
|
21
|
+
window.onerror = (err) => {
|
|
22
22
|
window.alert(err);
|
|
23
23
|
window.onerror = null;
|
|
24
24
|
};
|
|
@@ -27,25 +27,25 @@ function assert(condition, debugInfo) {
|
|
|
27
27
|
if (condition) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
const hasDebugInfo = debugInfo !== undefined;
|
|
31
31
|
if (hasDebugInfo) {
|
|
32
32
|
console.log(debugInfo);
|
|
33
33
|
if (typeof debugInfo === 'object') {
|
|
34
34
|
debugInfo = JSON.stringify(debugInfo);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
let errMsg = '[DocPress] Bug. Contact DocPress maintainer.';
|
|
38
38
|
if (hasDebugInfo) {
|
|
39
39
|
errMsg += ' Debug info: ' + String(debugInfo);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
const err = new Error(errMsg);
|
|
42
42
|
throw err;
|
|
43
43
|
}
|
|
44
44
|
function assertUsage(condition, msg) {
|
|
45
45
|
if (condition) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
const err = new Error('[DocPress][Wrong Usage] ' + msg);
|
|
49
49
|
throw err;
|
|
50
50
|
}
|
|
51
51
|
function isBrowser() {
|
|
@@ -55,34 +55,32 @@ function isDevMode() {
|
|
|
55
55
|
return isBrowser() && (!!window.localStorage[devModeKey] || isLocalhost());
|
|
56
56
|
}
|
|
57
57
|
function isLocalhost() {
|
|
58
|
-
|
|
59
|
-
return ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.port) !== '';
|
|
58
|
+
return window?.location?.port !== '';
|
|
60
59
|
}
|
|
61
60
|
function toggleDevMode() {
|
|
62
61
|
if (isLocalhost())
|
|
63
62
|
throw new Error('On localhost DEV MODE is always on.');
|
|
64
|
-
|
|
63
|
+
const isEnabled = () => window.localStorage[devModeKey];
|
|
65
64
|
if (!isEnabled()) {
|
|
66
65
|
window.localStorage[devModeKey] = 'true';
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
69
68
|
delete window.localStorage[devModeKey];
|
|
70
69
|
}
|
|
71
|
-
console.log(
|
|
70
|
+
console.log(`DEV MODE ${isEnabled() ? 'enabled' : 'disabled'}`);
|
|
72
71
|
}
|
|
73
|
-
function assertWarning(condition, msg,
|
|
74
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.onlyOnce, onlyOnce = _c === void 0 ? true : _c, showStackTrace = _b.showStackTrace;
|
|
72
|
+
function assertWarning(condition, msg, { onlyOnce = true, showStackTrace } = {}) {
|
|
75
73
|
if (condition) {
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
const err = new Error(msg);
|
|
79
77
|
if (!import.meta.env.DEV) {
|
|
80
78
|
throw err;
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
81
|
if (onlyOnce) {
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
const { alreadyLogged } = globalObject;
|
|
83
|
+
const key = onlyOnce === true ? msg : onlyOnce;
|
|
86
84
|
if (alreadyLogged.has(key))
|
|
87
85
|
return;
|
|
88
86
|
alreadyLogged.add(key);
|
package/dist/utils/cls.js
CHANGED
|
@@ -4,7 +4,7 @@ export { determineSectionTitle };
|
|
|
4
4
|
function determineSectionUrlHash(title) {
|
|
5
5
|
title = title.toLowerCase();
|
|
6
6
|
title = removeAccentsAndDiacritics(title);
|
|
7
|
-
|
|
7
|
+
const urlHash = title
|
|
8
8
|
// \u4E00-\u9FA5 are chinese characters, see https://github.com/brillout/docpress/pull/2
|
|
9
9
|
.split(/[^a-z0-9\u4E00-\u9FA5]+/)
|
|
10
10
|
.filter(Boolean)
|
|
@@ -20,11 +20,11 @@ function removeAccentsAndDiacritics(str) {
|
|
|
20
20
|
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
21
21
|
}
|
|
22
22
|
function determineSectionTitle(urlWithHash) {
|
|
23
|
-
assert(urlWithHash.includes('#'), { urlWithHash
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
assert(urlWithHash.includes('#'), { urlWithHash });
|
|
24
|
+
const urlHash = urlWithHash.split('#')[1];
|
|
25
|
+
const title = urlHash
|
|
26
26
|
.split('-')
|
|
27
|
-
.map(
|
|
27
|
+
.map((word, i) => {
|
|
28
28
|
if (i === 0) {
|
|
29
29
|
return capitalizeFirstLetter(word);
|
|
30
30
|
}
|
package/dist/utils/filter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { filter };
|
|
2
2
|
// https://stackoverflow.com/questions/66341757/typescript-how-to-filter-the-object
|
|
3
3
|
function filter(obj, predicate) {
|
|
4
|
-
|
|
5
|
-
Object.keys(obj).forEach(
|
|
4
|
+
const result = {};
|
|
5
|
+
Object.keys(obj).forEach((name) => {
|
|
6
6
|
if (predicate(obj[name], name)) {
|
|
7
7
|
result[name] = obj[name];
|
|
8
8
|
}
|
|
@@ -2,8 +2,8 @@ export function getGlobalObject(
|
|
|
2
2
|
// We use the filename as key; each `getGlobalObject()` call should live inside a file with a unique filename.
|
|
3
3
|
key, defaultValue) {
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const globalObjectsAll = (globalThis[projectKey] = globalThis[projectKey] || {});
|
|
6
|
+
const globalObject = (globalObjectsAll[key] = globalObjectsAll[key] || defaultValue);
|
|
7
7
|
return globalObject;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
const projectKey = '_docpress';
|
package/dist/vite.config.js
CHANGED
|
@@ -5,15 +5,25 @@ import { parsePageSections } from './parsePageSections.js';
|
|
|
5
5
|
import rehypePrettyCode from 'rehype-pretty-code';
|
|
6
6
|
import remarkGfm from 'remark-gfm';
|
|
7
7
|
import { transformerNotationDiff } from '@shikijs/transformers';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
import { rehypeMetaToProps } from './code-blocks/rehypeMetaToProps.js';
|
|
9
|
+
import { remarkDetype } from './code-blocks/remarkDetype.js';
|
|
10
|
+
import { shikiTransformerAutoLinks } from './code-blocks/shikiTransformerAutoLinks.js';
|
|
11
|
+
const root = process.cwd();
|
|
12
|
+
const prettyCode = [
|
|
13
|
+
rehypePrettyCode,
|
|
14
|
+
{
|
|
15
|
+
theme: 'github-light',
|
|
16
|
+
keepBackground: false,
|
|
17
|
+
transformers: [transformerNotationDiff(), shikiTransformerAutoLinks()],
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
const rehypePlugins = [prettyCode, [rehypeMetaToProps]];
|
|
21
|
+
const remarkPlugins = [remarkGfm, remarkDetype];
|
|
22
|
+
const config = {
|
|
23
|
+
root,
|
|
14
24
|
plugins: [
|
|
15
25
|
parsePageSections(),
|
|
16
|
-
mdx({ rehypePlugins
|
|
26
|
+
mdx({ rehypePlugins, remarkPlugins, providerImportSource: '@brillout/docpress' }),
|
|
17
27
|
// @vitejs/plugin-react-swc needs to be added *after* the mdx plugins
|
|
18
28
|
react(),
|
|
19
29
|
],
|
package/index.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
FileRemoved,
|
|
7
|
-
ImportMeta,
|
|
8
|
-
Emoji,
|
|
9
|
-
} from './components'
|
|
1
|
+
/**********/
|
|
2
|
+
/* PUBLIC */
|
|
3
|
+
/**********/
|
|
4
|
+
export { CodeBlockTransformer, Link, RepoLink, FileAdded, FileRemoved, ImportMeta, Emoji } from './components'
|
|
5
|
+
export { TypescriptOnly } from './code-blocks/components/CodeSnippets'
|
|
10
6
|
export { MenuToggle } from './Layout'
|
|
11
|
-
|
|
12
|
-
// The only place usePageContext() is used at:
|
|
13
|
-
// https://github.com/vikejs/vike/blob/0b1b109f64aafbed23a1c2ac2630e6146a270ec0/packages/vike.dev/components/CommunityNote.tsx#L4
|
|
14
|
-
export { usePageContext } from './renderer/usePageContext'
|
|
15
|
-
|
|
16
7
|
export * from './components/Note'
|
|
17
8
|
export * from './icons/index'
|
|
18
9
|
export { assert } from './utils/assert'
|
|
19
10
|
export { parseMarkdownMini } from './parseMarkdownMini'
|
|
20
11
|
export type { Config } from './types/Config'
|
|
21
12
|
export type { HeadingDefinition, HeadingDetachedDefinition } from './types/Heading'
|
|
13
|
+
// The only place usePageContext() is used at:
|
|
14
|
+
// https://github.com/vikejs/vike/blob/0b1b109f64aafbed23a1c2ac2630e6146a270ec0/packages/vike.dev/components/CommunityNote.tsx#L4
|
|
15
|
+
export { usePageContext } from './renderer/usePageContext'
|
|
16
|
+
|
|
17
|
+
// The following are used internally by DocPress — users (should) never use these exports
|
|
18
|
+
/************/
|
|
19
|
+
/* INTERNAL */
|
|
20
|
+
/************/
|
|
21
|
+
// We provide our own `useMDXComponents()` to enable MDX component injection by setting `providerImportSource` to '@brillout/docpress'.
|
|
22
|
+
// https://mdxjs.com/guides/injecting-components/
|
|
23
|
+
export { useMDXComponents } from './code-blocks/hooks/useMDXComponents'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brillout/docpress",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.11-commit-e615832",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@brillout/picocolors": "^1.0.10",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"@mdx-js/rollup": "3.0.1",
|
|
12
12
|
"@shikijs/transformers": "1.2.0",
|
|
13
13
|
"@vitejs/plugin-react-swc": "^3.10.2",
|
|
14
|
+
"detype": "^1.1.3",
|
|
14
15
|
"rehype-pretty-code": "0.13.0",
|
|
15
16
|
"remark-gfm": "4.0.0",
|
|
16
17
|
"shiki": "1.2.0",
|
|
18
|
+
"unist-util-visit": "^5.0.0",
|
|
17
19
|
"vite": "^6.3.5"
|
|
18
20
|
},
|
|
19
21
|
"peerDependencies": {
|
|
@@ -58,9 +60,12 @@
|
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
62
|
"@brillout/release-me": "^0.4.8",
|
|
63
|
+
"@types/hast": "^3.0.4",
|
|
64
|
+
"@types/mdast": "^4.0.4",
|
|
61
65
|
"@types/node": "^22.5.5",
|
|
62
66
|
"@types/react": "^18.3.8",
|
|
63
|
-
"@types/react-dom": "^18.3.0"
|
|
67
|
+
"@types/react-dom": "^18.3.0",
|
|
68
|
+
"mdast-util-mdx-jsx": "^3.2.0"
|
|
64
69
|
},
|
|
65
70
|
"repository": "https://github.com/brillout/docpress",
|
|
66
71
|
"license": "MIT",
|
package/resolvePageContext.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
HeadingDetachedResolved,
|
|
14
14
|
StringArray,
|
|
15
15
|
} from './types/Heading'
|
|
16
|
-
import { assert } from './utils/assert'
|
|
16
|
+
import { assert, assertUsage } from './utils/assert'
|
|
17
17
|
import { jsxToTextContent } from './utils/jsxToTextContent'
|
|
18
18
|
import pc from '@brillout/picocolors'
|
|
19
19
|
import { parseMarkdownMini } from './parseMarkdownMini'
|
|
@@ -149,6 +149,16 @@ function getActiveHeading(
|
|
|
149
149
|
headingsDetachedResolved: HeadingDetachedResolved[],
|
|
150
150
|
urlPathname: string,
|
|
151
151
|
) {
|
|
152
|
+
const URLs =
|
|
153
|
+
'\n' +
|
|
154
|
+
[...headingsResolved, ...headingsDetachedResolved]
|
|
155
|
+
.filter(Boolean)
|
|
156
|
+
.map((h) => h.url)
|
|
157
|
+
.sort()
|
|
158
|
+
.map((url) => ` ${url}`)
|
|
159
|
+
.join('\n')
|
|
160
|
+
const errNotFound = `URL ${pc.bold(urlPathname)} not found in following URLs:${URLs}`
|
|
161
|
+
const errFoundTwice = `URL ${pc.bold(urlPathname)} found twice in following URLs:${URLs}`
|
|
152
162
|
let activeHeading: HeadingResolved | HeadingDetachedResolved | null = null
|
|
153
163
|
let activeCategoryName = 'Miscellaneous'
|
|
154
164
|
let headingCategory: string | undefined
|
|
@@ -158,6 +168,7 @@ function getActiveHeading(
|
|
|
158
168
|
headingCategory = heading.title
|
|
159
169
|
}
|
|
160
170
|
if (heading.url === urlPathname) {
|
|
171
|
+
assertUsage(!activeHeading, errFoundTwice)
|
|
161
172
|
activeHeading = heading
|
|
162
173
|
assert(headingCategory)
|
|
163
174
|
activeCategoryName = headingCategory
|
|
@@ -167,21 +178,14 @@ function getActiveHeading(
|
|
|
167
178
|
}
|
|
168
179
|
const isDetachedPage = !activeHeading
|
|
169
180
|
if (!activeHeading) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
[
|
|
175
|
-
|
|
176
|
-
[...headingsResolved, ...headingsDetachedResolved]
|
|
177
|
-
.filter(Boolean)
|
|
178
|
-
.map((h) => h.url)
|
|
179
|
-
.sort()
|
|
180
|
-
.map((url) => ` ${url}`)
|
|
181
|
-
.join('\n'),
|
|
182
|
-
].join('\n'),
|
|
183
|
-
)
|
|
181
|
+
const found = headingsDetachedResolved.filter(({ url }) => urlPathname === url)
|
|
182
|
+
if (found.length > 0) {
|
|
183
|
+
assertUsage(found.length === 1, errFoundTwice)
|
|
184
|
+
assertUsage(!activeHeading, errFoundTwice)
|
|
185
|
+
activeHeading = found[0]!
|
|
186
|
+
}
|
|
184
187
|
}
|
|
188
|
+
assertUsage(activeHeading, errNotFound)
|
|
185
189
|
if (activeHeading.category) activeCategoryName = activeHeading.category
|
|
186
190
|
return { activeHeading, isDetachedPage, activeCategoryName }
|
|
187
191
|
}
|
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -7,17 +7,27 @@ import { parsePageSections } from './parsePageSections.js'
|
|
|
7
7
|
import rehypePrettyCode from 'rehype-pretty-code'
|
|
8
8
|
import remarkGfm from 'remark-gfm'
|
|
9
9
|
import { transformerNotationDiff } from '@shikijs/transformers'
|
|
10
|
+
import { rehypeMetaToProps } from './code-blocks/rehypeMetaToProps.js'
|
|
11
|
+
import { remarkDetype } from './code-blocks/remarkDetype.js'
|
|
12
|
+
import { shikiTransformerAutoLinks } from './code-blocks/shikiTransformerAutoLinks.js'
|
|
10
13
|
|
|
11
14
|
const root = process.cwd()
|
|
12
|
-
const prettyCode = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const prettyCode = [
|
|
16
|
+
rehypePrettyCode,
|
|
17
|
+
{
|
|
18
|
+
theme: 'github-light',
|
|
19
|
+
keepBackground: false,
|
|
20
|
+
transformers: [transformerNotationDiff(), shikiTransformerAutoLinks()],
|
|
21
|
+
},
|
|
22
|
+
]
|
|
23
|
+
const rehypePlugins: any = [prettyCode, [rehypeMetaToProps]]
|
|
24
|
+
const remarkPlugins = [remarkGfm, remarkDetype]
|
|
15
25
|
|
|
16
26
|
const config: UserConfig = {
|
|
17
27
|
root,
|
|
18
28
|
plugins: [
|
|
19
29
|
parsePageSections(),
|
|
20
|
-
mdx({ rehypePlugins, remarkPlugins }) as PluginOption,
|
|
30
|
+
mdx({ rehypePlugins, remarkPlugins, providerImportSource: '@brillout/docpress' }) as PluginOption,
|
|
21
31
|
// @vitejs/plugin-react-swc needs to be added *after* the mdx plugins
|
|
22
32
|
react(),
|
|
23
33
|
],
|