@traptitech/traq-markdown-it
Advanced tools
Comparing version 5.3.1 to 5.3.2
@@ -716,2 +716,9 @@ 'use strict'; | ||
}; | ||
this.katexOptions = { | ||
katex: katexE, | ||
output: 'html', | ||
strict: errCode => errCode === 'unicodeTextInMathMode' ? 'ignore' : 'warn', | ||
maxSize: 100, | ||
blockClass: 'is-scroll' | ||
}; | ||
this.md = new MarkdownIt(this.mdOptions); | ||
@@ -725,9 +732,3 @@ this.inlineRenderer = new InlineRenderer(); | ||
setPlugin(store, whitelist) { | ||
this.md.use(MarkdownItMark).use(spoiler, true).use(messageExtendsPlugin, store).use(stampPlugin, store).use(katex, { | ||
katex: katexE, | ||
output: 'html', | ||
strict: errCode => errCode === 'unicodeTextInMathMode' ? 'ignore' : 'warn', | ||
maxSize: 100, | ||
blockClass: 'is-scroll' | ||
}).use(mila, { | ||
this.md.use(MarkdownItMark).use(spoiler, true).use(messageExtendsPlugin, store).use(stampPlugin, store).use(katex, this.katexOptions).use(mila, { | ||
attrs: { | ||
@@ -740,4 +741,17 @@ target: '_blank', | ||
})); | ||
const dummyMd = new MarkdownIt(this.mdOptions); | ||
dummyMd.use(katex, { ...this.katexOptions, | ||
maxSize: 1, | ||
macros: { | ||
// 文字サイズを変更する関数を無効化する | ||
'\\Huge': () => '', | ||
'\\huge': () => '', | ||
'\\LARGE': () => '', | ||
'\\Large': () => '', | ||
'\\large': () => '' | ||
} | ||
}); | ||
this.inlineRenderer.setRules(this.md.renderer.rules, { | ||
math_block: this.md.renderer.rules.math_inline | ||
math_inline: dummyMd.renderer.rules.math_inline, | ||
math_block: dummyMd.renderer.rules.math_inline | ||
}); | ||
@@ -744,0 +758,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("markdown-it")),r=e(require("markdown-it-mark")),i=e(require("@traptitech/markdown-it-spoiler")),s=e(require("@traptitech/markdown-it-regexp")),n=e(require("markdown-it-json")),a=e(require("@traptitech/markdown-it-katex")),l=e(require("katex")),o=e(require("markdown-it-link-attributes")),c=e(require("markdown-it-image-filter")),p=e(require("highlight.js")),u=e(require("markdown-it/lib/renderer")),d=e(require("markdown-it-container"));const h=/[&<>"]/g,g=new Map([["&","&"],["<","<"],[">",">"],['"',"""]]),m=e=>g.get(e),f=e=>h.test(e)?e.replace(h,m):e,k=["ex-large","large","small"];let b,v="";const x=new Set(["rotate","rotate-inv","wiggle","parrot","zoom","inversion","turn","turn-v","happa","pyon","flashy","pull","atsumori","stretch","stretch-v","conga","conga-inv","marquee","marquee-inv","rainbow","ascension","shake","party","attract"]),y=new Set(k),_=new Map([["marquee","conga"],["marquee-inv","conga-inv"]]),$=e=>y.has(e),w=e=>x.has(e),q=(e,t,r,i,s)=>{const n=f(r),a=f(i),l=f(t),o=s.filter($),c=s.filter(w);if(o.length+c.length<s.length)return e;if(c.length>5)return e;const p=c.map(e=>{var t;return null!==(t=_.get(e))&&void 0!==t?t:e}),u=o[o.length-1]||"";return((e,t,r)=>t.map((e,t)=>`<span class="emoji-effect ${e}${0===t&&r?" "+r:""}">`).join("")+e+"</span>".repeat(t.length))(`<i class="emoji message-emoji ${u}" title=":${n}:" style="${a};">:${l}:</i>`,p,u)},j=(e,t,r,i,s)=>q(e,t,r,`background-image: url(${i})`,s),R=/^[a-zA-Z0-9+_-]{1,32}$/,T=/(?<color>hsl\(\d+,\s*[\d]+(?:\.[\d]+)?%,\s*[\d]+(?:\.[\d]+)?%\))(?<effects>.*)/,E=/0x(?<color>[0-9a-fA-F]{6})(?<effects>.*)/,M=e=>{const t=e[0],{inner:r}=e.groups,i=E.exec(r);if(i)return(e=>{const{color:t,effects:r}=e.groups;return q(`:${e[0]}:`,"0x"+t,"0x"+t,"background-color: #"+t,""===r?[]:r.split(".").slice(1))})(i);const s=T.exec(r);if(s)return(e=>{const{color:t,effects:r}=e.groups;return q(`:${e[0]}:`,t,t,"background-color: "+t,""===r?[]:r.split(".").slice(1))})(s);const[n="",...a]=r.split(".");return n.startsWith("@")?((e,t,r)=>{const i=e.slice(1),s=b.getUserByName(i);return s?j(t,e,e,`${v}/api/v3/files/${s.iconFileId}`,r):t})(n,t,a):R.exec(n)?((e,t,r)=>{const i=b.getStampByName(e);return i?j(t,e,i.name,`${v}/api/v3/files/${i.fileId}`,r):t})(n,t,a):t},P=/:(?<inner>(?:[a-zA-Z0-9+_-]{1,32}|@(?:Webhook#)?[a-zA-Z0-9_-]+|\w+\([^:<>"'=+!?]+\))[\w+-.]*):/;function z(e,t,r){b=t,r&&(v=r),s(P,M)(e)}let I;const O=e=>{if(!(e=>"string"==typeof e.type&&"string"==typeof e.raw&&"string"==typeof e.id)(e))return!1;const{type:t,id:r}=e;return"user"===t||"channel"===t&&!!I.getChannel(r)||"group"===t},A=(e,t)=>{"user"!==t.type?"channel"===t.type&&I.getChannel(t.id)?((e,{type:t,id:r,raw:i})=>{const s=[];s.push(["href",`javascript:changeChannel('${I.getChannelPath(r)}')`]),s.push(["class","message-channel-link"]);let n=e.push("traq_extends_link_open","a",1);n.attrs=s,n.meta={type:t,data:i},n=e.push("text","",0),n.content=i,e.push("traq_extends_link_close","a",-1)})(e,t):"group"!==t.type||((e,{type:t,id:r,raw:i})=>{var s,n;const a=[],l=I.getUserGroup(r),o=I.getMe();a.push(["href",`javascript:openGroupModal('${r}')`]),null!==(s=null==l||null===(n=l.members)||void 0===n?void 0:n.some(e=>e.id===(null==o?void 0:o.id)))&&void 0!==s&&s?a.push(["class","message-group-link-highlight message-group-link"]):a.push(["class","message-group-link"]);let c=e.push("traq_extends_link_open","a",1);c.attrs=a,c.meta={type:t,data:r},c=e.push("text","",0),c.content=i,e.push("traq_extends_link_close","a",-1)})(e,t):((e,{type:t,id:r,raw:i})=>{const s=[],n=I.getMe();s.push(["href",`javascript:openUserModal('${r}')`]),s.push(r===(null==n?void 0:n.id)?["class","message-user-link-highlight message-user-link"]:["class","message-user-link"]);let a=e.push("traq_extends_link_open","a",1);a.attrs=s,a.meta={type:t,data:r},a=e.push("text","",0),a.content=i,e.push("traq_extends_link_close","a",-1)})(e,t)};function C(e,t){I=t,n(O,A)(e)}var S=["actionscript","awk","bash","basic","bnf","brainfuck","csharp","h","cpp","cmake","coq","css","clojure","coffeescript","crystal","d","dart","delphi","diff","django","dockerfile","elixir","elm","fsharp","fortran","go","gradle","groovy","xml","http","haml","handlebars","haxe","ini","json","java","javascript","kotlin","tex","less","lisp","livescript","lua","makefile","markdown","mathematica","matlab","moonscript","nginx","nimrod","ocaml","objectivec","glsl","php","perl","plaintext","pgsql","powershell","processing","prolog","protobuf","python","k","r","ruby","scss","sql","scheme","shell","stylus","swift","twig","typescript","vbnet","vbscript","verilog","vim","x86asm","xquery","yaml","zephir"];const F=/^(no-?highlight|plain|text)$/i,U=(e,t=!0,r=!0)=>(i,s)=>{let n,a="";if(t){const[e,t]=s.split(":");n=null!=e?e:"",t&&(a=`<cite>${f(t)}</cite>`)}else n=s;if(p.getLanguage(n)){const t=p.highlight(i,{language:n});return`<pre class="${e}">${a}<code class="lang-${t.language}">${t.value}</code></pre>`}if(F.test(n))return`<pre class="${e}">${a}<code>${f(i)}</code></pre>`;{const t=p.highlightAuto(i,r?S:void 0);return`<pre class="${e}">${a}<code class="lang-${t.language}">${t.value}</code></pre>`}};var Z=["libra.tokyotech.org","user-images.githubusercontent.com","git.trap.jp","wiki.trapti.tech","wiki.trap.jp","md.trapti.tech","md.trap.jp","trap.jp","traq-dev.tokyotech.org"];const G=/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}/;class N{constructor(e){this.pathNameEmbeddingTypeMap=new Map([["files","file"],["messages","message"]]),this.embeddingOrigin=e}extractType(e){var t,r;if(e.origin!==this.embeddingOrigin)return"url";const i=null!==(t=e.pathname.split("/")[1])&&void 0!==t?t:"";return null!==(r=this.pathNameEmbeddingTypeMap.get(i))&&void 0!==r?r:"internal"}extractId(e,t){var r;if(e.origin!==this.embeddingOrigin||"url"===t||"internal"===t)return;const i=null!==(r=e.pathname.split("/")[2])&&void 0!==r?r:"";return G.test(i)?i:void 0}urlToEmbeddingData(e){let t;try{t=new URL(e)}catch{return}if("http:"!==t.protocol&&"https:"!==t.protocol)return;const r=this.extractType(t),i=this.extractId(t,r);return"internal"!==r?"url"===r?{type:r,url:e}:i?{type:r,id:i}:void 0:void 0}extractUrlsFromTokens(e,t=[]){let r=0;for(const i of e)if(i.children)this.extractUrlsFromTokens(i.children,t);else if("spoiler_open"!==i.type){if("spoiler_close"===i.type&&r>0)r--;else if(!(r>0)&&"link_open"===i.type){const e=i.attrGet("href");if(e){const r=this.urlToEmbeddingData(e);r&&(i.embedding=r,t.push(r))}}}else r++;return t}extract(e){const t=this.extractUrlsFromTokens(e),r=new Set,i=[];for(const e of t)"internal"!==e.type&&("url"!==e.type?r.has(e.id)||(r.add(e.id),i.push(e)):i.push(e));return i}removeTailEmbeddingsFromTailParagraph(e){let t=!1,r=-1;for(let s=e.length-1;s>=0;s--){const n=e[s];if("softbreak"!==n.type){if("link_open"===n.type&&"linkify"===n.markup){var i;t=!1;const e=null===(i=n.embedding)||void 0===i?void 0:i.type;if("file"===e||"message"===e){r=s;continue}}if(!t){if("link_close"!==n.type||"linkify"!==n.markup){if(-1===r)return!1;break}t=!0}}else r>0&&!t&&(r=s)}return e.splice(r,e.length-r),!0}removeTailEmbeddings(e){let t=!1,r=void 0;for(let s=e.length-1;s>=0;s--){const n=e[s];if("hardbreak"!==n.type)if("paragraph_close"!==n.type){if(!t||"inline"!==n.type||!n.children)return;if(this.removeTailEmbeddingsFromTailParagraph(n.children)){var i;e.splice(s+1,e.length-(s+1));const t=e[e.length-1];t&&"inline"===t.type&&0===(null===(i=t.children)||void 0===i?void 0:i.length)&&e.pop(),r&&e.push(r)}}else t=!0,r=n}}replace(e){let t=void 0;for(const r of e)r.children?this.replace(r.children):(r.embedding&&(t=r),t&&("text"!==r.type?"link_close"!==r.type||"linkify"!==r.markup||(t=void 0):"message"===t.embedding.type?r.content="[[引用メッセージ]]":"file"===t.embedding.type&&(r.content="[[添付ファイル]]")))}}class W extends u{constructor(){super(...arguments),this.blockRules={}}setRules(e=null,t={}){null!==e&&(this.rules={...e}),this.rules.softbreak=()=>" ",this.blockRules.softbreak=()=>" ",this.rules.hardbreak=()=>" ",this.blockRules.hardbreak=()=>" ",this.rules.image=(e,t)=>{var r,i;const s=e[t],n=(null!==(r=s.attrs)&&void 0!==r?r:[]).filter(([e])=>"src"!==e&&"alt"!==e).map(([e,t])=>`${f(e)}="${f(t)}"`).join(" ");return`<a href="${null!==(i=s.attrGet("src"))&&void 0!==i?i:""}" ${n} data-is-image>${s.content}</a>`},this.blockRules.code_block=this.rules.code_inline,this.blockRules.fence=this.rules.code_inline,this.blockRules.hr=(e,t)=>` ${e[t].markup} `,this.blockRules.heading_open=(e,t)=>"#".repeat(+e[t].tag.slice(1))+" ",this.blockRules.blockquote_open=(e,t)=>e[t].markup+" ",this.blockRules.list_item_open=(e,t)=>e[t].markup+" ",this.blockRules.th_open=()=>"| ",this.blockRules.td_open=()=>"| ",this.blockRules.tr_close=()=>" |";for(const[e,r]of Object.entries(t))this.rules[e]=r,this.blockRules[e]=r}renderContent(e){return f(e.content)}render(e,t,r){let i="";for(const[a,l]of e.entries()){var s;const o=l.type,c=this.blockRules[o];var n;1===l.nesting&&-1===(null===(s=e[a-1])||void 0===s?void 0:s.nesting)&&(i+=" "),i+="inline"===o?this.renderInline(null!==(n=l.children)&&void 0!==n?n:[],t,r):void 0!==c?c(e,a,t,r,this):this.renderContent(l)}return i}}const L=["success","info","warning","danger"],B=/:((?:[a-zA-Z0-9+_-]{1,32}|@[a-zA-Z0-9_-]+)[\w+-.]*):/,D=/:((?:[a-zA-Z0-9+_-]{1,32}|@[a-zA-Z0-9_-]+)[\w+-.]*)[:;]/;exports.markPlugin=r,exports.spoilerPlugin=i,exports.katexPlugin=a,exports.animeEffectSet=x,exports.createHighlightFunc=U,exports.jsonPlugin=C,exports.sizeEffectSet=y,exports.stampCssPlugin=(e,t,r=!1)=>{s(r?D:B,([e="",i=""])=>{const s=r?e.endsWith(":")?32:16:24;return i.startsWith("@")?((e,t,r)=>`<i class="emoji s${r}" title="${e}" style="background-image: url(https://q.trap.jp/api/v3/public/icon/${t.slice(1)})">${e}</i>`)(e,i,s):t.includes(i)?((e,t,r)=>`<i class="emoji s${r} ${"e_"+t.replace(/\+/g,"_-plus-_")}" title="${e}">${e}</i>`)(e,i,s):e})(e)},exports.stampPlugin=z,exports.traQMarkdownIt=class{constructor(e,r=Z,i){this.mdOptions={breaks:!0,linkify:!0,highlight:U("traq-code traq-lang")},this.md=new t(this.mdOptions),this.inlineRenderer=new W,this.embeddingExtractor=new N(i),this.setRendererRule(),this.setPlugin(e,r)}setPlugin(e,t){this.md.use(r).use(i,!0).use(C,e).use(z,e).use(a,{katex:l,output:"html",strict:e=>"unicodeTextInMathMode"===e?"ignore":"warn",maxSize:100,blockClass:"is-scroll"}).use(o,{attrs:{target:"_blank",rel:"nofollow noopener noreferrer"}}).use(c(t,{httpsOnly:!0})),this.inlineRenderer.setRules(this.md.renderer.rules,{math_block:this.md.renderer.rules.math_inline})}setRendererRule(){this.md.block.State.prototype.skipEmptyLines=function(e){for(let t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++)this.push("hardbreak","br",0);return e}}_render(e){return this.md.renderer.render(e,this.mdOptions,{})}render(e){const t=this.md.parse(e,{}),r=this.embeddingExtractor.extract(t);return this.embeddingExtractor.removeTailEmbeddings(t),{embeddings:r,rawText:e,renderedText:this._render(t)}}_renderInline(e){return this.inlineRenderer.render(e,this.mdOptions,{})}renderInline(e){const t=this.md.parse(e,{}),r=this.embeddingExtractor.extract(t);return this.embeddingExtractor.removeTailEmbeddings(t),this.embeddingExtractor.replace(t),{embeddings:r,rawText:e,renderedText:this._renderInline(t)}}},exports.useContainer=(e,t=L)=>{t.forEach(t=>{e.use(d,t)})}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("markdown-it")),r=e(require("markdown-it-mark")),i=e(require("@traptitech/markdown-it-spoiler")),s=e(require("@traptitech/markdown-it-regexp")),n=e(require("markdown-it-json")),a=e(require("@traptitech/markdown-it-katex")),l=e(require("katex")),o=e(require("markdown-it-link-attributes")),c=e(require("markdown-it-image-filter")),p=e(require("highlight.js")),u=e(require("markdown-it/lib/renderer")),d=e(require("markdown-it-container"));const h=/[&<>"]/g,g=new Map([["&","&"],["<","<"],[">",">"],['"',"""]]),m=e=>g.get(e),f=e=>h.test(e)?e.replace(h,m):e,k=["ex-large","large","small"];let b,x="";const v=new Set(["rotate","rotate-inv","wiggle","parrot","zoom","inversion","turn","turn-v","happa","pyon","flashy","pull","atsumori","stretch","stretch-v","conga","conga-inv","marquee","marquee-inv","rainbow","ascension","shake","party","attract"]),y=new Set(k),_=new Map([["marquee","conga"],["marquee-inv","conga-inv"]]),w=e=>y.has(e),$=e=>v.has(e),q=(e,t,r,i,s)=>{const n=f(r),a=f(i),l=f(t),o=s.filter(w),c=s.filter($);if(o.length+c.length<s.length)return e;if(c.length>5)return e;const p=c.map(e=>{var t;return null!==(t=_.get(e))&&void 0!==t?t:e}),u=o[o.length-1]||"";return((e,t,r)=>t.map((e,t)=>`<span class="emoji-effect ${e}${0===t&&r?" "+r:""}">`).join("")+e+"</span>".repeat(t.length))(`<i class="emoji message-emoji ${u}" title=":${n}:" style="${a};">:${l}:</i>`,p,u)},j=(e,t,r,i,s)=>q(e,t,r,`background-image: url(${i})`,s),R=/^[a-zA-Z0-9+_-]{1,32}$/,T=/(?<color>hsl\(\d+,\s*[\d]+(?:\.[\d]+)?%,\s*[\d]+(?:\.[\d]+)?%\))(?<effects>.*)/,E=/0x(?<color>[0-9a-fA-F]{6})(?<effects>.*)/,M=e=>{const t=e[0],{inner:r}=e.groups,i=E.exec(r);if(i)return(e=>{const{color:t,effects:r}=e.groups;return q(`:${e[0]}:`,"0x"+t,"0x"+t,"background-color: #"+t,""===r?[]:r.split(".").slice(1))})(i);const s=T.exec(r);if(s)return(e=>{const{color:t,effects:r}=e.groups;return q(`:${e[0]}:`,t,t,"background-color: "+t,""===r?[]:r.split(".").slice(1))})(s);const[n="",...a]=r.split(".");return n.startsWith("@")?((e,t,r)=>{const i=e.slice(1),s=b.getUserByName(i);return s?j(t,e,e,`${x}/api/v3/files/${s.iconFileId}`,r):t})(n,t,a):R.exec(n)?((e,t,r)=>{const i=b.getStampByName(e);return i?j(t,e,i.name,`${x}/api/v3/files/${i.fileId}`,r):t})(n,t,a):t},O=/:(?<inner>(?:[a-zA-Z0-9+_-]{1,32}|@(?:Webhook#)?[a-zA-Z0-9_-]+|\w+\([^:<>"'=+!?]+\))[\w+-.]*):/;function z(e,t,r){b=t,r&&(x=r),s(O,M)(e)}let P;const A=e=>{if(!(e=>"string"==typeof e.type&&"string"==typeof e.raw&&"string"==typeof e.id)(e))return!1;const{type:t,id:r}=e;return"user"===t||"channel"===t&&!!P.getChannel(r)||"group"===t},I=(e,t)=>{"user"!==t.type?"channel"===t.type&&P.getChannel(t.id)?((e,{type:t,id:r,raw:i})=>{const s=[];s.push(["href",`javascript:changeChannel('${P.getChannelPath(r)}')`]),s.push(["class","message-channel-link"]);let n=e.push("traq_extends_link_open","a",1);n.attrs=s,n.meta={type:t,data:i},n=e.push("text","",0),n.content=i,e.push("traq_extends_link_close","a",-1)})(e,t):"group"!==t.type||((e,{type:t,id:r,raw:i})=>{var s,n;const a=[],l=P.getUserGroup(r),o=P.getMe();a.push(["href",`javascript:openGroupModal('${r}')`]),null!==(s=null==l||null===(n=l.members)||void 0===n?void 0:n.some(e=>e.id===(null==o?void 0:o.id)))&&void 0!==s&&s?a.push(["class","message-group-link-highlight message-group-link"]):a.push(["class","message-group-link"]);let c=e.push("traq_extends_link_open","a",1);c.attrs=a,c.meta={type:t,data:r},c=e.push("text","",0),c.content=i,e.push("traq_extends_link_close","a",-1)})(e,t):((e,{type:t,id:r,raw:i})=>{const s=[],n=P.getMe();s.push(["href",`javascript:openUserModal('${r}')`]),s.push(r===(null==n?void 0:n.id)?["class","message-user-link-highlight message-user-link"]:["class","message-user-link"]);let a=e.push("traq_extends_link_open","a",1);a.attrs=s,a.meta={type:t,data:r},a=e.push("text","",0),a.content=i,e.push("traq_extends_link_close","a",-1)})(e,t)};function S(e,t){P=t,n(A,I)(e)}var C=["actionscript","awk","bash","basic","bnf","brainfuck","csharp","h","cpp","cmake","coq","css","clojure","coffeescript","crystal","d","dart","delphi","diff","django","dockerfile","elixir","elm","fsharp","fortran","go","gradle","groovy","xml","http","haml","handlebars","haxe","ini","json","java","javascript","kotlin","tex","less","lisp","livescript","lua","makefile","markdown","mathematica","matlab","moonscript","nginx","nimrod","ocaml","objectivec","glsl","php","perl","plaintext","pgsql","powershell","processing","prolog","protobuf","python","k","r","ruby","scss","sql","scheme","shell","stylus","swift","twig","typescript","vbnet","vbscript","verilog","vim","x86asm","xquery","yaml","zephir"];const F=/^(no-?highlight|plain|text)$/i,U=(e,t=!0,r=!0)=>(i,s)=>{let n,a="";if(t){const[e,t]=s.split(":");n=null!=e?e:"",t&&(a=`<cite>${f(t)}</cite>`)}else n=s;if(p.getLanguage(n)){const t=p.highlight(i,{language:n});return`<pre class="${e}">${a}<code class="lang-${t.language}">${t.value}</code></pre>`}if(F.test(n))return`<pre class="${e}">${a}<code>${f(i)}</code></pre>`;{const t=p.highlightAuto(i,r?C:void 0);return`<pre class="${e}">${a}<code class="lang-${t.language}">${t.value}</code></pre>`}};var Z=["libra.tokyotech.org","user-images.githubusercontent.com","git.trap.jp","wiki.trapti.tech","wiki.trap.jp","md.trapti.tech","md.trap.jp","trap.jp","traq-dev.tokyotech.org"];const G=/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}/;class L{constructor(e){this.pathNameEmbeddingTypeMap=new Map([["files","file"],["messages","message"]]),this.embeddingOrigin=e}extractType(e){var t,r;if(e.origin!==this.embeddingOrigin)return"url";const i=null!==(t=e.pathname.split("/")[1])&&void 0!==t?t:"";return null!==(r=this.pathNameEmbeddingTypeMap.get(i))&&void 0!==r?r:"internal"}extractId(e,t){var r;if(e.origin!==this.embeddingOrigin||"url"===t||"internal"===t)return;const i=null!==(r=e.pathname.split("/")[2])&&void 0!==r?r:"";return G.test(i)?i:void 0}urlToEmbeddingData(e){let t;try{t=new URL(e)}catch{return}if("http:"!==t.protocol&&"https:"!==t.protocol)return;const r=this.extractType(t),i=this.extractId(t,r);return"internal"!==r?"url"===r?{type:r,url:e}:i?{type:r,id:i}:void 0:void 0}extractUrlsFromTokens(e,t=[]){let r=0;for(const i of e)if(i.children)this.extractUrlsFromTokens(i.children,t);else if("spoiler_open"!==i.type){if("spoiler_close"===i.type&&r>0)r--;else if(!(r>0)&&"link_open"===i.type){const e=i.attrGet("href");if(e){const r=this.urlToEmbeddingData(e);r&&(i.embedding=r,t.push(r))}}}else r++;return t}extract(e){const t=this.extractUrlsFromTokens(e),r=new Set,i=[];for(const e of t)"internal"!==e.type&&("url"!==e.type?r.has(e.id)||(r.add(e.id),i.push(e)):i.push(e));return i}removeTailEmbeddingsFromTailParagraph(e){let t=!1,r=-1;for(let s=e.length-1;s>=0;s--){const n=e[s];if("softbreak"!==n.type){if("link_open"===n.type&&"linkify"===n.markup){var i;t=!1;const e=null===(i=n.embedding)||void 0===i?void 0:i.type;if("file"===e||"message"===e){r=s;continue}}if(!t){if("link_close"!==n.type||"linkify"!==n.markup){if(-1===r)return!1;break}t=!0}}else r>0&&!t&&(r=s)}return e.splice(r,e.length-r),!0}removeTailEmbeddings(e){let t=!1,r=void 0;for(let s=e.length-1;s>=0;s--){const n=e[s];if("hardbreak"!==n.type)if("paragraph_close"!==n.type){if(!t||"inline"!==n.type||!n.children)return;if(this.removeTailEmbeddingsFromTailParagraph(n.children)){var i;e.splice(s+1,e.length-(s+1));const t=e[e.length-1];t&&"inline"===t.type&&0===(null===(i=t.children)||void 0===i?void 0:i.length)&&e.pop(),r&&e.push(r)}}else t=!0,r=n}}replace(e){let t=void 0;for(const r of e)r.children?this.replace(r.children):(r.embedding&&(t=r),t&&("text"!==r.type?"link_close"!==r.type||"linkify"!==r.markup||(t=void 0):"message"===t.embedding.type?r.content="[[引用メッセージ]]":"file"===t.embedding.type&&(r.content="[[添付ファイル]]")))}}class N extends u{constructor(){super(...arguments),this.blockRules={}}setRules(e=null,t={}){null!==e&&(this.rules={...e}),this.rules.softbreak=()=>" ",this.blockRules.softbreak=()=>" ",this.rules.hardbreak=()=>" ",this.blockRules.hardbreak=()=>" ",this.rules.image=(e,t)=>{var r,i;const s=e[t],n=(null!==(r=s.attrs)&&void 0!==r?r:[]).filter(([e])=>"src"!==e&&"alt"!==e).map(([e,t])=>`${f(e)}="${f(t)}"`).join(" ");return`<a href="${null!==(i=s.attrGet("src"))&&void 0!==i?i:""}" ${n} data-is-image>${s.content}</a>`},this.blockRules.code_block=this.rules.code_inline,this.blockRules.fence=this.rules.code_inline,this.blockRules.hr=(e,t)=>` ${e[t].markup} `,this.blockRules.heading_open=(e,t)=>"#".repeat(+e[t].tag.slice(1))+" ",this.blockRules.blockquote_open=(e,t)=>e[t].markup+" ",this.blockRules.list_item_open=(e,t)=>e[t].markup+" ",this.blockRules.th_open=()=>"| ",this.blockRules.td_open=()=>"| ",this.blockRules.tr_close=()=>" |";for(const[e,r]of Object.entries(t))this.rules[e]=r,this.blockRules[e]=r}renderContent(e){return f(e.content)}render(e,t,r){let i="";for(const[a,l]of e.entries()){var s;const o=l.type,c=this.blockRules[o];var n;1===l.nesting&&-1===(null===(s=e[a-1])||void 0===s?void 0:s.nesting)&&(i+=" "),i+="inline"===o?this.renderInline(null!==(n=l.children)&&void 0!==n?n:[],t,r):void 0!==c?c(e,a,t,r,this):this.renderContent(l)}return i}}const W=["success","info","warning","danger"],B=/:((?:[a-zA-Z0-9+_-]{1,32}|@[a-zA-Z0-9_-]+)[\w+-.]*):/,D=/:((?:[a-zA-Z0-9+_-]{1,32}|@[a-zA-Z0-9_-]+)[\w+-.]*)[:;]/;exports.markPlugin=r,exports.spoilerPlugin=i,exports.katexPlugin=a,exports.animeEffectSet=v,exports.createHighlightFunc=U,exports.jsonPlugin=S,exports.sizeEffectSet=y,exports.stampCssPlugin=(e,t,r=!1)=>{s(r?D:B,([e="",i=""])=>{const s=r?e.endsWith(":")?32:16:24;return i.startsWith("@")?((e,t,r)=>`<i class="emoji s${r}" title="${e}" style="background-image: url(https://q.trap.jp/api/v3/public/icon/${t.slice(1)})">${e}</i>`)(e,i,s):t.includes(i)?((e,t,r)=>`<i class="emoji s${r} ${"e_"+t.replace(/\+/g,"_-plus-_")}" title="${e}">${e}</i>`)(e,i,s):e})(e)},exports.stampPlugin=z,exports.traQMarkdownIt=class{constructor(e,r=Z,i){this.mdOptions={breaks:!0,linkify:!0,highlight:U("traq-code traq-lang")},this.katexOptions={katex:l,output:"html",strict:e=>"unicodeTextInMathMode"===e?"ignore":"warn",maxSize:100,blockClass:"is-scroll"},this.md=new t(this.mdOptions),this.inlineRenderer=new N,this.embeddingExtractor=new L(i),this.setRendererRule(),this.setPlugin(e,r)}setPlugin(e,s){this.md.use(r).use(i,!0).use(S,e).use(z,e).use(a,this.katexOptions).use(o,{attrs:{target:"_blank",rel:"nofollow noopener noreferrer"}}).use(c(s,{httpsOnly:!0}));const n=new t(this.mdOptions);n.use(a,{...this.katexOptions,maxSize:1,macros:{"\\Huge":()=>"","\\huge":()=>"","\\LARGE":()=>"","\\Large":()=>"","\\large":()=>""}}),this.inlineRenderer.setRules(this.md.renderer.rules,{math_inline:n.renderer.rules.math_inline,math_block:n.renderer.rules.math_inline})}setRendererRule(){this.md.block.State.prototype.skipEmptyLines=function(e){for(let t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++)this.push("hardbreak","br",0);return e}}_render(e){return this.md.renderer.render(e,this.mdOptions,{})}render(e){const t=this.md.parse(e,{}),r=this.embeddingExtractor.extract(t);return this.embeddingExtractor.removeTailEmbeddings(t),{embeddings:r,rawText:e,renderedText:this._render(t)}}_renderInline(e){return this.inlineRenderer.render(e,this.mdOptions,{})}renderInline(e){const t=this.md.parse(e,{}),r=this.embeddingExtractor.extract(t);return this.embeddingExtractor.removeTailEmbeddings(t),this.embeddingExtractor.replace(t),{embeddings:r,rawText:e,renderedText:this._renderInline(t)}}},exports.useContainer=(e,t=W)=>{t.forEach(t=>{e.use(d,t)})}; | ||
//# sourceMappingURL=traq-markdown-it.cjs.production.min.js.map |
@@ -713,2 +713,9 @@ import MarkdownIt from 'markdown-it'; | ||
}; | ||
this.katexOptions = { | ||
katex: katexE, | ||
output: 'html', | ||
strict: errCode => errCode === 'unicodeTextInMathMode' ? 'ignore' : 'warn', | ||
maxSize: 100, | ||
blockClass: 'is-scroll' | ||
}; | ||
this.md = new MarkdownIt(this.mdOptions); | ||
@@ -722,9 +729,3 @@ this.inlineRenderer = new InlineRenderer(); | ||
setPlugin(store, whitelist) { | ||
this.md.use(MarkdownItMark).use(spoiler, true).use(messageExtendsPlugin, store).use(stampPlugin, store).use(katex, { | ||
katex: katexE, | ||
output: 'html', | ||
strict: errCode => errCode === 'unicodeTextInMathMode' ? 'ignore' : 'warn', | ||
maxSize: 100, | ||
blockClass: 'is-scroll' | ||
}).use(mila, { | ||
this.md.use(MarkdownItMark).use(spoiler, true).use(messageExtendsPlugin, store).use(stampPlugin, store).use(katex, this.katexOptions).use(mila, { | ||
attrs: { | ||
@@ -737,4 +738,17 @@ target: '_blank', | ||
})); | ||
const dummyMd = new MarkdownIt(this.mdOptions); | ||
dummyMd.use(katex, { ...this.katexOptions, | ||
maxSize: 1, | ||
macros: { | ||
// 文字サイズを変更する関数を無効化する | ||
'\\Huge': () => '', | ||
'\\huge': () => '', | ||
'\\LARGE': () => '', | ||
'\\Large': () => '', | ||
'\\large': () => '' | ||
} | ||
}); | ||
this.inlineRenderer.setRules(this.md.renderer.rules, { | ||
math_block: this.md.renderer.rules.math_inline | ||
math_inline: dummyMd.renderer.rules.math_inline, | ||
math_block: dummyMd.renderer.rules.math_inline | ||
}); | ||
@@ -741,0 +755,0 @@ } |
import MarkdownIt from 'markdown-it'; | ||
import katexE from 'katex'; | ||
import type Token from 'markdown-it/lib/token'; | ||
@@ -17,2 +18,9 @@ import type { Store } from './Store'; | ||
}; | ||
readonly katexOptions: { | ||
readonly katex: typeof katexE; | ||
readonly output: "html"; | ||
readonly strict: (errCode: string) => string; | ||
readonly maxSize: 100; | ||
readonly blockClass: "is-scroll"; | ||
}; | ||
readonly md: MarkdownIt; | ||
@@ -19,0 +27,0 @@ readonly embeddingExtractor: EmbeddingExtractor; |
{ | ||
"name": "@traptitech/traq-markdown-it", | ||
"version": "5.3.1", | ||
"version": "5.3.2", | ||
"description": "Markdown parser for traQ.", | ||
@@ -37,3 +37,3 @@ "main": "dist/index.js", | ||
"core-js": "^3.12.0", | ||
"highlight.js": "^10.7.2", | ||
"highlight.js": "^11.0.0", | ||
"katex": "^0.13.9", | ||
@@ -40,0 +40,0 @@ "markdown-it": "^12.0.6", |
@@ -31,2 +31,10 @@ import /* tree-shaking no-side-effects-when-called */ MarkdownIt from 'markdown-it' | ||
} as const | ||
readonly katexOptions = { | ||
katex: katexE, | ||
output: 'html', | ||
strict: (errCode: string): string => | ||
errCode === 'unicodeTextInMathMode' ? 'ignore' : 'warn', | ||
maxSize: 100, | ||
blockClass: 'is-scroll' | ||
} as const | ||
readonly md = new MarkdownIt(this.mdOptions) | ||
@@ -52,10 +60,3 @@ readonly embeddingExtractor: EmbeddingExtractor | ||
.use(stamp, store) | ||
.use(katex, { | ||
katex: katexE, | ||
output: 'html', | ||
strict: (errCode: string) => | ||
errCode === 'unicodeTextInMathMode' ? 'ignore' : 'warn', | ||
maxSize: 100, | ||
blockClass: 'is-scroll' | ||
}) | ||
.use(katex, this.katexOptions) | ||
.use(mila, { | ||
@@ -69,4 +70,19 @@ attrs: { | ||
const dummyMd = new MarkdownIt(this.mdOptions) | ||
dummyMd.use(katex, { | ||
...this.katexOptions, | ||
maxSize: 1, | ||
macros: { | ||
// 文字サイズを変更する関数を無効化する | ||
'\\Huge': () => '', | ||
'\\huge': () => '', | ||
'\\LARGE': () => '', | ||
'\\Large': () => '', | ||
'\\large': () => '' | ||
} | ||
}) | ||
this.inlineRenderer.setRules(this.md.renderer.rules, { | ||
math_block: this.md.renderer.rules.math_inline | ||
math_inline: dummyMd.renderer.rules.math_inline, | ||
math_block: dummyMd.renderer.rules.math_inline | ||
}) | ||
@@ -73,0 +89,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315057
3587
+ Addedhighlight.js@11.10.0(transitive)
- Removedhighlight.js@10.7.3(transitive)
Updatedhighlight.js@^11.0.0