loghub-me-markdown-renderer 0.1.1 → 0.2.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 +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
2
|
|
|
3
3
|
interface MarkdownRendererOptions extends MarkdownIt.Options {
|
|
4
|
-
|
|
5
|
-
useSafeLinkify?: boolean;
|
|
6
|
-
useSanitize?: boolean;
|
|
4
|
+
enabledPlugins: MarkdownRendererPlugin[];
|
|
7
5
|
}
|
|
6
|
+
type MarkdownRendererPlugin = 'anchor' | 'safeLink' | 'captionedImage';
|
|
8
7
|
|
|
9
8
|
declare class MarkdownRenderer {
|
|
10
9
|
private static readonly DEFAULT_OPTIONS;
|
|
11
10
|
private readonly client;
|
|
12
11
|
private readonly options;
|
|
13
|
-
constructor(options
|
|
12
|
+
constructor(options: MarkdownRendererOptions);
|
|
14
13
|
render(markdown: string): string;
|
|
15
14
|
}
|
|
16
15
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
2
|
|
|
3
3
|
interface MarkdownRendererOptions extends MarkdownIt.Options {
|
|
4
|
-
|
|
5
|
-
useSafeLinkify?: boolean;
|
|
6
|
-
useSanitize?: boolean;
|
|
4
|
+
enabledPlugins: MarkdownRendererPlugin[];
|
|
7
5
|
}
|
|
6
|
+
type MarkdownRendererPlugin = 'anchor' | 'safeLink' | 'captionedImage';
|
|
8
7
|
|
|
9
8
|
declare class MarkdownRenderer {
|
|
10
9
|
private static readonly DEFAULT_OPTIONS;
|
|
11
10
|
private readonly client;
|
|
12
11
|
private readonly options;
|
|
13
|
-
constructor(options
|
|
12
|
+
constructor(options: MarkdownRendererOptions);
|
|
14
13
|
render(markdown: string): string;
|
|
15
14
|
}
|
|
16
15
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.create;var
|
|
1
|
+
"use strict";var w=Object.create;var o=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var a in t)o(e,a,{get:t[a],enumerable:!0})},b=(e,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of v(t))!I.call(e,i)&&i!==a&&o(e,i,{get:()=>t[i],enumerable:!(n=R(t,i))||n.enumerable});return e};var c=(e,t,a)=>(a=e!=null?w(L(e)):{},b(t||!e||!e.__esModule?o(a,"default",{value:e,enumerable:!0}):a,e)),S=e=>b(o({},"__esModule",{value:!0}),e);var P={};O(P,{MarkdownRenderer:()=>y});module.exports=S(P);var d=c(require("highlight.js")),x=c(require("markdown-it")),T=c(require("markdown-it-anchor"));var p=e=>encodeURIComponent(e.toLowerCase().replace(/%20/g,"-").replace(/[^가-힣ㄱ-ㅎㅏ-ㅣa-z0-9-_]/g,"-").replace(/--+/g,"-").replace(/^-|-$/g,""));function h(e){let t=e.attrGet("href");if(t)try{let a=new URL(t);a.protocol="https:";let n=`/safe-link?url=${a.toString()}`;e.attrSet("href",n),e.attrSet("target","_blank")}catch{return}}function f(e,t){e.attrSet("loading","lazy");let n=e.attrGet("title")?.trim();return n?(e.attrSet("class","mx-auto"),`<figure>${t()}<figcaption class="mt-2 text-sm text-center text-muted-foreground">${n}</figcaption></figure>`):t()}var k=c(require("sanitize-html")),z=["a","aside","blockquote","br","circle","code","details","div","em","eq","eqn","figure","figcaption","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"],M={a:["aria-hidden","class","href","id","rel","style","target","title"],aside:["class"],blockquote:["class","data-line","align"],br:["style"],circle:["cx","cy","fill","r"],code:["class","data-line"],details:[],div:["class"],em:[],eq:["class"],eqn:[],figure:["class","data-line"],figcaption:["class","data-line"],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","align"],pre:["class"],s:[],section:["class","data-line"],span:["class","title","align"],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"]},m=e=>(0,k.default)(e,{allowedTags:z,allowedAttributes:M,disallowedTagsMode:"discard",selfClosing:["img","br","hr","area","base","basefont","input","link","meta"]});var g=class g{constructor(t){this.options={...g.DEFAULT_OPTIONS,...t},this.client=new x.default(this.options);let a=(n,i,r,l,s)=>s.renderToken(n,i,r);if(this.options.enabledPlugins.includes("anchor")&&this.client.use(T.default,{slugify:p}),this.options.enabledPlugins.includes("safeLink")){let n=this.client.renderer.rules.link_open||a;this.client.renderer.rules.link_open=(i,r,l,s,u)=>(h(i[r]),n(i,r,l,s,u))}if(this.options.enabledPlugins.includes("captionedImage")){let n=this.client.renderer.rules.image||a;this.client.renderer.rules.image=(i,r,l,s,u)=>f(i[r],()=>n(i,r,l,s,u))}}render(t){let a=this.client.render(t);return m(a)}};g.DEFAULT_OPTIONS={html:!0,xhtmlOut:!0,langPrefix:"language-",linkify:!0,typographer:!1,highlight:(t,a)=>{try{return a&&d.default.getLanguage(a)?d.default.highlight(t,{language:a}).value:d.default.highlightAuto(t).value}catch{return""}},enabledPlugins:["anchor","safeLink","captionedImage"]};var y=g;0&&(module.exports={MarkdownRenderer});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import h from"highlight.js";import k from"markdown-it";import x from"markdown-it-anchor";var d=a=>encodeURIComponent(a.toLowerCase().replace(/%20/g,"-").replace(/[^가-힣ㄱ-ㅎㅏ-ㅣa-z0-9-_]/g,"-").replace(/--+/g,"-").replace(/^-|-$/g,""));function g(a){let e=a.attrGet("href");if(e)try{let t=new URL(e);t.protocol="https:";let i=`/safe-link?url=${t.toString()}`;a.attrSet("href",i),a.attrSet("target","_blank")}catch{return}}function u(a,e){a.attrSet("loading","lazy");let i=a.attrGet("title")?.trim();return i?(a.attrSet("class","mx-auto"),`<figure>${e()}<figcaption class="mt-2 text-sm text-center text-muted-foreground">${i}</figcaption></figure>`):e()}import m from"sanitize-html";var y=["a","aside","blockquote","br","circle","code","details","div","em","eq","eqn","figure","figcaption","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"],b={a:["aria-hidden","class","href","id","rel","style","target","title"],aside:["class"],blockquote:["class","data-line","align"],br:["style"],circle:["cx","cy","fill","r"],code:["class","data-line"],details:[],div:["class"],em:[],eq:["class"],eqn:[],figure:["class","data-line"],figcaption:["class","data-line"],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","align"],pre:["class"],s:[],section:["class","data-line"],span:["class","title","align"],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"]},p=a=>m(a,{allowedTags:y,allowedAttributes:b,disallowedTagsMode:"discard",selfClosing:["img","br","hr","area","base","basefont","input","link","meta"]});var o=class o{constructor(e){this.options={...o.DEFAULT_OPTIONS,...e},this.client=new k(this.options);let t=(i,n,r,l,s)=>s.renderToken(i,n,r);if(this.options.enabledPlugins.includes("anchor")&&this.client.use(x,{slugify:d}),this.options.enabledPlugins.includes("safeLink")){let i=this.client.renderer.rules.link_open||t;this.client.renderer.rules.link_open=(n,r,l,s,c)=>(g(n[r]),i(n,r,l,s,c))}if(this.options.enabledPlugins.includes("captionedImage")){let i=this.client.renderer.rules.image||t;this.client.renderer.rules.image=(n,r,l,s,c)=>u(n[r],()=>i(n,r,l,s,c))}}render(e){let t=this.client.render(e);return p(t)}};o.DEFAULT_OPTIONS={html:!0,xhtmlOut:!0,langPrefix:"language-",linkify:!0,typographer:!1,highlight:(e,t)=>{try{return t&&h.getLanguage(t)?h.highlight(e,{language:t}).value:h.highlightAuto(e).value}catch{return""}},enabledPlugins:["anchor","safeLink","captionedImage"]};var f=o;export{f as MarkdownRenderer};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loghub-me-markdown-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A markdown renderer for LogHub",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup src/index.ts --format cjs,esm --dts --minify",
|
|
10
|
-
"test": "tsx
|
|
10
|
+
"test": "node --test --import tsx test/*.ts"
|
|
11
11
|
},
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"keywords": [],
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/node": "^24.3.1",
|
|
27
27
|
"@types/sanitize-html": "^2.16.0",
|
|
28
28
|
"prettier": "^3.6.2",
|
|
29
|
-
"tsup": "^8.5.
|
|
29
|
+
"tsup": "^8.5.1",
|
|
30
30
|
"tsx": "^4.20.5",
|
|
31
31
|
"typescript": "^5.8.3"
|
|
32
32
|
},
|