orz-mdhtml 0.1.1 → 0.1.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/assets/app.js +39 -6
- package/dist/cli.js +1 -0
- package/package.json +1 -1
package/assets/app.js
CHANGED
|
@@ -63,11 +63,15 @@
|
|
|
63
63
|
+ '<article class="markdown-body" id="orz-doc"></article>'
|
|
64
64
|
+ '<script src="' + f.hljsJs + '"><\/script>'
|
|
65
65
|
+ '<script src="' + f.mermaidJs + '"><\/script>'
|
|
66
|
+
+ '<script src="' + f.smilesJs + '"><\/script>'
|
|
66
67
|
+ '<script>try{mermaid.initialize({startOnLoad:false})}catch(e){}<\/script>'
|
|
67
68
|
+ '<script>' + guard(CFG.runtime) + '<\/script>'
|
|
68
69
|
+ '<script>window.__orzEnhance=function(){'
|
|
69
70
|
+ 'try{if(window.hljs){document.querySelectorAll("#orz-doc pre code:not(.hljs)").forEach(function(b){window.hljs.highlightElement(b)})}}catch(e){}'
|
|
70
71
|
+ 'try{if(window.mermaid){window.mermaid.run({querySelector:"#orz-doc .mermaid:not([data-processed])"})}}catch(e){}'
|
|
72
|
+
// SMILES: draw each canvas once (tracked via a JS prop so morphdom keeps
|
|
73
|
+
// the drawn canvas across edits — DOM attributes stay identical).
|
|
74
|
+
+ 'try{if(window.SmilesDrawer){document.querySelectorAll("#orz-doc canvas[data-smiles]").forEach(function(c){if(c.__orzSmilesDone)return;var s=c.getAttribute("data-smiles");if(!s)return;if(c.__orzOrigW===undefined){c.__orzOrigW=c.width;c.__orzOrigH=c.height;}c.width=c.__orzOrigW;c.height=c.__orzOrigH;c.__orzSmilesDone=true;var dr=new window.SmilesDrawer.Drawer({width:c.__orzOrigW,height:c.__orzOrigH});window.SmilesDrawer.parse(s,function(t){try{dr.draw(t,c,window.__orzSmilesTheme||"light",false)}catch(e){}},function(){})})}}catch(e){}'
|
|
71
75
|
// Tabs init runs in the runtime on load (empty #orz-doc); re-run now that
|
|
72
76
|
// content is injected, and after each incremental update. Idempotent.
|
|
73
77
|
+ 'try{if(window.OrzMarkdownRuntime&&window.OrzMarkdownRuntime.initTabs){window.OrzMarkdownRuntime.initTabs(document)}}catch(e){}'
|
|
@@ -94,7 +98,20 @@
|
|
|
94
98
|
|
|
95
99
|
function enhance() {
|
|
96
100
|
var w = frame.contentWindow;
|
|
97
|
-
if (w
|
|
101
|
+
if (!w) return;
|
|
102
|
+
try { w.__orzSmilesTheme = themeById(currentTheme).scheme === 'dark' ? 'dark' : 'light'; } catch (e) {}
|
|
103
|
+
if (typeof w.__orzEnhance === 'function') { try { w.__orzEnhance(); } catch (e) {} }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Re-draw SMILES canvases in the current light/dark theme (after a theme
|
|
107
|
+
// switch). Just clear the done flag; the draw hook resets each canvas to its
|
|
108
|
+
// original dimensions before redrawing, so sizes never drift.
|
|
109
|
+
function redrawSmiles() {
|
|
110
|
+
var doc = frameDoc(); if (!doc) return;
|
|
111
|
+
Array.prototype.forEach.call(doc.querySelectorAll('#orz-doc canvas[data-smiles]'), function (c) {
|
|
112
|
+
c.__orzSmilesDone = false;
|
|
113
|
+
});
|
|
114
|
+
enhance();
|
|
98
115
|
}
|
|
99
116
|
// CDN libs inside the iframe load async — retry enhance a few times.
|
|
100
117
|
function enhanceSoon() { enhance(); setTimeout(enhance, 150); setTimeout(enhance, 600); setTimeout(enhance, 1500); }
|
|
@@ -117,9 +134,13 @@
|
|
|
117
134
|
window.morphdom(container, next, {
|
|
118
135
|
onBeforeElUpdated: function (fromEl, toEl) {
|
|
119
136
|
if (fromEl.isEqualNode && fromEl.isEqualNode(toEl)) return false;
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
137
|
+
// Keep an already-rendered generated construct (mermaid / smiles / qr /
|
|
138
|
+
// youtube) when its source is unchanged. These are client-rendered into
|
|
139
|
+
// canvases / SVGs / iframes, so letting morphdom touch them would wipe
|
|
140
|
+
// the drawing (e.g. a SMILES canvas disappearing when nearby text is
|
|
141
|
+
// edited). data-md carries the source; skip the whole subtree on match.
|
|
142
|
+
var dm = fromEl.getAttribute && fromEl.getAttribute('data-md');
|
|
143
|
+
if (dm != null && toEl.getAttribute && dm === toEl.getAttribute('data-md')) return false;
|
|
123
144
|
// keep highlighted code when the text is unchanged
|
|
124
145
|
if (fromEl.nodeName === 'CODE' && fromEl.classList && fromEl.classList.contains('hljs') &&
|
|
125
146
|
fromEl.textContent === toEl.textContent) return false;
|
|
@@ -330,6 +351,7 @@
|
|
|
330
351
|
root.setAttribute('data-chrome', t.scheme);
|
|
331
352
|
if (themeSelect) themeSelect.value = id;
|
|
332
353
|
applyThemeToFrame(t);
|
|
354
|
+
redrawSmiles(); // pick up the new light/dark SMILES palette
|
|
333
355
|
if (cm) cm.setOption('theme', cmTheme(t.scheme));
|
|
334
356
|
markDirty();
|
|
335
357
|
}
|
|
@@ -466,19 +488,30 @@
|
|
|
466
488
|
}
|
|
467
489
|
|
|
468
490
|
// ---- version check -------------------------------------------------------
|
|
491
|
+
// True only when `a` is a strictly newer semver than `b` (so an older
|
|
492
|
+
// resolved version never shows a bogus "update available").
|
|
493
|
+
function isNewer(a, b) {
|
|
494
|
+
var pa = String(a).split('.'), pb = String(b).split('.');
|
|
495
|
+
for (var i = 0; i < 3; i++) {
|
|
496
|
+
var x = parseInt(pa[i], 10) || 0, y = parseInt(pb[i], 10) || 0;
|
|
497
|
+
if (x > y) return true;
|
|
498
|
+
if (x < y) return false;
|
|
499
|
+
}
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
469
502
|
function checkVersion() {
|
|
470
503
|
if (!CFG.versionManifest || !CFG.rendererVersion) return;
|
|
471
504
|
try {
|
|
472
505
|
var cached = JSON.parse(localStorage.getItem('orz-mdhtml:vercheck') || 'null');
|
|
473
506
|
if (cached && (Date.now() - cached.t) < 86400000) {
|
|
474
|
-
if (cached.v && cached.v
|
|
507
|
+
if (cached.v && isNewer(cached.v, CFG.rendererVersion)) showUpdate(cached.v);
|
|
475
508
|
return;
|
|
476
509
|
}
|
|
477
510
|
} catch (e) {}
|
|
478
511
|
fetch(CFG.versionManifest).then(function (r) { return r.json(); }).then(function (j) {
|
|
479
512
|
var latest = j && j.version;
|
|
480
513
|
try { localStorage.setItem('orz-mdhtml:vercheck', JSON.stringify({ t: Date.now(), v: latest })); } catch (e) {}
|
|
481
|
-
if (latest && latest
|
|
514
|
+
if (latest && isNewer(latest, CFG.rendererVersion)) showUpdate(latest);
|
|
482
515
|
}).catch(function () {});
|
|
483
516
|
}
|
|
484
517
|
function showUpdate(latest) {
|
package/dist/cli.js
CHANGED
|
@@ -140,6 +140,7 @@ function main() {
|
|
|
140
140
|
hljsDarkCss: `${CDN.hl}/styles/atom-one-dark.min.css`,
|
|
141
141
|
hljsJs: `${CDN.hl}/highlight.min.js`,
|
|
142
142
|
mermaidJs: 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js',
|
|
143
|
+
smilesJs: 'https://cdn.jsdelivr.net/npm/smiles-drawer@1.0.10/dist/smiles-drawer.min.js',
|
|
143
144
|
},
|
|
144
145
|
editorLibs: {
|
|
145
146
|
codemirrorCss: `${CDN.cm}/codemirror.min.css`,
|
package/package.json
CHANGED