confluence-md-sync 0.8.7 → 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.
- package/dist/markdown/render.d.ts +12 -0
- package/dist/markdown/render.js +22 -0
- package/package.json +1 -1
|
@@ -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);
|
package/dist/markdown/render.js
CHANGED
|
@@ -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