@scribdown/markdown-renderer 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GrainFull
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 将 Markdown 文本渲染为安全 HTML。
3
+ * 渲染链路固定开启代码高亮与 HTML sanitize(rehype 结构清洗 + DOMPurify),
4
+ * 库不再对外暴露这些细节开关,保证所有宿主拿到一致的预览输出。
5
+ * @param markdownText 输入的 Markdown 文本。
6
+ * @returns 可挂载到 DOM 容器的 HTML 字符串。
7
+ */
8
+ declare function renderMarkdown(markdownText: string): Promise<string>;
9
+ /**
10
+ * Markdown 交互 hydration 的可注入选项,用于让各宿主落地平台差异,
11
+ * 渲染器自身保持跨端一致(仅调用注入的实现)。
12
+ */
13
+ interface MarkdownInteractionOptions {
14
+ /**
15
+ * 目录条目跳转到目标标题的滚动实现,由宿主注入以适配各端平滑滚动差异。
16
+ * 缺省使用原生 `scrollIntoView({ behavior: "smooth" })`(标准浏览器即丝滑);
17
+ * 若宿主原生平滑被降级(如 VS Code webview 对真实锚点点击会瞬时),
18
+ * 可注入自定义实现(如手动 requestAnimationFrame 动画)。
19
+ * @param targetElement 目标标题元素。
20
+ */
21
+ scrollToHeading?: (targetElement: HTMLElement) => void;
22
+ }
23
+ /**
24
+ * 对已渲染到 DOM 的 Markdown 内容执行交互 hydration。
25
+ * 处理图片放大查看、视频占位、Mermaid、代码块复制等运行时行为。
26
+ * 不挂载浮动工具栏;如需工具栏请额外调用 {@link mountMarkdownToolbar}。
27
+ * @param rootElement 包含 Markdown 渲染结果的根节点。
28
+ * @param options 可注入交互选项(如目录跳转滚动实现)。
29
+ */
30
+ declare function hydrateMarkdown(rootElement: ParentNode, options?: MarkdownInteractionOptions): void;
31
+ /**
32
+ * 在指定 DOM 容器上挂载 Scribdown 浮动工具栏(回到顶部 / 目录 / 页面宽度切换)。
33
+ * 工具栏 DOM 会直接 append 到 `container` 内,便于宿主控制生命周期:
34
+ * 移除 / 替换 container 即可一并卸载工具栏,不会污染 `<body>`。
35
+ * 视觉上工具栏使用 `position: fixed`,位置始终相对视口,与挂载点的 CSS 上下文无关。
36
+ *
37
+ * 仅在浏览器环境生效;非浏览器环境(如 Node.js 单测)或 SSR 阶段直接跳过。
38
+ * 重复调用会先清理 container 内的旧实例,可在每次 {@link hydrateMarkdown} 后安全重新挂载。
39
+ * @param container 目标挂载容器;同时作为目录采集与点击外部关闭的作用域。
40
+ * @param options 可注入交互选项(如目录跳转滚动实现)。
41
+ */
42
+ declare function mountMarkdownToolbar(container: Element, options?: MarkdownInteractionOptions): void;
43
+
44
+ export { type MarkdownInteractionOptions, hydrateMarkdown, mountMarkdownToolbar, renderMarkdown };