@pretextbook/import 0.0.1 → 0.3.0
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/README.md +118 -121
- package/dist/import-mode-DK83Lfue.js +4214 -0
- package/dist/import-mode-vewAEq9k.cjs +95 -0
- package/dist/import.css +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +134 -101
- package/dist/lib/import-mode.d.ts +9 -1
- package/dist/lib/pool/division-pool.d.ts +1 -6
- package/dist/lib/pool/index.d.ts +1 -0
- package/dist/lib/pool/native-pool.d.ts +20 -0
- package/dist/lib/pool/refs.d.ts +39 -0
- package/dist/lib/pool/serialize-plus.d.ts +1 -6
- package/dist/lib/types.d.ts +38 -17
- package/dist/react/import-source-form.d.ts +1 -1
- package/dist/react/import-upload-panel.d.ts +1 -1
- package/dist/react/import-wizard.d.ts +25 -2
- package/dist/react/index.d.ts +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.js +372 -309
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +66 -63
- package/dist/import-mode-CSZlmUxw.cjs +0 -66
- package/dist/import-mode-iBDd9oQY.js +0 -3862
package/README.md
CHANGED
|
@@ -1,121 +1,118 @@
|
|
|
1
|
-
# @pretextbook/import
|
|
2
|
-
|
|
3
|
-
Shared helpers for importing existing source content into PreTeXt.
|
|
4
|
-
|
|
5
|
-
Two use cases:
|
|
6
|
-
|
|
7
|
-
- VS Code extension logic: format detection, cleaning, and conversion utilities.
|
|
8
|
-
- Web apps: React components for paste-or-upload import UX, plus a non-React
|
|
9
|
-
library entry point suitable for server-side or extension-host use.
|
|
10
|
-
|
|
11
|
-
The LaTeX cleaning pipeline is a TypeScript port of
|
|
12
|
-
[`davidfarmer/PreprocessLaTeX`](https://github.com/davidfarmer/PreprocessLaTeX)
|
|
13
|
-
(`src/main.js`'s `describeFiles` flow): drop comments, normalize whitespace,
|
|
14
|
-
expand `\input`/`\include`, rewrite plain-TeX font directives, scrub
|
|
15
|
-
presentation macros, and convert via `@pretextbook/latex-pretext`.
|
|
16
|
-
|
|
17
|
-
## Install
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
npm install @pretextbook/import
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Utilities
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import {
|
|
27
|
-
detectSourceFormat,
|
|
28
|
-
convertSourceToPretext,
|
|
29
|
-
importProjectFromFiles,
|
|
30
|
-
} from "@pretextbook/import";
|
|
31
|
-
|
|
32
|
-
const format = detectSourceFormat(rawInput);
|
|
33
|
-
const result = convertSourceToPretext(rawInput, format);
|
|
34
|
-
|
|
35
|
-
if ("pretextError" in result) {
|
|
36
|
-
console.error(result.pretextError);
|
|
37
|
-
} else {
|
|
38
|
-
console.log(result.pretextSource);
|
|
39
|
-
console.log(result.warnings); // cleaning diagnostics
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Multi-file project import (file paths -> source text):
|
|
43
|
-
const project = importProjectFromFiles({
|
|
44
|
-
"main.tex": "\\documentclass{article}\\begin{document}Hi.\\end{document}",
|
|
45
|
-
});
|
|
46
|
-
if ("outputFiles" in project) {
|
|
47
|
-
// Standard PreTeXt project layout, keyed by path:
|
|
48
|
-
console.log(project.outputFiles["source/main.ptx"]);
|
|
49
|
-
console.log(project.outputFiles["project.ptx"]);
|
|
50
|
-
console.log(project.outputFiles["publication/publication.ptx"]);
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Book splitting
|
|
55
|
-
|
|
56
|
-
If the converted source is a `<book>`, the layout splitter writes each
|
|
57
|
-
`<chapter>` to its own file under `source/`, and `source/main.ptx` is rebuilt
|
|
58
|
-
with `xi:include` references. Chapter filenames use `ch-<xml:id>.ptx` when an
|
|
59
|
-
`xml:id` is present, falling back to a zero-padded index. Pass
|
|
60
|
-
`splitSections: true` to additionally split each chapter by section.
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
importProjectFromFiles(files, {
|
|
64
|
-
documentKind: "book", // override auto-detect
|
|
65
|
-
splitSections: true,
|
|
66
|
-
});
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Upload pipeline
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
import { handleImportUploadFile } from "@pretextbook/import";
|
|
73
|
-
|
|
74
|
-
const result = await handleImportUploadFile(file);
|
|
75
|
-
if ("pretextError" in result) {
|
|
76
|
-
console.error(result.pretextError);
|
|
77
|
-
} else {
|
|
78
|
-
// Text files (the converted PreTeXt project + routed .bib auxiliaries)
|
|
79
|
-
for (const [path, content] of Object.entries(result.outputFiles)) {
|
|
80
|
-
saveOrUpload(path, content);
|
|
81
|
-
}
|
|
82
|
-
// Binary assets (images, PDFs, EPS) routed to source/assets/
|
|
83
|
-
for (const [path, bytes] of Object.entries(result.outputAssets)) {
|
|
84
|
-
saveBinary(path, bytes);
|
|
85
|
-
}
|
|
86
|
-
// Optional cleaned native source (LaTeX/Markdown), if the input was that format
|
|
87
|
-
if (result.nativeOutputFiles) {
|
|
88
|
-
for (const [path, content] of Object.entries(result.nativeOutputFiles)) {
|
|
89
|
-
saveOrUpload(path, content);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Supports `.tex`, `.md`, `.ptx`, `.xml`, `.zip`, and `.tar.gz` uploads. For zip
|
|
96
|
-
and tar.gz archives, the extractor identifies the main source file, expands
|
|
97
|
-
LaTeX `\input`/`\include` or PreTeXt `xi:include` references, and routes
|
|
98
|
-
binaries (`.png`, `.jpg`, `.pdf`, `.eps`, ...) into `source/assets/` and `.bib`
|
|
99
|
-
files into `source/`.
|
|
100
|
-
|
|
101
|
-
## React Components
|
|
102
|
-
|
|
103
|
-
```tsx
|
|
104
|
-
import {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
`ImportUploadPanel` exposes UI controls for the `documentKind` override and
|
|
120
|
-
`splitSections` toggle. Pass `importOptions={...}` to suppress those controls
|
|
121
|
-
and use a fixed configuration.
|
|
1
|
+
# @pretextbook/import
|
|
2
|
+
|
|
3
|
+
Shared helpers for importing existing source content into PreTeXt.
|
|
4
|
+
|
|
5
|
+
Two use cases:
|
|
6
|
+
|
|
7
|
+
- VS Code extension logic: format detection, cleaning, and conversion utilities.
|
|
8
|
+
- Web apps: React components for paste-or-upload import UX, plus a non-React
|
|
9
|
+
library entry point suitable for server-side or extension-host use.
|
|
10
|
+
|
|
11
|
+
The LaTeX cleaning pipeline is a TypeScript port of
|
|
12
|
+
[`davidfarmer/PreprocessLaTeX`](https://github.com/davidfarmer/PreprocessLaTeX)
|
|
13
|
+
(`src/main.js`'s `describeFiles` flow): drop comments, normalize whitespace,
|
|
14
|
+
expand `\input`/`\include`, rewrite plain-TeX font directives, scrub
|
|
15
|
+
presentation macros, and convert via `@pretextbook/latex-pretext`.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @pretextbook/import
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Utilities
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {
|
|
27
|
+
detectSourceFormat,
|
|
28
|
+
convertSourceToPretext,
|
|
29
|
+
importProjectFromFiles,
|
|
30
|
+
} from "@pretextbook/import";
|
|
31
|
+
|
|
32
|
+
const format = detectSourceFormat(rawInput);
|
|
33
|
+
const result = convertSourceToPretext(rawInput, format);
|
|
34
|
+
|
|
35
|
+
if ("pretextError" in result) {
|
|
36
|
+
console.error(result.pretextError);
|
|
37
|
+
} else {
|
|
38
|
+
console.log(result.pretextSource);
|
|
39
|
+
console.log(result.warnings); // cleaning diagnostics
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Multi-file project import (file paths -> source text):
|
|
43
|
+
const project = importProjectFromFiles({
|
|
44
|
+
"main.tex": "\\documentclass{article}\\begin{document}Hi.\\end{document}",
|
|
45
|
+
});
|
|
46
|
+
if ("outputFiles" in project) {
|
|
47
|
+
// Standard PreTeXt project layout, keyed by path:
|
|
48
|
+
console.log(project.outputFiles["source/main.ptx"]);
|
|
49
|
+
console.log(project.outputFiles["project.ptx"]);
|
|
50
|
+
console.log(project.outputFiles["publication/publication.ptx"]);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Book splitting
|
|
55
|
+
|
|
56
|
+
If the converted source is a `<book>`, the layout splitter writes each
|
|
57
|
+
`<chapter>` to its own file under `source/`, and `source/main.ptx` is rebuilt
|
|
58
|
+
with `xi:include` references. Chapter filenames use `ch-<xml:id>.ptx` when an
|
|
59
|
+
`xml:id` is present, falling back to a zero-padded index. Pass
|
|
60
|
+
`splitSections: true` to additionally split each chapter by section.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
importProjectFromFiles(files, {
|
|
64
|
+
documentKind: "book", // override auto-detect
|
|
65
|
+
splitSections: true,
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Upload pipeline
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { handleImportUploadFile } from "@pretextbook/import";
|
|
73
|
+
|
|
74
|
+
const result = await handleImportUploadFile(file);
|
|
75
|
+
if ("pretextError" in result) {
|
|
76
|
+
console.error(result.pretextError);
|
|
77
|
+
} else {
|
|
78
|
+
// Text files (the converted PreTeXt project + routed .bib auxiliaries)
|
|
79
|
+
for (const [path, content] of Object.entries(result.outputFiles)) {
|
|
80
|
+
saveOrUpload(path, content);
|
|
81
|
+
}
|
|
82
|
+
// Binary assets (images, PDFs, EPS) routed to source/assets/
|
|
83
|
+
for (const [path, bytes] of Object.entries(result.outputAssets)) {
|
|
84
|
+
saveBinary(path, bytes);
|
|
85
|
+
}
|
|
86
|
+
// Optional cleaned native source (LaTeX/Markdown), if the input was that format
|
|
87
|
+
if (result.nativeOutputFiles) {
|
|
88
|
+
for (const [path, content] of Object.entries(result.nativeOutputFiles)) {
|
|
89
|
+
saveOrUpload(path, content);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Supports `.tex`, `.md`, `.ptx`, `.xml`, `.zip`, and `.tar.gz` uploads. For zip
|
|
96
|
+
and tar.gz archives, the extractor identifies the main source file, expands
|
|
97
|
+
LaTeX `\input`/`\include` or PreTeXt `xi:include` references, and routes
|
|
98
|
+
binaries (`.png`, `.jpg`, `.pdf`, `.eps`, ...) into `source/assets/` and `.bib`
|
|
99
|
+
files into `source/`.
|
|
100
|
+
|
|
101
|
+
## React Components
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { ImportSourceForm, ImportUploadPanel } from "@pretextbook/import/react";
|
|
105
|
+
|
|
106
|
+
function ImportPanel() {
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<ImportSourceForm onImport={(r) => console.log(r)} />
|
|
110
|
+
<ImportUploadPanel onImport={(r) => console.log(r)} />
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`ImportUploadPanel` exposes UI controls for the `documentKind` override and
|
|
117
|
+
`splitSections` toggle. Pass `importOptions={...}` to suppress those controls
|
|
118
|
+
and use a fixed configuration.
|