confluence-md-sync 0.8.6 → 0.8.8

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.
@@ -680,11 +680,14 @@ class Converter {
680
680
  }
681
681
  // ── Списки ───────────────────────────────────────────────────────────
682
682
  listToMd(list) {
683
- if (list.attrs.some(([k]) => !(list.name === 'ol' && k === 'start'))) {
683
+ // readable-режим отбрасывает оформление, поэтому презентационные атрибуты
684
+ // (class/style, напр. вставленный ds-markdown/code-line) на списке и его
685
+ // пунктах игнорируются — список всё равно превращается в чистый markdown.
686
+ if (!this.readable && list.attrs.some(([k]) => !(list.name === 'ol' && k === 'start'))) {
684
687
  throw new Unrepresentable();
685
688
  }
686
689
  const items = list.children.filter((n) => !(n.kind === 'text' && /^[ \t\r\n]*$/.test(n.raw)));
687
- if (!items.every((n) => n.kind === 'el' && n.name === 'li' && n.attrs.length === 0)) {
690
+ if (!items.every((n) => n.kind === 'el' && n.name === 'li' && (this.readable || n.attrs.length === 0))) {
688
691
  throw new Unrepresentable();
689
692
  }
690
693
  const lis = items;
@@ -733,7 +736,7 @@ class Converter {
733
736
  flushInline();
734
737
  lines.push(...this.listToMd(part).split('\n'));
735
738
  }
736
- else if (part.kind === 'el' && part.name === 'p' && part.attrs.length === 0) {
739
+ else if (part.kind === 'el' && part.name === 'p' && (this.readable || part.attrs.length === 0)) {
737
740
  if (!loose)
738
741
  throw new Unrepresentable();
739
742
  if (lines.length > 0)
@@ -43,6 +43,18 @@ export interface RenderStorageOptions {
43
43
  fileStyle?: 'url' | 'attachment';
44
44
  /** Автопревращение голых URL в ссылки (default: true). */
45
45
  linkify?: boolean;
46
+ /**
47
+ * Резолвер относительных ссылок на другие md-файлы набора. Для каждой
48
+ * markdown-ссылки `[text](href)` вызывается с исходным href; если вернул
49
+ * цель — ссылка публикуется как Confluence page-link (`<ac:link><ri:page>`)
50
+ * на страницу связанного md (карту file→page строит вызывающий, напр.
51
+ * docs-studio из манифеста). `null`/`undefined` — ссылка остаётся как есть
52
+ * (обычная `<a href>`), пригодна для внешних URL и якорей.
53
+ */
54
+ linkResolver?: (href: string) => {
55
+ title: string;
56
+ space?: string;
57
+ } | null;
46
58
  }
47
59
  export declare class MissingAttachmentUrlError extends Error {
48
60
  constructor(message: string);
@@ -116,6 +116,28 @@ export function renderToStorage(markdown, urls, opts = {}) {
116
116
  // markdown-it сквозь себя не пропускает). Fence рендерится в экранированный
117
117
  // <pre><code>; здесь разэкранируем содержимое обратно в живую разметку.
118
118
  html = html.replace(/<pre><code class="language-confluence-storage">([\s\S]*?)<\/code><\/pre>\n?/g, (_full, escaped) => unescapeHtml(escaped.replace(/\n$/, '')) + '\n');
119
+ // Ссылки на связанные md → Confluence page-link по резолверу (карта из
120
+ // манифеста). Только markdown-ссылки (`<a href>` из markdown-it); плейсхолдеры
121
+ // {{file:}}/{{img:}} рендерятся ниже и сюда ещё не попали. Внешние URL/якоря
122
+ // резолвер отсекает (возвращает null) — они остаются как есть.
123
+ if (opts.linkResolver) {
124
+ const resolve = opts.linkResolver;
125
+ html = html.replace(/<a href="([^"]*)">([\s\S]*?)<\/a>/g, (full, href, inner) => {
126
+ const decoded = unescapeHtml(href);
127
+ if (/^(?:[a-z][a-z0-9+.-]*:|#|\/\/)/i.test(decoded))
128
+ return full; // http(s):, mailto:, #anchor
129
+ const target = resolve(decoded);
130
+ if (!target)
131
+ return full;
132
+ const text = unescapeHtml(inner.replace(/<[^>]+>/g, '')).trim();
133
+ const attrs = [];
134
+ if (target.space)
135
+ attrs.push(['space', target.space]);
136
+ if (text)
137
+ attrs.push(['text', text]);
138
+ return renderPageLink(target.title, attrs);
139
+ });
140
+ }
119
141
  return html.replace(PLACEHOLDER_RE, (_full, kind, rawBody) => {
120
142
  const { name, attrs } = parsePlaceholder(String(rawBody));
121
143
  if (kind === 'page') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "confluence-md-sync",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
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",