confluence-md-sync 0.8.3 → 0.8.5

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 CHANGED
@@ -370,6 +370,12 @@ macros.tableExcerptInclude('name', 'Source Page');
370
370
  macros.tableExcerpt(md, 'name', /* hide */ true);
371
371
  macros.tableFilter(md, { totalrow: ',,Sum' });
372
372
  macros.tableJoiner(includesMd, "SELECT * FROM T1 LEFT JOIN T2 ON …"); // multiline SQL ok
373
+
374
+ // CSV Table app — render a table from an attached CSV (page body stays tiny;
375
+ // ideal for large datasets that would blow the Confluence storage-size limit
376
+ // as an inline table). Wrap in tableFilter for in-header filtering/pagination.
377
+ macros.csvTable('data.csv');
378
+ macros.tableFilter(macros.csvTable('data.csv'), { totalrow: ',,,,,,,,Sum' });
373
379
  ```
374
380
 
375
381
  Or write markers by hand right in Markdown:
@@ -582,14 +582,24 @@ class Converter {
582
582
  const grid = trs.map((tr) => elements(tr.children)
583
583
  .filter((c) => c.name === 'td' || c.name === 'th')
584
584
  .map((c) => {
585
+ // Сначала честная конвертация (page-ссылки → {{page:…}}); стрип пустых
586
+ // ac:/ri:-вставок — только если она не удалась (иначе теряются ссылки
587
+ // без текста тела: у них подпись — заголовок страницы).
585
588
  let flat;
586
589
  try {
587
- flat = this.cellFlatten(this.stripEmptyNamespaced(c.children));
590
+ flat = this.cellFlatten(c.children);
588
591
  }
589
592
  catch (e) {
590
593
  if (!(e instanceof Unrepresentable))
591
594
  throw e;
592
- flat = textContent(c.children);
595
+ try {
596
+ flat = this.cellFlatten(this.stripEmptyNamespaced(c.children));
597
+ }
598
+ catch (e2) {
599
+ if (!(e2 instanceof Unrepresentable))
600
+ throw e2;
601
+ flat = textContent(c.children);
602
+ }
593
603
  }
594
604
  return flat.replace(/\s+/g, ' ').trim();
595
605
  }));
@@ -4,9 +4,11 @@ export { MacroRegistry, processMacros } from './registry.js';
4
4
  export { escapeXmlAttr, generateMacroId, structuredMacro, pageLinkValue, type StructuredMacroOptions, } from './xml.js';
5
5
  export { coreMacrosPlugin, extractPlainText } from './plugins/core.js';
6
6
  export { tableFilterPlugin, TABLE_FILTER_DEFAULTS } from './plugins/table-filter.js';
7
+ export { csvTablePlugin, CSV_TABLE_DEFAULTS } from './plugins/csv-table.js';
7
8
  import { MacroRegistry } from './registry.js';
8
9
  import { anchor, children, codeBlock, excerpt, excerptInclude, expand, includePage, jiraIssue, panel, status, toc } from './plugins/core.js';
9
10
  import { tableExcerpt, tableExcerptInclude, tableFilter, tableJoiner } from './plugins/table-filter.js';
11
+ import { csvTable } from './plugins/csv-table.js';
10
12
  /** Creates a registry pre-loaded with all built-in plugins. */
11
13
  export declare function createDefaultRegistry(): MacroRegistry;
12
14
  /**
@@ -42,4 +44,5 @@ export declare const macros: {
42
44
  tableFilter: typeof tableFilter;
43
45
  tableExcerptInclude: typeof tableExcerptInclude;
44
46
  tableJoiner: typeof tableJoiner;
47
+ csvTable: typeof csvTable;
45
48
  };
@@ -4,14 +4,17 @@ export { MacroRegistry, processMacros } from './registry.js';
4
4
  export { escapeXmlAttr, generateMacroId, structuredMacro, pageLinkValue, } from './xml.js';
5
5
  export { coreMacrosPlugin, extractPlainText } from './plugins/core.js';
6
6
  export { tableFilterPlugin, TABLE_FILTER_DEFAULTS } from './plugins/table-filter.js';
7
+ export { csvTablePlugin, CSV_TABLE_DEFAULTS } from './plugins/csv-table.js';
7
8
  import { MacroRegistry } from './registry.js';
8
9
  import { coreMacrosPlugin } from './plugins/core.js';
9
10
  import { tableFilterPlugin } from './plugins/table-filter.js';
11
+ import { csvTablePlugin } from './plugins/csv-table.js';
10
12
  import { anchor, children, codeBlock, excerpt, excerptInclude, expand, includePage, info, jiraIssue, note, panel, status, tip, toc, warning, } from './plugins/core.js';
11
13
  import { tableExcerpt, tableExcerptInclude, tableFilter, tableJoiner } from './plugins/table-filter.js';
14
+ import { csvTable } from './plugins/csv-table.js';
12
15
  /** Creates a registry pre-loaded with all built-in plugins. */
13
16
  export function createDefaultRegistry() {
14
- return new MacroRegistry().use(coreMacrosPlugin).use(tableFilterPlugin);
17
+ return new MacroRegistry().use(coreMacrosPlugin).use(tableFilterPlugin).use(csvTablePlugin);
15
18
  }
16
19
  /**
17
20
  * Глобальный реестр по умолчанию (core + table-filter). Используется,
@@ -48,4 +51,5 @@ export const macros = {
48
51
  tableFilter,
49
52
  tableExcerptInclude,
50
53
  tableJoiner,
54
+ csvTable,
51
55
  };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Plugin for the "CSV Table" Confluence macro (csv-table): renders a table
3
+ * from a CSV — most usefully from a page attachment (`source=attachment`),
4
+ * so the page body stays tiny while the data lives in the attached CSV.
5
+ * Large datasets that would blow the Confluence storage-size limit as an
6
+ * inline table are published as a CSV attachment and rendered by this macro
7
+ * (optionally wrapped in table-filter for in-header filtering/pagination).
8
+ */
9
+ import { Markdown } from '../../markdown/markdown.js';
10
+ import { type MacroPlugin } from '../types.js';
11
+ export declare const CSV_TABLE_DEFAULTS: Record<string, string>;
12
+ export declare const csvTablePlugin: MacroPlugin;
13
+ /**
14
+ * Строит макрос "CSV Table" из вложения. По умолчанию `source=attachment`.
15
+ * Опции перекрывают дефолты (например `header`, `source`).
16
+ *
17
+ * @example
18
+ * csvTable('worklogs_summary.csv')
19
+ * macros.tableFilter(csvTable('worklogs_summary.csv'), { totalrow: ',,,,,,,,Sum' })
20
+ */
21
+ export declare function csvTable(attachment: string, opts?: Record<string, string | undefined>): Markdown;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Plugin for the "CSV Table" Confluence macro (csv-table): renders a table
3
+ * from a CSV — most usefully from a page attachment (`source=attachment`),
4
+ * so the page body stays tiny while the data lives in the attached CSV.
5
+ * Large datasets that would blow the Confluence storage-size limit as an
6
+ * inline table are published as a CSV attachment and rendered by this macro
7
+ * (optionally wrapped in table-filter for in-header filtering/pagination).
8
+ */
9
+ import { macro } from '../builder.js';
10
+ import { paramMap } from '../types.js';
11
+ import { structuredMacro } from '../xml.js';
12
+ // Дефолты csv-table, какие сохраняет редактор Confluence. Пустые-присутствие
13
+ // (password/header/login) — чтобы редактор не «терял» контролы при следующем
14
+ // открытии и сохранении страницы. source=attachment — данные из вложения.
15
+ export const CSV_TABLE_DEFAULTS = {
16
+ isFirstTimeEnter: 'true',
17
+ password: '',
18
+ header: '',
19
+ source: 'attachment',
20
+ login: '',
21
+ };
22
+ // Порядок параметров как у редактора (стабильный вывод, дружелюбно к hash-diff).
23
+ const CSV_TABLE_PARAM_ORDER = ['isFirstTimeEnter', 'password', 'attachment', 'header', 'source', 'login'];
24
+ export const csvTablePlugin = {
25
+ name: 'csv-table',
26
+ macros: [
27
+ {
28
+ // Макрос «CSV Table». Рендерит таблицу из CSV. Обычный режим —
29
+ // source=attachment + attachment=<имя.csv>: CSV берётся из вложения
30
+ // страницы, тело страницы не пухнет от данных. Все переданные параметры
31
+ // накладываются поверх дефолтов; вывод — в каноничном порядке редактора.
32
+ name: 'csv-table',
33
+ render: (ctx) => {
34
+ const merged = { ...CSV_TABLE_DEFAULTS, ...paramMap(ctx.params) };
35
+ const keys = [...CSV_TABLE_PARAM_ORDER, ...Object.keys(merged).filter((k) => !CSV_TABLE_PARAM_ORDER.includes(k))];
36
+ const params = keys.filter((k) => merged[k] !== undefined).map((k) => ({ name: k, value: merged[k] }));
37
+ return structuredMacro('csv-table', ctx.macroId, { params });
38
+ },
39
+ },
40
+ ],
41
+ };
42
+ // ── Convenience builder ─────────────────────────────────────────────────
43
+ /**
44
+ * Строит макрос "CSV Table" из вложения. По умолчанию `source=attachment`.
45
+ * Опции перекрывают дефолты (например `header`, `source`).
46
+ *
47
+ * @example
48
+ * csvTable('worklogs_summary.csv')
49
+ * macros.tableFilter(csvTable('worklogs_summary.csv'), { totalrow: ',,,,,,,,Sum' })
50
+ */
51
+ export function csvTable(attachment, opts = {}) {
52
+ return macro('csv-table').param('attachment', attachment).withParams(opts).toMarkdown();
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "confluence-md-sync",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Publish Markdown to Confluence (Data Center & Cloud): idempotent page sync, attachment dedup, tables and a pluggable macro system",
5
5
  "keywords": [
6
6
  "confluence",