@dimm-city/print-md 0.5.0-rc.2 → 0.5.0-rc.3
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/cli.js
CHANGED
|
@@ -758,6 +758,15 @@ var init_images = __esm(() => {
|
|
|
758
758
|
PREFIX_PATTERNS = [/^(?:\.\/|\/)?temp\/images\//, /^(?:\.\/|\/)?images\//];
|
|
759
759
|
});
|
|
760
760
|
|
|
761
|
+
// ../lib/src/lib/markdown/chapter-id.ts
|
|
762
|
+
function canonicalChapterId(p) {
|
|
763
|
+
let s = String(p).replace(/\\/g, "/");
|
|
764
|
+
s = s.replace(/\/{2,}/g, "/");
|
|
765
|
+
while (s.startsWith("./"))
|
|
766
|
+
s = s.slice(2);
|
|
767
|
+
return s;
|
|
768
|
+
}
|
|
769
|
+
|
|
761
770
|
// ../lib/src/lib/markdown/plugins.ts
|
|
762
771
|
import { existsSync as existsSync2 } from "node:fs";
|
|
763
772
|
import { resolve as resolve2, join } from "node:path";
|
|
@@ -911,12 +920,13 @@ async function renderChapters(inputDir, opts = {}) {
|
|
|
911
920
|
}
|
|
912
921
|
let bodyContent = "";
|
|
913
922
|
for (const file of files) {
|
|
914
|
-
const
|
|
923
|
+
const chapterId = canonicalChapterId(file);
|
|
924
|
+
const filePath = join2(inputDir, chapterId);
|
|
915
925
|
try {
|
|
916
926
|
const content = await readFile2(filePath, "utf-8");
|
|
917
927
|
const rendered = md.render(content);
|
|
918
928
|
if (opts.wrapChapters) {
|
|
919
|
-
const safe =
|
|
929
|
+
const safe = chapterId.replace(/&/g, "&").replace(/"/g, """);
|
|
920
930
|
bodyContent += `<div class="pmd-chapter" data-chapter-src="${safe}">
|
|
921
931
|
${rendered}
|
|
922
932
|
</div>
|
|
@@ -22693,7 +22703,7 @@ var package_default;
|
|
|
22693
22703
|
var init_package = __esm(() => {
|
|
22694
22704
|
package_default = {
|
|
22695
22705
|
name: "@dimm-city/print-md-lib",
|
|
22696
|
-
version: "0.5.0-rc.
|
|
22706
|
+
version: "0.5.0-rc.3",
|
|
22697
22707
|
private: true,
|
|
22698
22708
|
type: "module",
|
|
22699
22709
|
main: "dist/index.js",
|
|
@@ -22950,7 +22960,7 @@ var pagedjs_bridge_default = "./pagedjs-bridge-k1a8jxtv.js";
|
|
|
22950
22960
|
var init_pagedjs_bridge = () => {};
|
|
22951
22961
|
|
|
22952
22962
|
// ../lib/src/assets/preview/scripts/preview-shell.js
|
|
22953
|
-
var preview_shell_default = "./preview-shell-
|
|
22963
|
+
var preview_shell_default = "./preview-shell-fx145xzs.js";
|
|
22954
22964
|
var init_preview_shell = () => {};
|
|
22955
22965
|
|
|
22956
22966
|
// ../lib/src/assets/vendor/paged.polyfill.js
|
|
@@ -93686,7 +93696,7 @@ function createFileWatcher(state) {
|
|
|
93686
93696
|
await generateAndWriteHtml(state.currentInputPath, state.tempDir, updatedConfig);
|
|
93687
93697
|
const only = dests.length === 1 ? dests[0] : null;
|
|
93688
93698
|
if (incrementalPreviewEnabled() && changes.length === 1 && only && only.ext === ".md" && only.event !== "unlink" && only.event !== "unlinkDir") {
|
|
93689
|
-
state.previewServer?.broadcastContentUpdate(only.relativePath);
|
|
93699
|
+
state.previewServer?.broadcastContentUpdate(canonicalChapterId(only.relativePath));
|
|
93690
93700
|
info(`Chapter updated: ${only.relativePath}`);
|
|
93691
93701
|
} else {
|
|
93692
93702
|
state.previewServer?.broadcastReload();
|
|
@@ -94519,7 +94529,6 @@ function capabilitiesFor(source) {
|
|
|
94519
94529
|
canSnapshot: false,
|
|
94520
94530
|
canViewHistory: false,
|
|
94521
94531
|
canRestoreSnapshot: false,
|
|
94522
|
-
canPublish: false,
|
|
94523
94532
|
canSync: false,
|
|
94524
94533
|
authManagedByApp: false
|
|
94525
94534
|
};
|
|
@@ -94531,7 +94540,6 @@ function capabilitiesFor(source) {
|
|
|
94531
94540
|
canSnapshot: true,
|
|
94532
94541
|
canViewHistory: true,
|
|
94533
94542
|
canRestoreSnapshot: true,
|
|
94534
|
-
canPublish: source.hasRemote,
|
|
94535
94543
|
canSync: source.hasRemote,
|
|
94536
94544
|
authManagedByApp: false
|
|
94537
94545
|
};
|
|
@@ -94543,7 +94551,6 @@ function capabilitiesFor(source) {
|
|
|
94543
94551
|
canSnapshot: true,
|
|
94544
94552
|
canViewHistory: true,
|
|
94545
94553
|
canRestoreSnapshot: true,
|
|
94546
|
-
canPublish: true,
|
|
94547
94554
|
canSync: true,
|
|
94548
94555
|
authManagedByApp: true
|
|
94549
94556
|
};
|
|
@@ -108156,9 +108163,9 @@ var init_diagnose = __esm(() => {
|
|
|
108156
108163
|
init_token_store();
|
|
108157
108164
|
});
|
|
108158
108165
|
|
|
108159
|
-
// ../lib/src/lib/remote-auth/
|
|
108166
|
+
// ../lib/src/lib/remote-auth/sync.ts
|
|
108160
108167
|
var import_diff3;
|
|
108161
|
-
var
|
|
108168
|
+
var init_sync = __esm(() => {
|
|
108162
108169
|
init_source_provider();
|
|
108163
108170
|
init_token_store();
|
|
108164
108171
|
import_diff3 = __toESM(require_diff3(), 1);
|
|
@@ -108179,7 +108186,7 @@ var init_api = __esm(() => {
|
|
|
108179
108186
|
init_test_access();
|
|
108180
108187
|
init_generic_auth();
|
|
108181
108188
|
init_diagnose();
|
|
108182
|
-
|
|
108189
|
+
init_sync();
|
|
108183
108190
|
});
|
|
108184
108191
|
|
|
108185
108192
|
// ../lib/src/index.ts
|
|
@@ -108840,7 +108847,7 @@ var SUBCOMMANDS = {
|
|
|
108840
108847
|
audit: () => Promise.resolve().then(() => (init_audit(), exports_audit)).then((m) => m.default),
|
|
108841
108848
|
preflight: () => Promise.resolve().then(() => (init_preflight(), exports_preflight)).then((m) => m.default)
|
|
108842
108849
|
};
|
|
108843
|
-
var VERSION = "0.5.0-rc.
|
|
108850
|
+
var VERSION = "0.5.0-rc.3";
|
|
108844
108851
|
var main = defineCommand8({
|
|
108845
108852
|
meta: {
|
|
108846
108853
|
name: "print-md",
|
|
@@ -102,6 +102,43 @@
|
|
|
102
102
|
return v ? v.split('\n') : [];
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// Canonical chapter id (inline copy of lib/markdown/chapter-id.ts — this
|
|
106
|
+
// file is plain embedded JS and cannot import the lib): forward slashes,
|
|
107
|
+
// no './' prefix, no duplicate slashes.
|
|
108
|
+
function normId(s) {
|
|
109
|
+
s = String(s || '').replace(/\\/g, '/').replace(/\/{2,}/g, '/');
|
|
110
|
+
while (s.indexOf('./') === 0) s = s.slice(2);
|
|
111
|
+
return s;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Every distinct chapter id present in the live view's page tags.
|
|
115
|
+
function liveChapterIds(d) {
|
|
116
|
+
var pages = d.querySelectorAll('.pagedjs_page'), ids = [], i, j;
|
|
117
|
+
for (i = 0; i < pages.length; i++) {
|
|
118
|
+
var list = pageChapters(pages[i]);
|
|
119
|
+
for (j = 0; j < list.length; j++) if (ids.indexOf(list[j]) === -1) ids.push(list[j]);
|
|
120
|
+
}
|
|
121
|
+
return ids;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Resolve a broadcast chapter id to the tag string actually used in the
|
|
125
|
+
// live view. Exact match first (the normal, canonical-everywhere case);
|
|
126
|
+
// then normalized match, then unique-basename match — defensive layers for
|
|
127
|
+
// a stale book.html tagged by an older build. Returns null when the chapter
|
|
128
|
+
// genuinely isn't in the live view (new file, or layout we can't resolve).
|
|
129
|
+
function resolveChapterId(d, file) {
|
|
130
|
+
var ids = liveChapterIds(d), i;
|
|
131
|
+
if (ids.indexOf(file) !== -1) return file;
|
|
132
|
+
var want = normId(file), hits = [];
|
|
133
|
+
for (i = 0; i < ids.length; i++) if (normId(ids[i]) === want) hits.push(ids[i]);
|
|
134
|
+
if (hits.length === 1) return hits[0];
|
|
135
|
+
if (!hits.length) {
|
|
136
|
+
var base = want.split('/').pop();
|
|
137
|
+
for (i = 0; i < ids.length; i++) if (normId(ids[i]).split('/').pop() === base) hits.push(ids[i]);
|
|
138
|
+
}
|
|
139
|
+
return hits.length === 1 ? hits[0] : null;
|
|
140
|
+
}
|
|
141
|
+
|
|
105
142
|
// Collect the live pages a chapter appears on: `owned` = every page that
|
|
106
143
|
// contains any of it (document order); `shared` = the subset it shares with
|
|
107
144
|
// another chapter (chapter starts or ends mid-page).
|
|
@@ -158,6 +195,20 @@
|
|
|
158
195
|
function spliceChapter(file) {
|
|
159
196
|
var anchor = capture(active);
|
|
160
197
|
tagPages(active);
|
|
198
|
+
// Presence check BEFORE rendering: if the chapter can't be located in the
|
|
199
|
+
// live view, the splice can never succeed — go straight to the full swap
|
|
200
|
+
// instead of paying a wasted single-chapter render first. The log carries
|
|
201
|
+
// both sides of the identity so any future mismatch is self-diagnosing.
|
|
202
|
+
var ad0 = fdoc(active);
|
|
203
|
+
var liveId = ad0 ? resolveChapterId(ad0, file) : null;
|
|
204
|
+
if (!liveId) {
|
|
205
|
+
var ids = ad0 ? liveChapterIds(ad0) : [];
|
|
206
|
+
var detail = 'broadcast "' + file + '" matched no live data-chapter-src tag (new file?); live tags: [' + ids.join(', ') + ']';
|
|
207
|
+
if (window.console) console.warn('[pmd] incremental splice skipped, full swap: ' + detail);
|
|
208
|
+
logToServer('splice skipped (full swap) for ' + file + ': ' + detail);
|
|
209
|
+
swap();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
161
212
|
var f = document.createElement('iframe'); f.style.visibility = 'hidden'; f.setAttribute('aria-hidden', 'true');
|
|
162
213
|
f.src = '/__chapter?file=' + encodeURIComponent(file) + '&t=' + Date.now();
|
|
163
214
|
f.addEventListener('load', function () {
|
|
@@ -165,7 +216,7 @@
|
|
|
165
216
|
try {
|
|
166
217
|
var ad = fdoc(active), sd = fdoc(f);
|
|
167
218
|
var container = ad.querySelector('.pagedjs_pages') || ad.body;
|
|
168
|
-
var found = pagesFor(ad,
|
|
219
|
+
var found = pagesFor(ad, liveId);
|
|
169
220
|
var newPages = [].slice.call(sd.querySelectorAll('.pagedjs_page'));
|
|
170
221
|
if (!newPages.length) throw new Error('chapter render produced no pages');
|
|
171
222
|
if (!found.owned.length) throw new Error('chapter not present in live view (new file?)');
|
|
@@ -198,9 +249,9 @@
|
|
|
198
249
|
for (i = 0; i < found.shared.length; i++) {
|
|
199
250
|
var frags = found.shared[i].querySelectorAll('.pmd-chapter[data-chapter-src]');
|
|
200
251
|
for (j = 0; j < frags.length; j++) {
|
|
201
|
-
if (frags[j].getAttribute('data-chapter-src') ===
|
|
252
|
+
if (frags[j].getAttribute('data-chapter-src') === liveId) frags[j].parentNode.removeChild(frags[j]);
|
|
202
253
|
}
|
|
203
|
-
var rest = pageChapters(found.shared[i]).filter(function (c) { return c !==
|
|
254
|
+
var rest = pageChapters(found.shared[i]).filter(function (c) { return c !== liveId; });
|
|
204
255
|
found.shared[i].setAttribute('data-chapter-srcs', rest.join('\n'));
|
|
205
256
|
if (rest.length) found.shared[i].setAttribute('data-chapter-src', rest[0]);
|
|
206
257
|
else found.shared[i].removeAttribute('data-chapter-src');
|
|
@@ -209,8 +260,8 @@
|
|
|
209
260
|
|
|
210
261
|
for (i = 0; i < newPages.length; i++) {
|
|
211
262
|
var imp = ad.importNode(newPages[i], true);
|
|
212
|
-
imp.setAttribute('data-chapter-src',
|
|
213
|
-
imp.setAttribute('data-chapter-srcs',
|
|
263
|
+
imp.setAttribute('data-chapter-src', liveId);
|
|
264
|
+
imp.setAttribute('data-chapter-srcs', liveId);
|
|
214
265
|
container.insertBefore(imp, at);
|
|
215
266
|
}
|
|
216
267
|
for (j = 0; j < exclusive.length; j++) exclusive[j].parentNode.removeChild(exclusive[j]);
|
package/package.json
CHANGED