@bendyline/squisq-formats 1.2.3 → 1.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/dist/__tests__/html.test.js +78 -4
- package/dist/__tests__/html.test.js.map +1 -1
- package/dist/__tests__/pdfExport.test.js +1 -1
- package/dist/__tests__/pdfExport.test.js.map +1 -1
- package/dist/__tests__/plainHtml.test.d.ts +5 -0
- package/dist/__tests__/plainHtml.test.d.ts.map +1 -0
- package/dist/__tests__/plainHtml.test.js +327 -0
- package/dist/__tests__/plainHtml.test.js.map +1 -0
- package/dist/__tests__/plainHtmlBundle.test.d.ts +11 -0
- package/dist/__tests__/plainHtmlBundle.test.d.ts.map +1 -0
- package/dist/__tests__/plainHtmlBundle.test.js +210 -0
- package/dist/__tests__/plainHtmlBundle.test.js.map +1 -0
- package/dist/chunk-33YRFXZZ.js +1187 -0
- package/dist/chunk-33YRFXZZ.js.map +1 -0
- package/dist/{chunk-EUQQYBZZ.js → chunk-ERZ627GR.js} +4 -4
- package/dist/chunk-ERZ627GR.js.map +1 -0
- package/dist/{chunk-MEZF76JA.js → chunk-UDS45KUJ.js} +68 -25
- package/dist/chunk-UDS45KUJ.js.map +1 -0
- package/dist/{chunk-NGWHV77G.js → chunk-VN2KEOYB.js} +7 -6
- package/dist/chunk-VN2KEOYB.js.map +1 -0
- package/dist/docx/export.d.ts.map +1 -1
- package/dist/docx/export.js +153 -22
- package/dist/docx/export.js.map +1 -1
- package/dist/epub/export.js +3 -3
- package/dist/epub/export.js.map +1 -1
- package/dist/html/docsHtmlBundle.d.ts +53 -0
- package/dist/html/docsHtmlBundle.d.ts.map +1 -0
- package/dist/html/docsHtmlBundle.js +299 -0
- package/dist/html/docsHtmlBundle.js.map +1 -0
- package/dist/html/htmlTemplate.d.ts.map +1 -1
- package/dist/html/htmlTemplate.js +43 -0
- package/dist/html/htmlTemplate.js.map +1 -1
- package/dist/html/index.d.ts +6 -0
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +31 -3
- package/dist/html/index.js.map +1 -1
- package/dist/html/plainHtml.d.ts +79 -0
- package/dist/html/plainHtml.d.ts.map +1 -0
- package/dist/html/plainHtml.js +614 -0
- package/dist/html/plainHtml.js.map +1 -0
- package/dist/html/plainHtmlBundle.d.ts +93 -0
- package/dist/html/plainHtmlBundle.d.ts.map +1 -0
- package/dist/html/plainHtmlBundle.js +357 -0
- package/dist/html/plainHtmlBundle.js.map +1 -0
- package/dist/pptx/export.d.ts.map +1 -1
- package/dist/pptx/export.js +10 -8
- package/dist/pptx/export.js.map +1 -1
- package/package.json +3 -2
- package/src/__tests__/html.test.ts +82 -4
- package/src/__tests__/pdfExport.test.ts +1 -1
- package/src/__tests__/plainHtml.test.ts +372 -0
- package/src/__tests__/plainHtmlBundle.test.ts +235 -0
- package/src/docx/export.ts +163 -22
- package/src/epub/export.ts +3 -3
- package/src/html/docsHtmlBundle.ts +369 -0
- package/src/html/htmlTemplate.ts +40 -0
- package/src/html/index.ts +32 -3
- package/src/html/plainHtml.ts +736 -0
- package/src/html/plainHtmlBundle.ts +419 -0
- package/src/pptx/export.ts +10 -9
- package/dist/chunk-EUQQYBZZ.js.map +0 -1
- package/dist/chunk-MEZF76JA.js.map +0 -1
- package/dist/chunk-NGWHV77G.js.map +0 -1
- package/dist/chunk-UM5V2XZG.js +0 -242
- package/dist/chunk-UM5V2XZG.js.map +0 -1
package/dist/html/index.js
CHANGED
|
@@ -31,6 +31,22 @@
|
|
|
31
31
|
import JSZip from 'jszip';
|
|
32
32
|
import { generateInlineHtml, generateExternalHtml, } from './htmlTemplate.js';
|
|
33
33
|
import { extractFilename } from './imageUtils.js';
|
|
34
|
+
/**
|
|
35
|
+
* Normalize a doc-referenced path for use as a zip entry name. Strips
|
|
36
|
+
* leading slashes and rejects any path that tries to escape the archive
|
|
37
|
+
* root via `..` segments (a malicious or malformed doc shouldn't be able
|
|
38
|
+
* to write outside the zip when extracted). Backslashes are folded to
|
|
39
|
+
* forward slashes so Windows-authored paths still produce a consistent
|
|
40
|
+
* tree across extractors.
|
|
41
|
+
*/
|
|
42
|
+
function sanitizeZipPath(path) {
|
|
43
|
+
const normalized = path.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
44
|
+
if (!normalized)
|
|
45
|
+
return null;
|
|
46
|
+
if (normalized.split('/').some((seg) => seg === '..'))
|
|
47
|
+
return null;
|
|
48
|
+
return normalized;
|
|
49
|
+
}
|
|
34
50
|
// ── Single HTML Export ─────────────────────────────────────────────
|
|
35
51
|
/**
|
|
36
52
|
* Export a Doc as a single, self-contained HTML file.
|
|
@@ -93,12 +109,21 @@ export async function docToHtmlZip(doc, options) {
|
|
|
93
109
|
const zip = new JSZip();
|
|
94
110
|
// 1. Add player JS as a separate file
|
|
95
111
|
zip.file('squisq-player.js', playerScript);
|
|
96
|
-
// 2. Add images
|
|
112
|
+
// 2. Add images preserving their original relative paths.
|
|
113
|
+
//
|
|
114
|
+
// We used to flatten everything into `images/<basename>`, but that
|
|
115
|
+
// requires the player to rewrite every `<img src>` at render time using
|
|
116
|
+
// the path map — and the static (non-slideshow) renderer doesn't do
|
|
117
|
+
// that, so its emitted `<img>` tags 404'd against the renamed assets.
|
|
118
|
+
// Keeping the original layout means direct `src="folder/file.png"`
|
|
119
|
+
// references just work, and the exported zip mirrors how the source
|
|
120
|
+
// folder is organized (e.g. pandoc-style `notes_files/` sidecars).
|
|
97
121
|
const imagePathMap = {};
|
|
98
122
|
if (images) {
|
|
99
123
|
for (const [originalPath, buffer] of images.entries()) {
|
|
100
|
-
const
|
|
101
|
-
|
|
124
|
+
const zipPath = sanitizeZipPath(originalPath);
|
|
125
|
+
if (!zipPath)
|
|
126
|
+
continue;
|
|
102
127
|
zip.file(zipPath, buffer);
|
|
103
128
|
imagePathMap[originalPath] = zipPath;
|
|
104
129
|
}
|
|
@@ -135,4 +160,7 @@ export async function docToHtmlZip(doc, options) {
|
|
|
135
160
|
// ── Re-exports ─────────────────────────────────────────────────────
|
|
136
161
|
export { collectImagePaths } from './htmlTemplate.js';
|
|
137
162
|
export { inferMimeType, arrayBufferToBase64DataUrl, extractFilename } from './imageUtils.js';
|
|
163
|
+
export { markdownDocToPlainHtml } from './plainHtml.js';
|
|
164
|
+
export { markdownDocsToPlainHtmlBundle, collectLinkRefs } from './plainHtmlBundle.js';
|
|
165
|
+
export { markdownDocsToHtmlBundle } from './docsHtmlBundle.js';
|
|
138
166
|
//# sourceMappingURL=index.js.map
|
package/dist/html/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/html/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/html/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAMlD;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChE,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7B,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC;QAAE,OA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sB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain HTML Export — semantic, player-free
|
|
3
|
+
*
|
|
4
|
+
* Renders a MarkdownDocument to a self-contained HTML string. Unlike
|
|
5
|
+
* `docToHtml` (which bundles the SquisqPlayer IIFE and renders SVG block
|
|
6
|
+
* cards), this output is what a reader-mode tool would produce: semantic
|
|
7
|
+
* `<h1>`/`<p>`/`<ul>`/etc. with a small embedded stylesheet, no JS, no
|
|
8
|
+
* runtime path-rewriting. Drives both the "Page" preview tab in the
|
|
9
|
+
* editor and the plain-style branch of the export dialog so what users
|
|
10
|
+
* see live matches the file they download.
|
|
11
|
+
*
|
|
12
|
+
* Image URLs default to the markdown's own paths. Pass `images` to
|
|
13
|
+
* substitute a different value per source URL — typically pre-resolved
|
|
14
|
+
* blob URLs (live preview) or data URIs (single-file export).
|
|
15
|
+
*/
|
|
16
|
+
import type { MarkdownDocument } from '@bendyline/squisq/markdown';
|
|
17
|
+
import type { Theme } from '@bendyline/squisq/schemas';
|
|
18
|
+
export interface PlainHtmlExportOptions {
|
|
19
|
+
/** Document title — populates `<title>` and is HTML-escaped. */
|
|
20
|
+
title?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Substitution map for image `src` URLs. Keys are the URL exactly as
|
|
23
|
+
* it appears in the markdown source; values are the URL to emit in
|
|
24
|
+
* the rendered `<img src>`. URLs not present in the map fall through
|
|
25
|
+
* unchanged (so external `https://…` references still work).
|
|
26
|
+
*/
|
|
27
|
+
images?: Map<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Substitution map for anchor `href` URLs. Keys are the URL exactly
|
|
30
|
+
* as it appears in the markdown source (e.g. `'resume.md'`,
|
|
31
|
+
* `'resume.md#experience'`); values are the URL to emit. URLs not in
|
|
32
|
+
* the map pass through unchanged. Used by the recursive bundle
|
|
33
|
+
* exporter to rewrite `.md` references to `.html` so a static export
|
|
34
|
+
* of a linked document tree is internally browsable.
|
|
35
|
+
*/
|
|
36
|
+
links?: Map<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* Optional Squisq theme. When provided, the rendered page uses the
|
|
39
|
+
* theme's colors and typography, and any Google-hosted fonts the
|
|
40
|
+
* theme references are loaded via a `<link>` to fonts.googleapis.com
|
|
41
|
+
* so the face renders correctly without host preloads.
|
|
42
|
+
*
|
|
43
|
+
* When omitted, the function falls back (in order) to {@link themeId}
|
|
44
|
+
* and then to `doc.frontmatter.themeId` — so an authored
|
|
45
|
+
* `themeId: warm-earth` in the doc's frontmatter styles the export
|
|
46
|
+
* automatically, without the caller having to wire theme resolution
|
|
47
|
+
* themselves.
|
|
48
|
+
*/
|
|
49
|
+
theme?: Theme;
|
|
50
|
+
/**
|
|
51
|
+
* Optional theme id (e.g. `'warm-earth'`, `'gezellig'`). Convenient
|
|
52
|
+
* for hosts whose export dialog tracks themes by id — they can pass
|
|
53
|
+
* the id straight through instead of resolving to a `Theme` object.
|
|
54
|
+
* When both `theme` and `themeId` are provided, `theme` wins.
|
|
55
|
+
*/
|
|
56
|
+
themeId?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Optional FontAwesome CSS text to inline into the rendered page,
|
|
59
|
+
* replacing the default cross-origin `<link>` to cdnjs. Required for
|
|
60
|
+
* sandboxed iframe previews where tracking prevention or stricter
|
|
61
|
+
* origin policies can silently drop cross-origin font fetches —
|
|
62
|
+
* inlining keeps the icons resolvable purely from same-origin
|
|
63
|
+
* resources. Hosts typically gather this string by scraping
|
|
64
|
+
* `document.styleSheets` for `@font-face` rules whose family starts
|
|
65
|
+
* with `"Font Awesome"`. The CDN `<link>` is only emitted when this
|
|
66
|
+
* option is not provided.
|
|
67
|
+
*/
|
|
68
|
+
iconsCss?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Render a parsed markdown document as a complete, semantic HTML page.
|
|
72
|
+
*
|
|
73
|
+
* When `options.theme` is provided, the output adopts the theme's
|
|
74
|
+
* colors and typography. Google-hosted fonts referenced by the theme
|
|
75
|
+
* are loaded via a single `<link>` to fonts.googleapis.com so the page
|
|
76
|
+
* renders consistently when opened standalone.
|
|
77
|
+
*/
|
|
78
|
+
export declare function markdownDocToPlainHtml(doc: MarkdownDocument, options?: PlainHtmlExportOptions): string;
|
|
79
|
+
//# sourceMappingURL=plainHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plainHtml.d.ts","sourceRoot":"","sources":["../../src/html/plainHtml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,4BAA4B,CAAC;AAC3F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAKvD,MAAM,WAAW,sBAAsB;IACrC,gEAAgE;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAcD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,sBAA2B,GACnC,MAAM,CA0CR"}
|