orz-markdown 1.2.0 → 1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-include.d.ts","sourceRoot":"","sources":["../../src/plugins/markdown-include.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAG1C,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAkC5D"}
1
+ {"version":3,"file":"markdown-include.d.ts","sourceRoot":"","sources":["../../src/plugins/markdown-include.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAG1C,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAqC5D"}
@@ -19,8 +19,11 @@ function registerMarkdownInclude(md) {
19
19
  // Guard against nested includes
20
20
  if (envObj['markdownIncludeActive'])
21
21
  return '';
22
- // Resolve path: prefer env.markdownBasePath (document dir) over process.cwd()
23
- const basePath = envObj['markdownBasePath'] ?? process.cwd();
22
+ // Resolve path: prefer env.markdownBasePath (document dir) over the cwd.
23
+ // Guard `process` so this stays usable in a browser bundle (no Node
24
+ // globals); there the fs read below fails and the include renders empty.
25
+ const cwd = typeof process !== 'undefined' && process.cwd ? process.cwd() : '.';
26
+ const basePath = envObj['markdownBasePath'] ?? cwd;
24
27
  const resolved = path_1.default.isAbsolute(filePath)
25
28
  ? filePath
26
29
  : path_1.default.resolve(basePath, filePath);
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-include.js","sourceRoot":"","sources":["../../src/plugins/markdown-include.ts"],"names":[],"mappings":";;;;;AAKA,0DAkCC;AAvCD,4CAAoB;AACpB,gDAAwB;AAExB,gDAA0C;AAE1C,SAAgB,uBAAuB,CAAC,EAAc;IACpD,IAAA,sBAAQ,EAAC;QACP,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,CAAC,UAAU,EAAE,IAAI,E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runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,QAkZhC,CAAC;AAEF,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,QA+ehC,CAAC;AAEF,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
package/dist/runtime.js CHANGED
@@ -82,8 +82,40 @@ exports.browserRuntimeScript = String.raw `
82
82
  });
83
83
  }
84
84
 
85
+ function initTabs(root) {
86
+ if (!root || typeof root.querySelectorAll !== 'function') return;
87
+ Array.prototype.slice.call(root.querySelectorAll('.tabs')).forEach(function (tabs) {
88
+ // data-js both guards re-init and switches the theme CSS from the no-JS
89
+ // fallback (all panels shown) to JS mode (only the .active panel shown).
90
+ if (tabs.getAttribute('data-js') === '1') return;
91
+ var panels = Array.prototype.slice.call(tabs.querySelectorAll(':scope > .tab'));
92
+ if (!panels.length) return;
93
+ tabs.setAttribute('data-js', '1');
94
+
95
+ var bar = global.document.createElement('div');
96
+ bar.className = 'tabs-bar';
97
+ panels.forEach(function (panel, i) {
98
+ var label = panel.getAttribute('data-label') || 'Tab ' + (i + 1);
99
+ var btn = global.document.createElement('button');
100
+ btn.className = 'tabs-bar-btn' + (i === 0 ? ' active' : '');
101
+ btn.textContent = label;
102
+ btn.addEventListener('click', function () {
103
+ Array.prototype.slice.call(tabs.querySelectorAll('.tabs-bar-btn')).forEach(function (b) { b.classList.remove('active'); });
104
+ panels.forEach(function (p) { p.classList.remove('active'); });
105
+ btn.classList.add('active');
106
+ panel.classList.add('active');
107
+ });
108
+ bar.appendChild(btn);
109
+ });
110
+ tabs.insertBefore(bar, tabs.firstChild);
111
+ panels[0].classList.add('active');
112
+ });
113
+ }
114
+
85
115
  function init(root) {
86
- initQrCodes(root || global.document);
116
+ var r = root || global.document;
117
+ initQrCodes(r);
118
+ initTabs(r);
87
119
  }
88
120
 
89
121
  // ---- copy-as-markdown: DOM -> Markdown walker ---------------------------
@@ -178,11 +210,10 @@ exports.browserRuntimeScript = String.raw `
178
210
  return '---';
179
211
  }
180
212
 
181
- function rt_table(tbl) {
213
+ function rt_tableRows(headRow, bodyRows) {
182
214
  var rows = [];
183
- var aligns = [];
184
215
  var header = [];
185
- var headRow = tbl.querySelector ? tbl.querySelector('thead tr') : null;
216
+ var aligns = [];
186
217
  if (headRow) {
187
218
  var hc = headRow.children;
188
219
  for (var i = 0; i < hc.length; i++) { header.push(rt_inlineChildren(hc[i]).trim()); aligns.push(rt_align(hc[i])); }
@@ -191,7 +222,6 @@ exports.browserRuntimeScript = String.raw `
191
222
  var seps = [];
192
223
  for (var s = 0; s < header.length; s++) seps.push(rt_sep(aligns[s]));
193
224
  rows.push('| ' + seps.join(' | ') + ' |');
194
- var bodyRows = tbl.querySelectorAll ? tbl.querySelectorAll('tbody tr') : [];
195
225
  for (var r = 0; r < bodyRows.length; r++) {
196
226
  var cells = [];
197
227
  var tds = bodyRows[r].children;
@@ -201,6 +231,27 @@ exports.browserRuntimeScript = String.raw `
201
231
  return rows.join('\n');
202
232
  }
203
233
 
234
+ function rt_table(tbl) {
235
+ var headRow = tbl.querySelector ? tbl.querySelector('thead tr') : null;
236
+ var bodyRows = tbl.querySelectorAll ? tbl.querySelectorAll('tbody tr') : [];
237
+ return rt_tableRows(headRow, bodyRows);
238
+ }
239
+
240
+ // Reconstruct a table from bare table-internal nodes (thead/tbody/tr), e.g.
241
+ // when a selection inside a table loses its <table> wrapper.
242
+ function rt_tableFromParts(parts) {
243
+ var headRow = null;
244
+ var bodyRows = [];
245
+ for (var i = 0; i < parts.length; i++) {
246
+ var p = parts[i];
247
+ var tag = p.tagName.toLowerCase();
248
+ if (tag === 'thead') { var tr = p.querySelector ? p.querySelector('tr') : null; if (tr && !headRow) headRow = tr; }
249
+ else if (tag === 'tbody') { var trs = p.querySelectorAll ? p.querySelectorAll('tr') : []; for (var j = 0; j < trs.length; j++) bodyRows.push(trs[j]); }
250
+ else if (tag === 'tr') { if (!headRow) headRow = p; else bodyRows.push(p); }
251
+ }
252
+ return rt_tableRows(headRow, bodyRows);
253
+ }
254
+
204
255
  function rt_codeBlock(pre) {
205
256
  var code = pre.querySelector ? (pre.querySelector('code') || pre) : pre;
206
257
  var lang = '';
@@ -275,6 +326,19 @@ exports.browserRuntimeScript = String.raw `
275
326
  parts.push(items.join('\n'));
276
327
  continue;
277
328
  }
329
+ // Bare table-internal nodes (selection inside a table that lost its
330
+ // <table> wrapper) — reconstruct a Markdown table.
331
+ if (k.nodeType === 1 && /^(thead|tbody|tr)$/.test(k.tagName.toLowerCase())) {
332
+ var trows = [];
333
+ while (i < kids.length) {
334
+ var tk = kids[i];
335
+ if (tk.nodeType === 1 && /^(thead|tbody|tr)$/.test(tk.tagName.toLowerCase())) { trows.push(tk); i++; }
336
+ else if (tk.nodeType === 3 && !(tk.nodeValue || '').trim()) { i++; }
337
+ else break;
338
+ }
339
+ parts.push(rt_tableFromParts(trows));
340
+ continue;
341
+ }
278
342
  var s = rt_blockNode(k);
279
343
  if (s && s.replace(/\s/g, '') !== '') parts.push(s.replace(/\s+$/, ''));
280
344
  i++;
@@ -338,15 +402,32 @@ exports.browserRuntimeScript = String.raw `
338
402
  return false;
339
403
  }
340
404
 
405
+ function rt_isCopyRoot(node) {
406
+ return node.nodeType === 1 && node.classList &&
407
+ (node.classList.contains('markdown-body') || rt_attr(node, 'data-orz-copy') != null);
408
+ }
341
409
  function rt_withinCopyRoot(node) {
342
410
  while (node) {
343
- if (node.nodeType === 1 && node.classList &&
344
- (node.classList.contains('markdown-body') || rt_attr(node, 'data-orz-copy') != null)) return true;
411
+ if (rt_isCopyRoot(node)) return true;
345
412
  node = node.parentNode;
346
413
  }
347
414
  return false;
348
415
  }
349
416
 
417
+ // When a selection sits entirely within one table/blockquote/pre, copy that
418
+ // whole block: a partial table/quote/code fragment isn't valid Markdown, and
419
+ // browsers often clone such selections without the wrapping element.
420
+ function rt_promotableBlock(node) {
421
+ while (node && !rt_isCopyRoot(node)) {
422
+ if (node.nodeType === 1) {
423
+ var tag = node.tagName.toLowerCase();
424
+ if (tag === 'table' || tag === 'blockquote' || tag === 'pre') return node;
425
+ }
426
+ node = node.parentNode;
427
+ }
428
+ return null;
429
+ }
430
+
350
431
  function onCopy(event) {
351
432
  if (!global.document) return;
352
433
  var sel = global.getSelection ? global.getSelection()
@@ -354,9 +435,20 @@ exports.browserRuntimeScript = String.raw `
354
435
  if (!sel || sel.rangeCount === 0 || sel.isCollapsed) return;
355
436
  if (rt_isEditable(sel.anchorNode) || rt_isEditable(sel.focusNode)) return;
356
437
  if (!rt_withinCopyRoot(sel.anchorNode) && !rt_withinCopyRoot(sel.focusNode)) return;
357
- var container = global.document.createElement('div');
358
- for (var i = 0; i < sel.rangeCount; i++) container.appendChild(sel.getRangeAt(i).cloneContents());
359
- var md = elementToMarkdown(container);
438
+
439
+ var md;
440
+ var range0 = sel.getRangeAt(0);
441
+ var common = range0.commonAncestorContainer;
442
+ var promoted = rt_promotableBlock(common.nodeType === 1 ? common : common.parentNode);
443
+ if (promoted && sel.rangeCount === 1) {
444
+ var pwrap = global.document.createElement('div');
445
+ pwrap.appendChild(promoted.cloneNode(true));
446
+ md = elementToMarkdown(pwrap);
447
+ } else {
448
+ var container = global.document.createElement('div');
449
+ for (var i = 0; i < sel.rangeCount; i++) container.appendChild(sel.getRangeAt(i).cloneContents());
450
+ md = elementToMarkdown(container);
451
+ }
360
452
  if (!md) return;
361
453
  var cd = event.clipboardData || global.clipboardData;
362
454
  if (cd && cd.setData) {
@@ -388,6 +480,7 @@ exports.browserRuntimeScript = String.raw `
388
480
  global.OrzMarkdownRuntime = Object.assign({}, global.OrzMarkdownRuntime, {
389
481
  init: init,
390
482
  initQrCodes: initQrCodes,
483
+ initTabs: initTabs,
391
484
  collapseQr: collapseQr,
392
485
  elementToMarkdown: elementToMarkdown,
393
486
  });
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;AAoZA,0DAEC;AAtZY,QAAA,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkZ7C,CAAC;AAEF,SAAgB,uBAAuB;IACrC,OAAO,4BAAoB,CAAC;AAC9B,CAAC"}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;AAifA,0DAEC;AAnfY,QAAA,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+e7C,CAAC;AAEF,SAAgB,uBAAuB;IACrC,OAAO,4BAAoB,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orz-markdown",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Customized markdown-it parser with official and custom plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",