loghub-me-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/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +37 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface MarkdownRendererOptions extends MarkdownIt.Options {
|
|
4
|
+
useMarkdownItAnchor?: boolean;
|
|
5
|
+
useSafeLinkify?: boolean;
|
|
6
|
+
useSanitize?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface RenderedResult {
|
|
9
|
+
html: string;
|
|
10
|
+
anchors: Anchor[];
|
|
11
|
+
}
|
|
12
|
+
interface Anchor {
|
|
13
|
+
level: number;
|
|
14
|
+
slug: string;
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare class MarkdownRenderer {
|
|
19
|
+
private static readonly DEFAULT_OPTIONS;
|
|
20
|
+
private readonly client;
|
|
21
|
+
private readonly options;
|
|
22
|
+
constructor(options?: MarkdownRendererOptions);
|
|
23
|
+
render(markdown: string): RenderedResult;
|
|
24
|
+
private parseAnchors;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { MarkdownRenderer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
|
|
3
|
+
interface MarkdownRendererOptions extends MarkdownIt.Options {
|
|
4
|
+
useMarkdownItAnchor?: boolean;
|
|
5
|
+
useSafeLinkify?: boolean;
|
|
6
|
+
useSanitize?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface RenderedResult {
|
|
9
|
+
html: string;
|
|
10
|
+
anchors: Anchor[];
|
|
11
|
+
}
|
|
12
|
+
interface Anchor {
|
|
13
|
+
level: number;
|
|
14
|
+
slug: string;
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare class MarkdownRenderer {
|
|
19
|
+
private static readonly DEFAULT_OPTIONS;
|
|
20
|
+
private readonly client;
|
|
21
|
+
private readonly options;
|
|
22
|
+
constructor(options?: MarkdownRendererOptions);
|
|
23
|
+
render(markdown: string): RenderedResult;
|
|
24
|
+
private parseAnchors;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { MarkdownRenderer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var x=Object.create;var r=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})},u=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of T(t))!O.call(e,i)&&i!==a&&r(e,i,{get:()=>t[i],enumerable:!(s=L(t,i))||s.enumerable});return e};var l=(e,t,a)=>(a=e!=null?x(M(e)):{},u(t||!e||!e.__esModule?r(a,"default",{value:e,enumerable:!0}):a,e)),A=e=>u(r({},"__esModule",{value:!0}),e);var q={};v(q,{MarkdownRenderer:()=>p});module.exports=A(q);var w=l(require("markdown-it")),b=l(require("markdown-it-anchor"));var f=e=>encodeURIComponent(e.toLowerCase().replace(/%20/g,"-").replace(/[^가-힣ㄱ-ㅎㅏ-ㅣa-z0-9-_]/g,"-").replace(/--+/g,"-").replace(/^-|-$/g,""));var c=l(require("highlight.js"));var g=l(require("sanitize-html")),S=["a","aside","blockquote","br","circle","code","details","div","em","embed-katex","eq","eqn","h1","h2","h3","h4","h5","h6","hr","iframe","img","input","li","ol","p","pre","s","section","span","strong","summary","sup","table","tbody","td","text","th","thead","tr","ul"],I={a:["aria-hidden","class","href","id","rel","style","target","title"],aside:["class"],blockquote:["class","data-line"],br:["style"],circle:["cx","cy","fill","r"],code:["class","data-line"],details:[],div:["class"],em:[],"embed-katex":["display-mode"],eq:["class"],eqn:[],h1:["id","class","data-line"],h2:["id","class","data-line"],h3:["id","class","data-line"],h4:["id","class","data-line"],h5:["class","data-line"],h6:["class","data-line"],hr:["class","data-line"],iframe:["allow","allowfullscreen","allowtransparency","data-content","frameborder","id","loading","sandbox","scrolling","src","style","width"],img:["alt","class","height","loading","src","title","width"],input:["checked","class","type"],li:["class","id","data-line"],ol:["class","start","data-line"],p:["class","data-line"],pre:["class"],s:[],section:["class","data-line"],span:["class","title"],strong:[],summary:[],sup:["class"],table:["class","data-line"],tbody:["class","data-line"],td:["style"],text:["dominant-baseline","fill","font-size","font-weight","text-anchor","x","y"],th:["style"],thead:["class","data-line"],tr:["class","data-line"],ul:["class","data-line"]},y=e=>(0,g.default)(e,{allowedTags:S,allowedAttributes:I,disallowedTagsMode:"discard",selfClosing:["img","br","hr","area","base","basefont","input","link","meta"]});function k(e){let t=e.attrGet("href");if(t){let a=`/safe-link?url=${t}`;e.attrSet("href",a),e.attrSet("target","_blank")}}var h=require("jsdom"),o=class o{constructor(t={}){if(this.options={...o.DEFAULT_OPTIONS,...t},this.client=new w.default(this.options),this.options.useMarkdownItAnchor&&this.client.use(b.default,{slugify:f}),this.options.useSafeLinkify){let a=this.client.renderer.rules.link_open??((s,i,n,m,d)=>d.renderToken(s,i,n));this.client.renderer.rules.link_open=(s,i,n,m,d)=>(k(s[i]),a(s,i,n,m,d))}}render(t){let a=this.client.render(t),s=this.options.useSanitize?y(a):a,i=new h.JSDOM(s),n=this.parseAnchors(i.window.document.body.innerHTML);return{html:s,anchors:n}}parseAnchors(t){let a=new h.JSDOM(t);return Array.from(a.window.document.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]")).map(s=>({level:parseInt(s.tagName[1],10),slug:s.id,text:s.textContent||""}))}};o.DEFAULT_OPTIONS={html:!1,xhtmlOut:!1,langPrefix:"language-",linkify:!0,typographer:!1,highlight:(t,a)=>{if(a&&c.default.getLanguage(a))try{return c.default.highlight(t,{language:a}).value}catch{}return""},useMarkdownItAnchor:!0,useSafeLinkify:!0,useSanitize:!0};var p=o;0&&(module.exports={MarkdownRenderer});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import k from"markdown-it";import w from"markdown-it-anchor";var d=s=>encodeURIComponent(s.toLowerCase().replace(/%20/g,"-").replace(/[^가-힣ㄱ-ㅎㅏ-ㅣa-z0-9-_]/g,"-").replace(/--+/g,"-").replace(/^-|-$/g,""));import p from"highlight.js";import f from"sanitize-html";var g=["a","aside","blockquote","br","circle","code","details","div","em","embed-katex","eq","eqn","h1","h2","h3","h4","h5","h6","hr","iframe","img","input","li","ol","p","pre","s","section","span","strong","summary","sup","table","tbody","td","text","th","thead","tr","ul"],y={a:["aria-hidden","class","href","id","rel","style","target","title"],aside:["class"],blockquote:["class","data-line"],br:["style"],circle:["cx","cy","fill","r"],code:["class","data-line"],details:[],div:["class"],em:[],"embed-katex":["display-mode"],eq:["class"],eqn:[],h1:["id","class","data-line"],h2:["id","class","data-line"],h3:["id","class","data-line"],h4:["id","class","data-line"],h5:["class","data-line"],h6:["class","data-line"],hr:["class","data-line"],iframe:["allow","allowfullscreen","allowtransparency","data-content","frameborder","id","loading","sandbox","scrolling","src","style","width"],img:["alt","class","height","loading","src","title","width"],input:["checked","class","type"],li:["class","id","data-line"],ol:["class","start","data-line"],p:["class","data-line"],pre:["class"],s:[],section:["class","data-line"],span:["class","title"],strong:[],summary:[],sup:["class"],table:["class","data-line"],tbody:["class","data-line"],td:["style"],text:["dominant-baseline","fill","font-size","font-weight","text-anchor","x","y"],th:["style"],thead:["class","data-line"],tr:["class","data-line"],ul:["class","data-line"]},c=s=>f(s,{allowedTags:g,allowedAttributes:y,disallowedTagsMode:"discard",selfClosing:["img","br","hr","area","base","basefont","input","link","meta"]});function h(s){let a=s.attrGet("href");if(a){let e=`/safe-link?url=${a}`;s.attrSet("href",e),s.attrSet("target","_blank")}}import{JSDOM as m}from"jsdom";var r=class r{constructor(a={}){if(this.options={...r.DEFAULT_OPTIONS,...a},this.client=new k(this.options),this.options.useMarkdownItAnchor&&this.client.use(w,{slugify:d}),this.options.useSafeLinkify){let e=this.client.renderer.rules.link_open??((t,i,n,o,l)=>l.renderToken(t,i,n));this.client.renderer.rules.link_open=(t,i,n,o,l)=>(h(t[i]),e(t,i,n,o,l))}}render(a){let e=this.client.render(a),t=this.options.useSanitize?c(e):e,i=new m(t),n=this.parseAnchors(i.window.document.body.innerHTML);return{html:t,anchors:n}}parseAnchors(a){let e=new m(a);return Array.from(e.window.document.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]")).map(t=>({level:parseInt(t.tagName[1],10),slug:t.id,text:t.textContent||""}))}};r.DEFAULT_OPTIONS={html:!1,xhtmlOut:!1,langPrefix:"language-",linkify:!0,typographer:!1,highlight:(a,e)=>{if(e&&p.getLanguage(e))try{return p.highlight(a,{language:e}).value}catch{}return""},useMarkdownItAnchor:!0,useSafeLinkify:!0,useSanitize:!0};var u=r;export{u as MarkdownRenderer};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "loghub-me-markdown-renderer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A markdown renderer for LogHub",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --minify",
|
|
10
|
+
"test": "tsx src/test.ts"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"packageManager": "pnpm@10.13.1",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"highlight.js": "^11.11.1",
|
|
19
|
+
"jsdom": "^26.1.0",
|
|
20
|
+
"markdown-it": "^14.1.0",
|
|
21
|
+
"markdown-it-anchor": "^9.2.0",
|
|
22
|
+
"sanitize-html": "^2.17.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/jsdom": "^21.1.7",
|
|
26
|
+
"@types/markdown-it": "^14.1.2",
|
|
27
|
+
"@types/node": "^24.3.1",
|
|
28
|
+
"@types/sanitize-html": "^2.16.0",
|
|
29
|
+
"prettier": "^3.6.2",
|
|
30
|
+
"tsup": "^8.5.0",
|
|
31
|
+
"tsx": "^4.20.5",
|
|
32
|
+
"typescript": "^5.8.3"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
]
|
|
37
|
+
}
|