qiling-web-markdown 0.0.0-stage → 0.1.1

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 炼器师
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.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # qiling-web-markdown
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ QiLing Web Markdown 拓展包。可注册渲染器的 Markdown 渲染组件。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install qiling-web qiling-web-markdown
9
+ # 或
10
+ bun add qiling-web qiling-web-markdown
11
+ ```
12
+
13
+ > `qiling-web-markdown` 通过 peer dependency 使用 `qiling-web`,请同时安装核心包。
14
+
15
+ ## 使用
16
+
17
+ ```js
18
+ import 'qiling-web'
19
+ import 'qiling-web-markdown'
20
+
21
+ // 导入即注册:ql-markdown
22
+ ```
23
+
24
+ 组件标签:`ql-markdown`。
25
+
26
+ ## 文档
27
+
28
+ - [QiLing Web 文档](https://gitee.com/i-o-i/qiling-web)
29
+ - [源码仓库](https://gitee.com/i-o-i/qiling-web)
30
+
31
+ ## License
32
+
33
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import{Registry as m}from"qiling-web/internal";import{QlElement as g}from"qiling-web";class r extends g{constructor(){super(...arguments);this.layout={type:"div",ref:"box"};this.actions={sync(){let t=this.$("div");if(!t)return;let o=r.renderers.get(r.defaultRenderer);if(!o){t.textContent=`未注册 Markdown 渲染器:${r.defaultRenderer}`;return}t.innerHTML=o(this.getProp("source")),r.wrapOverflow(t)}}}static renderers=new Map;static{r.register("simple",r.simpleRenderer)}static register(t,o){r.renderers.set(t,o)}static use(t){if(!r.renderers.has(t))throw Error(`未注册的 Markdown 渲染器:${t}`);r.defaultRenderer=t}static markdownRenderers(){return[...r.renderers.keys()]}static defaultRenderer="simple";static tag="ql-markdown";static props={source:{type:"string",default:"",description:"Markdown 原文"}};static styles=`
2
+ :host { display: block; font-size: var(--ql-font-size-md); line-height: 1.75; color: var(--ql-color-fg); }
3
+ :where(h1, h2, h3, h4, h5, h6) { margin: 16px 0 8px; line-height: 1.35; }
4
+ :where(h1) { font-size: var(--ql-font-size-2xl); }
5
+ :where(h2) { font-size: var(--ql-font-size-xl); padding-bottom: 6px; border-bottom: 1px solid var(--ql-color-border); }
6
+ :where(h3) { font-size: var(--ql-font-size-lg); }
7
+ :where(p) { margin: 0 0 12px; }
8
+ :where(ul, ol) { margin: 0 0 12px; padding-left: 22px; }
9
+ :where(li) { margin-bottom: 4px; }
10
+ :where(code) {
11
+ padding: 1px 5px;
12
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
13
+ font-size: .9em;
14
+ background: var(--ql-color-bg-subtle);
15
+ border-radius: var(--ql-radius-sm);
16
+ }
17
+ :where(pre) { margin: 0 0 12px; padding: var(--ql-space-3); overflow-x: auto; background: var(--ql-color-bg-subtle); border-radius: var(--ql-radius-md); }
18
+ :where(pre code) { padding: 0; background: none; }
19
+ :where(blockquote) { margin: 0 0 12px; padding: 4px 14px; color: var(--ql-color-fg-muted); border-left: 3px solid var(--ql-color-border-strong); }
20
+ :where(a) { color: var(--ql-color-primary); }
21
+ :where(hr) { margin: 18px 0; border: 0; border-top: 1px solid var(--ql-color-border); }
22
+ :where(table) { width: 100%; margin: 0 0 12px; border-collapse: collapse; font-size: var(--ql-font-size-sm); }
23
+ :where(th, td) { padding: 6px 10px; text-align: left; border: 1px solid var(--ql-color-border); }
24
+ :where(th) { background: var(--ql-color-bg-subtle); }
25
+ `;static effects={source(){this.actions.sync()}};static wrapOverflow(t){for(let o of t.querySelectorAll("pre, table")){if(o.parentElement?.tagName.toLowerCase()==="ql-scroll")continue;let e=document.createElement("ql-scroll");e.setAttribute("axis","x"),e.setAttribute("padding","none"),o.style.width="max-content",o.style.minWidth="100%",o.replaceWith(e),e.append(o)}}static simpleRenderer(t){let o=t.split(/\r?\n/),e=[],n=null,p=null,d=[],s=()=>{if(p)e.push(`</${p}>`),p=null},h=()=>{if(!d.length)return;let i=d.map((l)=>l.replace(/^\||\|$/g,"").split("|").map((c)=>c.trim())),[a,,...u]=i;if(a){e.push("<table><thead><tr>");for(let l of a)e.push(`<th>${r.inline(l)}</th>`);e.push("</tr></thead><tbody>");for(let l of u){e.push("<tr>");for(let c of l)e.push(`<td>${r.inline(c)}</td>`);e.push("</tr>")}e.push("</tbody></table>")}d=[]};for(let i of o){if(/^\s*```/.test(i)){if(h(),s(),n)e.push(`<pre><code>${r.escapeHtml(n.join(`
26
+ `))}</code></pre>`),n=null;else n=[];continue}if(n){n.push(i);continue}if(/^\s*\|.*\|\s*$/.test(i)){s(),d.push(i.trim());continue}if(h(),!i.trim()){s();continue}let a=/^(#{1,6})\s+(.*)$/.exec(i);if(a){s();let f=a[1].length;e.push(`<h${f}>${r.inline(a[2])}</h${f}>`);continue}if(/^\s*([-*_])\s*\1\s*\1[\s-*_]*$/.test(i)){s(),e.push("<hr/>");continue}let u=/^\s*>\s?(.*)$/.exec(i);if(u){s(),e.push(`<blockquote>${r.inline(u[1])}</blockquote>`);continue}let l=/^\s*[-*+]\s+(.*)$/.exec(i);if(l){if(p!=="ul")s(),e.push("<ul>"),p="ul";e.push(`<li>${r.inline(l[1])}</li>`);continue}let c=/^\s*\d+\.\s+(.*)$/.exec(i);if(c){if(p!=="ol")s(),e.push("<ol>"),p="ol";e.push(`<li>${r.inline(c[1])}</li>`);continue}s(),e.push(`<p>${r.inline(i)}</p>`)}if(h(),s(),n)e.push(`<pre><code>${r.escapeHtml(n.join(`
27
+ `))}</code></pre>`);return e.join(`
28
+ `)}static inline(t){return r.escapeHtml(t).replace(/`([^`]+)`/g,"<code>$1</code>").replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>").replace(/(^|[^*])\*([^*]+)\*/g,"$1<em>$2</em>").replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,'<a href="$2" target="_blank" rel="noreferrer">$1</a>')}static escapeHtml(t){return t.replace(/[&<>"]/g,(o)=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[o])}}m.define(r);export{r as QlMarkdown};
@@ -0,0 +1,3 @@
1
+ import { QlMarkdown } from './ql-markdown';
2
+ export { QlMarkdown };
3
+ export type { MarkdownRenderer } from './types';
@@ -0,0 +1,47 @@
1
+ import type { EffectMap } from 'qiling-web';
2
+ import type { GroupMethod } from 'qiling-web';
3
+ import { QlElement } from 'qiling-web';
4
+ import type { PropSchema } from 'qiling-web';
5
+ import type { MarkdownRenderer } from './types';
6
+ /**
7
+ * Markdown 渲染(**适配层**)。
8
+ *
9
+ * 内置一个极简渲染器(零依赖,覆盖标题/列表/代码块/引用/行内样式/链接);
10
+ * 需要完整 CommonMark、表格、脚注时,用 `registerMarkdownRenderer` 接 markdown-it,**页面不用改**。
11
+ *
12
+ * 安全:**内置渲染器对原文一律转义**,只输出受控标签;接入外部渲染器时应自行 sanitize。
13
+ */
14
+ export declare class QlMarkdown extends QlElement {
15
+ private static readonly renderers;
16
+ /** 注册渲染器 */
17
+ static register(name: string, renderer: MarkdownRenderer): void;
18
+ /** 切换全局渲染器(需先注册) */
19
+ static use(name: string): void;
20
+ static markdownRenderers(): string[];
21
+ private static defaultRenderer;
22
+ static tag: string;
23
+ static props: PropSchema;
24
+ source: string;
25
+ static styles: string;
26
+ /** 内部结构:一个容器(渲染结果由 `actions.sync` 注入) */
27
+ layout: {
28
+ type: string;
29
+ ref: string;
30
+ };
31
+ /** `source` 变化 → 重算(挂载时也会执行一次,故动作幂等) */
32
+ static effects: EffectMap;
33
+ /** 3. 操作:业务动作。**不挂 `Ql.desc()` 即内部方法**,不对外暴露 */
34
+ actions: Record<string, GroupMethod>;
35
+ private static wrapOverflow;
36
+ private static simpleRenderer;
37
+ /** 行内样式:先转义,再套受控标签 */
38
+ private static inline;
39
+ private static escapeHtml;
40
+ }
41
+ /**
42
+ * 代码块与表格的**横向滚动**交给 ql-scroll。
43
+ *
44
+ * 原生滚动条在 Shadow DOM 内无法自绘(::-webkit-scrollbar 对 shadow 内的滚动容器
45
+ * 不生效,实测踩到),只能退回浏览器默认的 15px 粗条,与 ql-scroll 的 4px 胶囊滑块
46
+ * 对不上。包一层 ql-scroll 后,横向滚动条与页面其余部分完全一致。
47
+ */
@@ -0,0 +1,2 @@
1
+ /** Markdown 渲染器 */
2
+ export type MarkdownRenderer = (source: string) => string;
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "qiling-web-markdown",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "QiLing UI 拓展组件:Markdown 渲染",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/types/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "LICENSE",
16
+ "README.md"
17
+ ],
18
+ "sideEffects": [
19
+ "./dist/index.js"
20
+ ],
21
+ "peerDependencies": {
22
+ "qiling-web": "^0.1.1"
23
+ },
24
+ "devDependencies": {
25
+ "qiling-web": "workspace:*"
26
+ },
27
+ "scripts": {
28
+ "clean": "rm -rf dist",
29
+ "build": "bun run clean && bun run build:ui && bun run build:types",
30
+ "build:ui": "bun build src/index.ts --outdir=dist --target=browser --format=esm --minify --splitting --entry-naming=index.js --chunk-naming=chunk-[hash].js --min-chunk-size=16384 --external qiling-web --external qiling-web/internal",
31
+ "build:types": "tsc -p tsconfig.build.json",
32
+ "typecheck": "tsc --noEmit -p tsconfig.json",
33
+ "prepublishOnly": "bun run build && bun run typecheck"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://gitee.com/i-o-i/qiling-web.git",
38
+ "directory": "packages/qiling-web-markdown"
39
+ },
40
+ "homepage": "https://gitee.com/i-o-i/qiling-web",
41
+ "bugs": {
42
+ "url": "https://gitee.com/i-o-i/qiling-web/issues"
43
+ },
44
+ "keywords": [
45
+ "qiling",
46
+ "qiling-web",
47
+ "web-components",
48
+ "ui",
49
+ "framework"
50
+ ],
51
+ "author": {
52
+ "name": "炼器师"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ }
57
+ }