@dita-viewer/core 0.2.0 → 0.2.2
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/LICENSE +21 -21
- package/README.md +90 -58
- package/dist/editor/renderContext.d.ts +7 -0
- package/dist/editor/renderContext.js +24 -0
- package/dist/editor/topicRender.d.ts +9 -0
- package/dist/editor/topicRender.js +4 -2
- package/dist/index.js +3 -3
- package/dist/language/ditaLanguageUtils.js +2 -0
- package/dist/profiling.d.ts +9 -3
- package/dist/profiling.js +12 -6
- package/dist/render/baseTypeMap.js +28 -2
- package/dist/render/mapTypeMap.js +23 -23
- package/dist/render/renderer.d.ts +24 -0
- package/dist/render/renderer.js +36 -9
- package/dist-esm/bookRender.js +145 -0
- package/dist-esm/completion.js +142 -0
- package/dist-esm/completionData.js +155 -0
- package/dist-esm/diagnostics.js +378 -0
- package/dist-esm/editor/conkeyref.js +104 -0
- package/dist-esm/editor/keySpace.js +201 -0
- package/dist-esm/editor/refResolvers.js +633 -0
- package/dist-esm/editor/renderContext.js +138 -0
- package/dist-esm/editor/sourceText.js +142 -0
- package/dist-esm/editor/topicRender.js +328 -0
- package/dist-esm/index.js +66 -0
- package/dist-esm/keyMapForDocument.js +23 -0
- package/dist-esm/language/ditaLanguageUtils.js +659 -0
- package/dist-esm/language/referenceableFiles.js +108 -0
- package/dist-esm/mapRender.js +24 -0
- package/dist-esm/package.json +1 -0
- package/dist-esm/parser/ditaParser.js +409 -0
- package/dist-esm/parser/domTypes.js +1 -0
- package/dist-esm/parser/mapTagMap.js +77 -0
- package/dist-esm/parser/namedEntities.js +321 -0
- package/dist-esm/parser/standardTagMap.js +393 -0
- package/dist-esm/profiling.js +224 -0
- package/dist-esm/render/baseTypeMap.js +1057 -0
- package/dist-esm/render/cjkSpacing.js +94 -0
- package/dist-esm/render/mapTypeMap.js +568 -0
- package/dist-esm/render/renderer.js +519 -0
- package/dist-esm/siteRender.js +261 -0
- package/package.json +55 -53
- package/styles/TOKENS.md +59 -38
- package/styles/dita-content.css +1171 -1157
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 aREversez
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aREversez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,58 +1,90 @@
|
|
|
1
|
-
# @dita-viewer/core
|
|
2
|
-
|
|
3
|
-
Host-neutral DITA parsing and HTML rendering
|
|
4
|
-
[VS Code DITA Viewer](https://github.com/aREversez/VS-Code-DITA-Viewer)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
| `src/
|
|
14
|
-
| `src/
|
|
15
|
-
| `src/index.ts` | New here. The public API
|
|
16
|
-
| `src/
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
npm
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
# @dita-viewer/core
|
|
2
|
+
|
|
3
|
+
Host-neutral DITA parsing and HTML rendering. It lives in the
|
|
4
|
+
[VS Code DITA Viewer](https://github.com/aREversez/VS-Code-DITA-Viewer)
|
|
5
|
+
repository, under `packages/core`, and is shared with
|
|
6
|
+
[obsidian-dita](https://github.com/aREversez/obsidian-dita), which installs it
|
|
7
|
+
from npm.
|
|
8
|
+
|
|
9
|
+
## What is in it
|
|
10
|
+
|
|
11
|
+
| Path | Origin |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `src/parser/`, `src/render/`, `src/editor/*.ts` | The extension's own parser, renderer and editor files. They were first copied from its `dev` at commit `596202d` into this package, and the extension deleted its copies when it switched to depend on it. Except `editor/topicRender.ts`, which is from the upstream change "move openHrefTarget out of topicRender" (it was identical before that, and the other files were checked identical to `dev` at `de5a237`). The 15 files in `parser/`, `render/` and `editor/` are exactly the transitive import closure of `renderTopicToHtml` and import nothing from `vscode`. |
|
|
14
|
+
| `src/language/ditaLanguageUtils.ts`, `src/language/referenceableFiles.ts` | The extension's files too (same commit): completion-context detection, tag-stack scanning, and the file walk behind `href` completion. Both are `vscode`-free. |
|
|
15
|
+
| `src/keyMapForDocument.ts`, `src/mapRender.ts`, `src/bookRender.ts`, `src/siteRender.ts`, `src/index.ts` | New here. The public API; the key-map lookup without the VS Code workspace features; `renderMapXml`, which sequences the copied map parser and renderer for a `.ditamap` outline; `renderBookXml` for the whole map on one page; and `renderSiteXml`, which renders one map topic at a time plus the sidebar manifest. |
|
|
16
|
+
| `src/profiling.ts` | New here. Conditional processing: read a `.ditaval`, read the profiling values of an element or of the renderer's `data-profile-keys`, decide whether an element stays (DITA-OT rules), list the values for a filter panel, and prune filtered entries from a parsed map. `renderBookXml` and `renderSiteXml` take it as `filter`. Informed by the VS Code viewer's `src/editor/ditaval.ts`, which only answers the exclusion question and is not a drop-in. |
|
|
17
|
+
| `src/index.ts` | New here. The public API. Besides the high-level `render*` functions it exports the parser and renderer entry points (`parseDita`, `parseDitamap`, `renderDocument`, ...) and the types they use, which is everything the VS Code viewer imports from the modules it copied; `test/publicApi.test.ts` pins that list. |
|
|
18
|
+
| `src/completion.ts`, `src/completionData.ts` | New here. Host-neutral completion engine (`complete(text, offset, env)`) and its tables: usual children per element (a ranking aid only, never a filter), enumerated attribute values, which attributes name files. |
|
|
19
|
+
| `styles/dita-content.css` | The topic-content, `.ditamap` outline-tree, and map page/site rules of the VS Code `media/styles.css`, with every `--vscode-*` replaced by a `--dita-*` host token. See the header comment for the complete list of differences. |
|
|
20
|
+
| `styles/TOKENS.md` | The contract between the stylesheet and a host. |
|
|
21
|
+
| `test/` | The upstream tests whose imports stay inside the 15 files (plus tests for completion, map rendering, book and site rendering), unchanged except for import paths. |
|
|
22
|
+
|
|
23
|
+
## Changing the shared files
|
|
24
|
+
|
|
25
|
+
This package is edited here. The extension imports it through the npm
|
|
26
|
+
workspace (`"@dita-viewer/core": "*"` links `packages/core`), so a change is in
|
|
27
|
+
the extension's next build with no release in between. obsidian-dita installs
|
|
28
|
+
a published version, so a change reaches it only after a release (see below).
|
|
29
|
+
The extension depends on the core as `*` on purpose: an exact version stops
|
|
30
|
+
matching the workspace after the first bump, and npm would then install the
|
|
31
|
+
published copy next to it.
|
|
32
|
+
|
|
33
|
+
The root scripts compile this package before anything that imports it
|
|
34
|
+
(`typecheck`, `build`, `test`, `test:visual`, `test:e2e`, `watch`), because the
|
|
35
|
+
extension reads its `dist/`. `npm run verify` also runs this package's own
|
|
36
|
+
tests. `npm run watch` compiles it once, at the start; after editing it while
|
|
37
|
+
watching, run `npm run build:core`.
|
|
38
|
+
|
|
39
|
+
The stylesheet is the same in both places apart from the host. The
|
|
40
|
+
extension's `media/styles.css` reads the same `--dita-*` tokens as
|
|
41
|
+
`styles/dita-content.css` in its content and outline rules, answered from VS
|
|
42
|
+
Code's theme in one `:root` block, and `src/test/media/hostTokens.test.ts`
|
|
43
|
+
fails when the set of tokens the two read drifts apart. What remains is that
|
|
44
|
+
the extension keeps its own copy of the rules; `dita-content.css` also holds the
|
|
45
|
+
Obsidian-only book and site rules the extension does not need.
|
|
46
|
+
|
|
47
|
+
## Two builds
|
|
48
|
+
|
|
49
|
+
`npm run build` writes `dist/` (CommonJS, with the type declarations) and
|
|
50
|
+
`dist-esm/` (the same modules as ES modules). `package.json` offers `dist-esm`
|
|
51
|
+
under the `module` condition of `exports`, which bundlers such as esbuild take
|
|
52
|
+
and Node ignores; Node, `require` and TypeScript get `dist/`. The point is size:
|
|
53
|
+
a bundler can leave out what the host does not import, which took about 43 KB
|
|
54
|
+
out of the extension's bundle (the site and book renderers, diagnostics and
|
|
55
|
+
completion, none of which it uses). `npm run check:core-pack` checks all three
|
|
56
|
+
paths: a Node `require`, a Node ES module `import`, and a bundler dropping the
|
|
57
|
+
modules it does not use. `dist-esm` is not meant for Node to load directly: its
|
|
58
|
+
relative imports have no file extensions.
|
|
59
|
+
|
|
60
|
+
## Publishing to npm
|
|
61
|
+
|
|
62
|
+
Releases are made by `.github/workflows/release-core.yml`, which publishes with
|
|
63
|
+
npm's OIDC trusted publishing: no npm token is stored anywhere.
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
# raise "version" in packages/core/package.json, commit, then:
|
|
67
|
+
git tag core-0.2.1 # the tag must be core-<the version in package.json>
|
|
68
|
+
git push --follow-tags
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
One-time setup, on npmjs.com: open the package `@dita-viewer/core`, then
|
|
72
|
+
Settings, Trusted Publisher, GitHub Actions, and enter owner `aREversez`,
|
|
73
|
+
repository `VS-Code-DITA-Viewer`, workflow filename `release-core.yml`. It
|
|
74
|
+
must match exactly, and the `repository` field of `package.json` must name the
|
|
75
|
+
same repository, or npm refuses the provenance.
|
|
76
|
+
|
|
77
|
+
To publish by hand instead:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
npm login # two-factor authentication is required
|
|
81
|
+
npm run verify
|
|
82
|
+
npm run check:core-pack # packs, installs the tarball into an empty project, requires it, type-checks it
|
|
83
|
+
cd packages/core
|
|
84
|
+
npm publish # publishConfig makes it public; prepublishOnly builds first
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
A published version can never be reused, so run `check:core-pack` before every
|
|
88
|
+
release. Until the host-token and selector gaps are closed, keep the version at
|
|
89
|
+
`0.x`: the exported surface is allowed to change. obsidian-dita pins the exact
|
|
90
|
+
version it was built against.
|
|
@@ -39,6 +39,13 @@ export interface BuildRenderContextInput {
|
|
|
39
39
|
suppressIndexterm?: boolean;
|
|
40
40
|
/** Book / docsite only: the set of files that make up the current book. */
|
|
41
41
|
bookMembers?: ReadonlySet<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Standalone preview only: render non-book cross-file xrefs as real links
|
|
44
|
+
* carrying data-dita-href for the webview to hand to the host (see
|
|
45
|
+
* RenderContext.clickableExternalXrefs). Every other render path leaves it
|
|
46
|
+
* unset and keeps the historical non-clickable hint span.
|
|
47
|
+
*/
|
|
48
|
+
clickableExternalXrefs?: boolean;
|
|
42
49
|
/** Book / site only: sink that records every file the render read. */
|
|
43
50
|
collectDependencies?: Set<string>;
|
|
44
51
|
}
|
|
@@ -72,6 +72,8 @@ function buildRenderContext(input) {
|
|
|
72
72
|
ctx.indexLabel = (0, refResolvers_1.detectIndexLabel)(ownRoot, uiLanguage);
|
|
73
73
|
if (input.bookMembers)
|
|
74
74
|
ctx.isInCurrentBook = (0, refResolvers_1.makeIsInCurrentBook)(docDir, input.bookMembers);
|
|
75
|
+
if (input.clickableExternalXrefs)
|
|
76
|
+
ctx.clickableExternalXrefs = true;
|
|
75
77
|
// conkeyref rides on the same file cache: a key's href resolves against the
|
|
76
78
|
// map that defined it (baseDir), not the topic being rendered, so it needs
|
|
77
79
|
// the absolute-path loader rather than the docDir-relative conref resolver.
|
|
@@ -79,6 +81,28 @@ function buildRenderContext(input) {
|
|
|
79
81
|
let lastLoaded;
|
|
80
82
|
const keyDefs = input.keyDefs ?? (0, keySpace_1.getKeyDefs)(keyMap);
|
|
81
83
|
if (keyDefs && keyDefs.size > 0) {
|
|
84
|
+
// A keyref on a link-shaped element (topic/xref) resolves to the key's
|
|
85
|
+
// resource target as its effective href. The keydef's href is relative
|
|
86
|
+
// to the map that defined it, but every href the renderer consumes
|
|
87
|
+
// (isInCurrentBook, resolveTitle, the preview's own open-by-href) is
|
|
88
|
+
// relative to the DOCUMENT's folder -- so rebase here, preserving any
|
|
89
|
+
// element-id fragment, and hand through the shapes that are not
|
|
90
|
+
// filesystem paths (URL schemes, absolute paths) untouched.
|
|
91
|
+
ctx.resolveKeyHref = (key) => {
|
|
92
|
+
const def = keyDefs.get(key);
|
|
93
|
+
if (!def?.href)
|
|
94
|
+
return undefined;
|
|
95
|
+
const raw = def.href;
|
|
96
|
+
if (refResolvers_1.URL_SCHEME_RE.test(raw) || (0, path_1.isAbsolute)(raw))
|
|
97
|
+
return raw;
|
|
98
|
+
const hashIdx = raw.indexOf('#');
|
|
99
|
+
const pathPart = hashIdx >= 0 ? raw.slice(0, hashIdx) : raw;
|
|
100
|
+
const fragment = hashIdx >= 0 ? raw.slice(hashIdx) : '';
|
|
101
|
+
if (!pathPart)
|
|
102
|
+
return fragment || undefined;
|
|
103
|
+
const abs = (0, path_1.resolve)(def.baseDir, (0, refResolvers_1.decodeHrefPart)(pathPart));
|
|
104
|
+
return (0, path_1.relative)(docDir, abs).replace(/\\/g, '/') + fragment;
|
|
105
|
+
};
|
|
82
106
|
const loadTopic = (baseDir, href) => {
|
|
83
107
|
const absPath = (0, path_1.resolve)(baseDir, (0, refResolvers_1.decodeHrefPart)(href.split('#')[0]));
|
|
84
108
|
// A conkeyref target is a real dependency of the rendered HTML, exactly
|
|
@@ -31,6 +31,8 @@ export interface TopicRenderInput {
|
|
|
31
31
|
collectDependencies?: Set<string>;
|
|
32
32
|
/** See TopicXmlRenderInput.bookMembers below; passed through untouched. */
|
|
33
33
|
bookMembers?: ReadonlySet<string>;
|
|
34
|
+
/** See TopicXmlRenderInput.clickableExternalXrefs below; passed through untouched. */
|
|
35
|
+
clickableExternalXrefs?: boolean;
|
|
34
36
|
/**
|
|
35
37
|
* Mark conref'd content for the preview's tint and jump button (see
|
|
36
38
|
* RenderContext.conrefSource). Off for "Export as HTML"; renderTopicCached,
|
|
@@ -70,6 +72,13 @@ export interface TopicXmlRenderInput {
|
|
|
70
72
|
* whole point here.
|
|
71
73
|
*/
|
|
72
74
|
bookMembers?: ReadonlySet<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Standalone preview only: render non-book cross-file xrefs as real links
|
|
77
|
+
* carrying data-dita-href for the webview to hand to the host (see
|
|
78
|
+
* RenderContext.clickableExternalXrefs). Undefined for book/site rendering
|
|
79
|
+
* and "Export as HTML", which keep the non-clickable xref-external hint.
|
|
80
|
+
*/
|
|
81
|
+
clickableExternalXrefs?: boolean;
|
|
73
82
|
/**
|
|
74
83
|
* Absolute path of the topic being rendered, and the opt-in that uses it:
|
|
75
84
|
* together they let the renderer mark conref'd content (same-file targets
|
|
@@ -48,7 +48,7 @@ function buildTitleMap(root) {
|
|
|
48
48
|
return map;
|
|
49
49
|
}
|
|
50
50
|
function renderTopicXml(input) {
|
|
51
|
-
const { xml, docDir, keyMap, asWebviewUri, headingLevel, uiLanguage, suppressIndexterm, collectDependencies, bookMembers, docFile, markConrefs } = input;
|
|
51
|
+
const { xml, docDir, keyMap, asWebviewUri, headingLevel, uiLanguage, suppressIndexterm, collectDependencies, bookMembers, clickableExternalXrefs, docFile, markConrefs } = input;
|
|
52
52
|
try {
|
|
53
53
|
const preprocessedXml = (0, ditaParser_1.preprocessEntities)(xml);
|
|
54
54
|
const ditaDoc = (0, ditaParser_1.parseDita)(preprocessedXml);
|
|
@@ -68,6 +68,7 @@ function renderTopicXml(input) {
|
|
|
68
68
|
includeIndexLabel: true,
|
|
69
69
|
suppressIndexterm,
|
|
70
70
|
bookMembers,
|
|
71
|
+
clickableExternalXrefs,
|
|
71
72
|
collectDependencies,
|
|
72
73
|
docFile,
|
|
73
74
|
markConrefs,
|
|
@@ -87,7 +88,7 @@ function renderTopicXml(input) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
function renderTopicToHtml(input) {
|
|
90
|
-
const { filePath, keyMap, asWebviewUri, headingLevel, uiLanguage, suppressIndexterm, collectDependencies, bookMembers, markConrefs } = input;
|
|
91
|
+
const { filePath, keyMap, asWebviewUri, headingLevel, uiLanguage, suppressIndexterm, collectDependencies, bookMembers, clickableExternalXrefs, markConrefs } = input;
|
|
91
92
|
try {
|
|
92
93
|
if (!(0, fs_1.existsSync)(filePath)) {
|
|
93
94
|
return { html: '', error: `File not found: ${filePath}` };
|
|
@@ -106,6 +107,7 @@ function renderTopicToHtml(input) {
|
|
|
106
107
|
suppressIndexterm,
|
|
107
108
|
collectDependencies,
|
|
108
109
|
bookMembers,
|
|
110
|
+
clickableExternalXrefs,
|
|
109
111
|
docFile: filePath,
|
|
110
112
|
markConrefs,
|
|
111
113
|
});
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Public surface of @dita-viewer/core.
|
|
3
3
|
//
|
|
4
4
|
// Hosts (the Obsidian plugin, and in time the VS Code extension) render DITA
|
|
5
|
-
// through these exports only.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// through these exports only. The VS Code DITA Viewer depends on this package
|
|
6
|
+
// and holds no copies of ./parser, ./render and ./editor (see README), so they
|
|
7
|
+
// are edited here and released as a new version.
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.renderMapDocument = exports.isDitamapRef = exports.getDisplayNameInfo = exports.extractText = exports.createBookRoleLabeler = exports.findTopLevelIndextermsInSubtree = exports.collectIndextermChips = exports.renderElement = exports.renderDocument = exports.MAP_STANDARD_TAG_TO_BASETYPE = exports.STANDARD_TAG_TO_BASETYPE = exports.preprocessEntities = exports.parseDitamap = exports.parseDita = exports.getMapTitleText = exports.collectMapEntries = exports.pruneExcluded = exports.profileValuesOfKeys = exports.profileValuesOf = exports.profileKey = exports.profileGroups = exports.parseDitaval = exports.isValueExcluded = exports.isExcluded = exports.isEmptyFilter = exports.ditavalAction = exports.PROFILE_ATTRS = exports.renderSiteXml = exports.renderBookXml = exports.renderMapXml = exports.offsetToLineCol = exports.collectRefEntries = exports.splitRefFragment = exports.collectIds = exports.IMAGE_EXT = exports.toRelativeHref = exports.collectReferenceableFiles = exports.collectDiagnostics = exports.complete = exports.buildKeySpaceForDocument = exports.buildKeyMapForDocument = exports.decodeHrefPart = exports.clearSourceOverlay = exports.setSourceOverlay = exports.readSourceText = exports.getKeyDefs = exports.buildKeySpace = exports.collectDitamapFilesUpward = exports.buildTitleMap = exports.renderTopicXml = void 0;
|
|
10
10
|
exports.findIdAttrAt = exports.findEnclosingKeydefKeys = exports.findConrefTargetOffset = exports.collectUnknownElements = exports.collectTopicSymbols = exports.collectMapSymbols = exports.topicRenderCacheSize = exports.topicRenderCacheBytesHeld = exports.stampFiles = exports.setTopicRenderCacheBudgetForTesting = exports.renderTopicToHtml = exports.renderTopicCached = exports.collectText = exports.clearTopicRenderCache = exports.TOPIC_RENDER_CACHE_MAX_BYTES = exports.trackSourceReads = exports.sourceStamp = exports.sourceOverlaySize = exports.noteSourceDependencies = exports.dependsOn = exports.clearAllSourceOverlays = exports.buildRenderContext = exports.readImageDimensions = exports.makeIsInCurrentBook = exports.makeFileTitleResolver = exports.makeFileCache = exports.makeConrefResolver = exports.makeConrefRangeResolver = exports.expandDitamapRefs = exports.detectNoteLabels = exports.detectIndexLabel = exports.clearImageDimensionsCache = exports.ZH_NOTE_LABELS = exports.URL_SCHEME_RE = exports.IMAGE_DIMENSIONS_CACHE_MAX = exports.DEFAULT_NOTE_LABELS = exports.qualifiedNamesMulti = exports.qualifiedNames = exports.keySourceMaps = exports.isKeyContextAvailable = exports.collectMapKeys = exports.resolveConkeyref = exports.profilingKeysAttr = exports.profilingChipsHtml = exports.mergeProfilingAttrs = exports.needsSpace = exports.computeKeyrefSpacing = exports.BASE_TYPE_RENDERERS = exports.lookupNamedEntity = exports.isExternalRef = void 0;
|
package/dist/profiling.d.ts
CHANGED
|
@@ -20,10 +20,16 @@ export interface ProfileFilter {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* The attributes the renderer records in data-profile-keys, in its order.
|
|
23
|
-
* Kept in step with PROFILING_ATTRS in render/renderer.ts (
|
|
24
|
-
*
|
|
23
|
+
* Kept in step with PROFILING_ATTRS in render/renderer.ts (not exported from
|
|
24
|
+
* there); a test renders each one to catch drift.
|
|
25
|
+
*
|
|
26
|
+
* deliveryTarget joins the filter-atts group: DITA 1.3 added it to the
|
|
27
|
+
* select-atts (it replaces the deprecated DITA 1.2 @print), and DITA-OT
|
|
28
|
+
* filters on it exactly like the rest of the group, so an element carrying
|
|
29
|
+
* it must show up highlighted, in the filter panel, and in .ditaval
|
|
30
|
+
* filtering like any other profiling attribute.
|
|
25
31
|
*/
|
|
26
|
-
export declare const PROFILE_ATTRS: readonly ["props", "platform", "product", "audience", "otherprops", "base", "importance", "rev", "status"];
|
|
32
|
+
export declare const PROFILE_ATTRS: readonly ["props", "platform", "product", "audience", "otherprops", "deliveryTarget", "base", "importance", "rev", "status"];
|
|
27
33
|
/** The key a hand-picked value is stored under. */
|
|
28
34
|
export declare function profileKey(att: string, value: string): string;
|
|
29
35
|
/** The profiling values an element's attributes carry. */
|
package/dist/profiling.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Conditional processing: which profiled content a .ditaval file, or a hand
|
|
3
3
|
// picked set of values, leaves out of a preview.
|
|
4
4
|
//
|
|
5
|
-
// Host-neutral and DOM-free. The renderer
|
|
5
|
+
// Host-neutral and DOM-free. The renderer
|
|
6
6
|
// already stamps every profiled element with `data-profile-keys`, a list of
|
|
7
7
|
// `attribute:value` pairs, and the stylesheet already hides anything carrying
|
|
8
8
|
// `.profile-filtered-out`. What was missing is the decision: does this
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// The rules follow DITA-OT's filtering, which is what a .ditaval is written
|
|
13
13
|
// for:
|
|
14
14
|
// - an element is judged attribute by attribute (audience, platform,
|
|
15
|
-
// product, otherprops, props, and any attribute
|
|
16
|
-
// `props="name(value ...)"`);
|
|
15
|
+
// product, otherprops, deliveryTarget, props, and any attribute
|
|
16
|
+
// generalised through `props="name(value ...)"`);
|
|
17
17
|
// - for one attribute it is left out only when EVERY one of its values is
|
|
18
18
|
// excluded -- `audience="internal admin"` stays if admin is not excluded;
|
|
19
19
|
// - it is left out when ANY attribute leaves it out;
|
|
@@ -39,10 +39,16 @@ exports.pruneExcluded = pruneExcluded;
|
|
|
39
39
|
const sax_1 = __importDefault(require("sax"));
|
|
40
40
|
/**
|
|
41
41
|
* The attributes the renderer records in data-profile-keys, in its order.
|
|
42
|
-
* Kept in step with PROFILING_ATTRS in render/renderer.ts (
|
|
43
|
-
*
|
|
42
|
+
* Kept in step with PROFILING_ATTRS in render/renderer.ts (not exported from
|
|
43
|
+
* there); a test renders each one to catch drift.
|
|
44
|
+
*
|
|
45
|
+
* deliveryTarget joins the filter-atts group: DITA 1.3 added it to the
|
|
46
|
+
* select-atts (it replaces the deprecated DITA 1.2 @print), and DITA-OT
|
|
47
|
+
* filters on it exactly like the rest of the group, so an element carrying
|
|
48
|
+
* it must show up highlighted, in the filter panel, and in .ditaval
|
|
49
|
+
* filtering like any other profiling attribute.
|
|
44
50
|
*/
|
|
45
|
-
exports.PROFILE_ATTRS = ['props', 'platform', 'product', 'audience', 'otherprops', 'base', 'importance', 'rev', 'status'];
|
|
51
|
+
exports.PROFILE_ATTRS = ['props', 'platform', 'product', 'audience', 'otherprops', 'deliveryTarget', 'base', 'importance', 'rev', 'status'];
|
|
46
52
|
/**
|
|
47
53
|
* Attributes a .ditaval never acts on: DITA-OT filters on audience, platform,
|
|
48
54
|
* product, otherprops, props and their specialisations only. The rest are
|
|
@@ -782,8 +782,25 @@ exports.BASE_TYPE_RENDERERS = {
|
|
|
782
782
|
'topic/pre': (_node, ctx, renderChildren) => `<pre class="pre preformatted">${renderChildren(_node, ctx)}</pre>`,
|
|
783
783
|
'topic/xref': (node, ctx, renderChildren) => {
|
|
784
784
|
const href = getAttr(node, 'href') || '';
|
|
785
|
-
|
|
786
|
-
|
|
785
|
+
// No target at all: an xref with neither @href nor a keyref that
|
|
786
|
+
// resolves to one. Dropping the element silently (the old behaviour)
|
|
787
|
+
// hid both the author's text and the broken reference; keeping it
|
|
788
|
+
// visible -- its own content when it has any, an unresolved-key hint
|
|
789
|
+
// when it does not (the same treatment topic/ph gives an unresolved
|
|
790
|
+
// keyref) -- means a broken xref reads as one instead of vanishing.
|
|
791
|
+
if (!href) {
|
|
792
|
+
if (node.children.length > 0) {
|
|
793
|
+
const content = renderChildren(node, ctx);
|
|
794
|
+
const keyref = getAttr(node, 'keyref');
|
|
795
|
+
return keyref
|
|
796
|
+
? `<span class="xref unresolved-keyref" title="Unresolved key: ${escapeAttr(keyref)}">${content}</span>`
|
|
797
|
+
: `<span class="xref">${content}</span>`;
|
|
798
|
+
}
|
|
799
|
+
const keyref = getAttr(node, 'keyref');
|
|
800
|
+
if (!keyref)
|
|
801
|
+
return '';
|
|
802
|
+
return `<span class="xref unresolved-keyref" title="Unresolved key: ${escapeAttr(keyref)}">[${escapeAttr(keyref)}]</span>`;
|
|
803
|
+
}
|
|
787
804
|
let content;
|
|
788
805
|
if (node.children.length > 0) {
|
|
789
806
|
content = renderChildren(node, ctx);
|
|
@@ -819,6 +836,15 @@ exports.BASE_TYPE_RENDERERS = {
|
|
|
819
836
|
const target = bookTarget + (anchorId ? '#' + anchorId : '');
|
|
820
837
|
return `<a href="#" class="xref" data-dita-book-xref="${escapeAttr(target)}">${content}</a>`;
|
|
821
838
|
}
|
|
839
|
+
// Standalone preview opt-in (clickableExternalXrefs, no book context):
|
|
840
|
+
// keep the target's own href and let the webview hand it to the host,
|
|
841
|
+
// which opens DITA targets in their preview and everything else in the
|
|
842
|
+
// right place (see openHrefTarget) -- instead of the dead hint span.
|
|
843
|
+
// Without the opt-in (export, diff, book/site, the second host) the
|
|
844
|
+
// historical non-clickable hint below is kept exactly as it was.
|
|
845
|
+
if (ctx.clickableExternalXrefs) {
|
|
846
|
+
return `<a href="#" class="xref" data-dita-href="${escapeAttr(href)}">${content}</a>`;
|
|
847
|
+
}
|
|
822
848
|
return `<span class="xref-external">→ ${content}</span>`;
|
|
823
849
|
},
|
|
824
850
|
'topic/link': (node, ctx, renderChildren) => {
|
|
@@ -292,16 +292,16 @@ function renderRef(node, ctx, renderChildren) {
|
|
|
292
292
|
const keyAttr = safeAttr('data-keys', keys);
|
|
293
293
|
const hrefAttr = href ? safeAttr('data-href', href) : '';
|
|
294
294
|
if (nav) {
|
|
295
|
-
return `<li class="map-tree-item map-tree-item--nav${boxClass}" role="treeitem"${keyAttr}${hrefAttr}${profileAttr}>
|
|
296
|
-
<a href="#" class="map-tree-link" data-href="${escapeAttr(href)}">${icon}${badge}<span class="map-tree-label">${nameAttr}</span></a>
|
|
297
|
-
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
298
|
-
${profileLabel}
|
|
295
|
+
return `<li class="map-tree-item map-tree-item--nav${boxClass}" role="treeitem"${keyAttr}${hrefAttr}${profileAttr}>
|
|
296
|
+
<a href="#" class="map-tree-link" data-href="${escapeAttr(href)}">${icon}${badge}<span class="map-tree-label">${nameAttr}</span></a>
|
|
297
|
+
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
298
|
+
${profileLabel}
|
|
299
299
|
</li>`;
|
|
300
300
|
}
|
|
301
|
-
return `<li class="map-tree-item map-tree-item--keydef${boxClass}" role="treeitem"${keyAttr}${hrefAttr}${profileAttr}>
|
|
302
|
-
${icon}${badge}<span class="map-tree-label map-tree-label--keydef">${nameAttr}</span>
|
|
303
|
-
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
304
|
-
${profileLabel}
|
|
301
|
+
return `<li class="map-tree-item map-tree-item--keydef${boxClass}" role="treeitem"${keyAttr}${hrefAttr}${profileAttr}>
|
|
302
|
+
${icon}${badge}<span class="map-tree-label map-tree-label--keydef">${nameAttr}</span>
|
|
303
|
+
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
304
|
+
${profileLabel}
|
|
305
305
|
</li>`;
|
|
306
306
|
}
|
|
307
307
|
/**
|
|
@@ -337,9 +337,9 @@ const MAP_BASE_TYPE_RENDERERS = {
|
|
|
337
337
|
.filter((c) => c.type === 'element')
|
|
338
338
|
.map((c) => renderChildren(c, bodyCtx))
|
|
339
339
|
.join('');
|
|
340
|
-
return `<div class="ditamap-container">
|
|
341
|
-
${titleHtml}
|
|
342
|
-
<ul class="map-tree" role="tree" aria-label="${escapeAttr(ctx.treeLabel || 'Document outline')}">${bodyHtml}</ul>
|
|
340
|
+
return `<div class="ditamap-container">
|
|
341
|
+
${titleHtml}
|
|
342
|
+
<ul class="map-tree" role="tree" aria-label="${escapeAttr(ctx.treeLabel || 'Document outline')}">${bodyHtml}</ul>
|
|
343
343
|
</div>`;
|
|
344
344
|
},
|
|
345
345
|
'map/map-title': (node, ctx, _renderChildren) => `<h1 class="map-title">${escapeAttr(extractText(node, ctx.resolveKey))}</h1>`,
|
|
@@ -352,10 +352,10 @@ const MAP_BASE_TYPE_RENDERERS = {
|
|
|
352
352
|
const profileKeys = (0, renderer_1.profilingKeysAttr)(effectiveProfiling);
|
|
353
353
|
const profileAttr = profileKeys ? safeAttr('data-profile-keys', profileKeys) : '';
|
|
354
354
|
const { boxClass, label: profileLabel } = ownProfilingMarkup(node);
|
|
355
|
-
return `<li class="map-tree-item map-tree-item--head${boxClass}" role="treeitem"${profileAttr}>
|
|
356
|
-
<span class="map-tree-label map-tree-label--head">${escapeAttr(displayName)}</span>
|
|
357
|
-
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
358
|
-
${profileLabel}
|
|
355
|
+
return `<li class="map-tree-item map-tree-item--head${boxClass}" role="treeitem"${profileAttr}>
|
|
356
|
+
<span class="map-tree-label map-tree-label--head">${escapeAttr(displayName)}</span>
|
|
357
|
+
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
358
|
+
${profileLabel}
|
|
359
359
|
</li>`;
|
|
360
360
|
},
|
|
361
361
|
'map/topicgroup': (node, ctx, renderChildren) => {
|
|
@@ -368,8 +368,8 @@ const MAP_BASE_TYPE_RENDERERS = {
|
|
|
368
368
|
// grouping), so it isn't a distinct treeitem -- role="group" alone,
|
|
369
369
|
// wrapping its children as if they were direct siblings of whatever
|
|
370
370
|
// contains this topicgroup.
|
|
371
|
-
return `<li class="map-tree-item map-tree-item--group" role="none">
|
|
372
|
-
<ul class="map-tree" role="group">${childrenHtml}</ul>
|
|
371
|
+
return `<li class="map-tree-item map-tree-item--group" role="none">
|
|
372
|
+
<ul class="map-tree" role="group">${childrenHtml}</ul>
|
|
373
373
|
</li>`;
|
|
374
374
|
},
|
|
375
375
|
'map/bookmap-structural': (node, ctx, renderChildren) => {
|
|
@@ -384,18 +384,18 @@ const MAP_BASE_TYPE_RENDERERS = {
|
|
|
384
384
|
const profileKeys = (0, renderer_1.profilingKeysAttr)(effectiveProfiling);
|
|
385
385
|
const profileAttr = profileKeys ? safeAttr('data-profile-keys', profileKeys) : '';
|
|
386
386
|
const { boxClass, label: profileLabel } = ownProfilingMarkup(node);
|
|
387
|
-
return `<li class="map-tree-item map-tree-item--structural${boxClass}" role="treeitem"${profileAttr}>
|
|
388
|
-
<span class="map-tree-label map-tree-label--structural">${escapeAttr(displayName)}</span>
|
|
389
|
-
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
390
|
-
${profileLabel}
|
|
387
|
+
return `<li class="map-tree-item map-tree-item--structural${boxClass}" role="treeitem"${profileAttr}>
|
|
388
|
+
<span class="map-tree-label map-tree-label--structural">${escapeAttr(displayName)}</span>
|
|
389
|
+
${childrenHtml ? `<ul class="map-tree" role="group">${childrenHtml}</ul>` : ''}
|
|
390
|
+
${profileLabel}
|
|
391
391
|
</li>`;
|
|
392
392
|
},
|
|
393
393
|
'map/keydef': renderRef,
|
|
394
394
|
'map/reltable': (node, ctx, renderChildren) => {
|
|
395
395
|
const relbody = node.children.filter((c) => c.type === 'element' && (c.baseType === 'map/relheader' || c.baseType === 'map/relrow'));
|
|
396
396
|
const bodyHtml = relbody.map((c) => renderChildren(c, ctx)).join('');
|
|
397
|
-
return `<div class="map-reltable"><h2 class="map-reltable-title">Related Information</h2>
|
|
398
|
-
<table class="map-reltable-table"><tbody>${bodyHtml}</tbody></table>
|
|
397
|
+
return `<div class="map-reltable"><h2 class="map-reltable-title">Related Information</h2>
|
|
398
|
+
<table class="map-reltable-table"><tbody>${bodyHtml}</tbody></table>
|
|
399
399
|
</div>`;
|
|
400
400
|
},
|
|
401
401
|
'map/relheader': (node, ctx) => {
|
|
@@ -86,6 +86,30 @@ export interface RenderContext {
|
|
|
86
86
|
* MapViewerProvider) keeps showing chips exactly as before.
|
|
87
87
|
*/
|
|
88
88
|
suppressIndexterm?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Resolves a @keyref to the key's resource href ("other.dita#topic"),
|
|
91
|
+
* relative to the document being rendered, or undefined when the key
|
|
92
|
+
* defines no resource (a text-only key) or is not defined at all. Only
|
|
93
|
+
* link-shaped elements consume it (topic/xref): resolveKeyrefForNode
|
|
94
|
+
* copies the key's target onto the element's effective @href so
|
|
95
|
+
* `<xref keyref="k"/>` renders as a real link, exactly as DITA-OT
|
|
96
|
+
* resolves the same markup. The href is the caller's responsibility to
|
|
97
|
+
* make document-relative -- a keydef's href is relative to the map that
|
|
98
|
+
* defined it, and only the caller building this closure knows that
|
|
99
|
+
* directory (see buildRenderContext).
|
|
100
|
+
*/
|
|
101
|
+
resolveKeyHref?: (key: string) => string | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Opt-in for the standalone single-topic preview: cross-file xrefs whose
|
|
104
|
+
* target is NOT part of a book (no isInCurrentBook context) render as a
|
|
105
|
+
* real <a> carrying the raw href in data-dita-href, which the preview's
|
|
106
|
+
* webview script hands to the extension host to open (another topic's
|
|
107
|
+
* preview, a ditamap, a web page). Without this flag the renderer keeps
|
|
108
|
+
* the historical non-clickable <span class="xref-external"> hint --
|
|
109
|
+
* "Export as HTML", the diff view, book/site rendering and the second
|
|
110
|
+
* host all stay byte-identical (a test locks each of those shapes).
|
|
111
|
+
*/
|
|
112
|
+
clickableExternalXrefs?: boolean;
|
|
89
113
|
/**
|
|
90
114
|
* Resolves a cross-file xref's raw href to an absolute path IF the
|
|
91
115
|
* referenced topic is part of the book/docsite this topic is itself
|