主题与渲染插件
用主题变量和 Shadow Parts 调整组件外观,用插件增强 Markdown 的呈现。
调整外观
管理后台的 组件 页面可以直接预览主题、按钮颜色和圆角,再复制嵌入代码。theme 支持 auto、light 和 dark。在宿主页面上加入以下样式可覆盖直接嵌入的实例。
CSSblua-comments { --blua-color-primary: #963653; --blua-color-primary-ink: white; --blua-radius-card: 10px;}blua-comments::part(content) { line-height: 1.7;}blua-comments::part(submit) { border-radius: 999px;}
JS 组件也可通过 themeTokens 对象设置单个实例。iframe 内容通过 URL 接收主题变量,例如 &--blua-radius-card=10px。用 createBluaFrameUrl 编码包含 # 的颜色或带空格的字体名称。
使用 callouts
JavaScriptimport { mountBluaComments } from '@blua/embed/register';import { calloutsPlugin } from '@blua/embed/plugins/callouts';const thread = mountBluaComments(document.querySelector('#discussion'), { endpoint: 'https://blua.example', siteKey: 'garden', pageKey: 'spring-swallows', plugins: [calloutsPlugin],});
先在页面放置 <div id="discussion"></div>。在评论中用 > [!TIP] 开头,下一行以 > 写提示内容。框架组件同样接受 plugins 数组,iframe 则在 URL 中添加 plugins=callouts。移除用 JS 挂载的组件时调用 thread.remove()。
编写插件
TypeScriptimport type { BluaRenderPlugin } from '@blua/embed';export const codeLabels: BluaRenderPlugin = { name: 'code-labels', enhance(body) { for (const node of body.querySelectorAll('code')) node.part.add('inline-code'); },};
将插件加入 plugins,即可用 ::part(inline-code) 设置样式。插件按数组顺序处理已清理的评论 DOM。插件抛出异常时,这条评论会恢复原始渲染,并发出 blua:plugin-error 事件。仅加载站点维护者信任的模块。
自定义 iframe 插件必须由运营者安装:从网关提供 /embed/plugins/code-labels.js,默认导出名称匹配的插件对象,并在网关设置 BLUA_FRAME_PLUGINS=code-labels。随后在 iframe URL 中请求 plugins=code-labels。