import{M as C,b}from"./MarkdownRenderer.vue_vue_type_style_index_0_lang-207dad4c.js";import{i as T,_ as O,o as w,c as M,h as _,f as B,t as R,a as H,d as $}from"./index-e263e3d6.js";function I(e){return encodeURIComponent(String(e).trim().toLowerCase().replace(/\s+/g,"-"))}function p(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">")}function j(e,t){var n;t=Object.assign({},{placeholder:"(\\$\\{toc\\}|\\[\\[?_?toc_?\\]?\\]|\\$\\<toc(\\{[^}]*\\})\\>)",slugify:I,uniqueSlugStartIndex:1,containerClass:"table-of-contents",containerId:void 0,listClass:void 0,itemClass:void 0,linkClass:void 0,level:1,listType:"ol",format:void 0,callback:void 0},t);var i=new RegExp("^"+t.placeholder+"$","i");e.renderer.rules.tocOpen=function(r,s){var a=Object.assign({},t);return r&&s>=0&&(a=Object.assign(a,r[s].inlineOptions)),"<nav"+(a.containerId?' id="'+p(a.containerId)+'"':"")+' class="'+p(a.containerClass)+'">'},e.renderer.rules.tocClose=function(){return"</nav>"},e.renderer.rules.tocBody=function(r,s){var a=Object.assign({},t);r&&s>=0&&(a=Object.assign(a,r[s].inlineOptions));var o,l={},m=Array.isArray(a.level)?(o=a.level,function(d){return o.includes(d)}):function(d){return function(c){return c>=d}}(a.level);return function d(c){var u=a.listClass?' class="'+p(a.listClass)+'"':"",f=a.itemClass?' class="'+p(a.itemClass)+'"':"",k=a.linkClass?' class="'+p(a.linkClass)+'"':"";if(c.c.length===0)return"";var v="";return(c.l===0||m(c.l))&&(v+="<"+(p(a.listType)+u)+">"),c.c.forEach(function(g){m(g.l)?v+="<li"+f+"><a"+k+' href="#'+function(S){for(var y=S,x=a.uniqueSlugStartIndex;Object.prototype.hasOwnProperty.call(l,y);)y=S+"-"+x++;return l[y]=!0,y}(t.slugify(g.n))+'">'+(typeof a.format=="function"?a.format(g.n,p):p(g.n))+"</a>"+d(g)+"</li>":v+=d(g)}),(c.l===0||m(c.l))&&(v+="</"+p(a.listType)+">"),v}(n)},e.core.ruler.push("generateTocAst",function(r){n=function(s){for(var a={l:0,n:"",c:[]},o=[a],l=0,m=s.length;l<m;l++){var d=s[l];if(d.type==="heading_open"){var c=s[l+1].children.filter(function(f){return f.type==="text"||f.type==="code_inline"}).reduce(function(f,k){return f+k.content},""),u={l:parseInt(d.tag.substr(1),10),n:c,c:[]};if(u.l>o[0].l)o[0].c.push(u),o.unshift(u);else if(u.l===o[0].l)o[1].c.push(u),o[0]=u;else{for(;u.l<=o[0].l;)o.shift();o[0].c.push(u),o.unshift(u)}}}return a}(r.tokens),typeof t.callback=="function"&&t.callback(e.renderer.rules.tocOpen()+e.renderer.rules.tocBody()+e.renderer.rules.tocClose(),n)}),e.block.ruler.before("heading","toc",function(r,s,a,o){var l,m=r.src.slice(r.bMarks[s]+r.tShift[s],r.eMarks[s]).split(" ")[0];if(!i.test(m))return!1;if(o)return!0;var d=i.exec(m),c={};if(d!==null&&d.length===3)try{c=JSON.parse(d[2])}catch{}return r.line=s+1,(l=r.push("tocOpen","nav",1)).markup="",l.map=[s,r.line],l.inlineOptions=c,(l=r.push("tocBody","",0)).markup="",l.map=[s,r.line],l.inlineOptions=c,l.children=[],(l=r.push("tocClose","nav",-1)).markup="",!0},{alt:["paragraph","reference","blockquote"]})}const h={createMarkdownRenderer(e={}){try{const n={...{html:!0,linkify:!0,typographer:!0,breaks:!0,maxNesting:100},...e},i=new C(n);try{i.use(b,{permalink:b.permalink.linkInsideHeader({symbol:"",renderAttrs:()=>({"aria-hidden":"true"})})})}catch(r){console.error("配置锚点插件失败:",r)}try{i.use(j,{listType:"ul",level:[1,2,3],containerClass:"markdown-toc"})}catch(r){console.error("配置目录插件失败:",r)}return i}catch(t){throw console.error("创建Markdown渲染器失败:",t),t}},parseFrontMatter(e){try{return!e||typeof e!="string"?{data:{},content:e||""}:T(e)}catch(t){return console.error("解析前置元数据失败:",t),{data:{},content:e}}},processSpecialTags(e){try{if(!e||typeof e!="string")return"";console.log("[MarkdownService] 开始处理特殊标记");const t=/亲爱的公平正义的追寻者[\s\S]*?公民权利同盟(ACR)敬邀 2025年春/g;return e.match(t)&&console.log("[MarkdownService] 找到特定邀请函文本"),e=e.replace(t,n=>(console.log("[MarkdownService] 正在应用手写样式到特定邀请函"),`<div class="handwritten invitation-letter">${n.replace(/\n/g,"<br>")}</div>`)),e.match(/---(handwritten|手写)---/)&&console.log("[MarkdownService] 找到手写体标记"),e=e.replace(/---(handwritten|手写)---\s*([\s\S]*?)---/g,(n,i,r)=>(console.log("[MarkdownService] 应用手写样式:",r.substring(0,20)+"..."),`<div class="handwritten">${r.replace(/\n/g,"<br>")}</div>`)),e=e.replace(/:::invitation\s+([\s\S]*?):::/g,(n,i)=>`<div class="invitation">${i}</div>`),e=e.replace(/---(header|标题)---\s*([\s\S]*?)---/g,(n,i,r)=>`<div class="invitation-header">${r}</div>`),e=e.replace(/---(body|正文)---\s*([\s\S]*?)---/g,(n,i,r)=>{const s=r.trim().split(`
`);if(s.length>0){const a=s.shift(),o=s.join(`
`);return`<div class="invitation-body"><span class="invitation-greeting">${a}</span>${o}</div>`}return`<div class="invitation-body">${r}</div>`}),e=e.replace(/---(signature|签名)---\s*([\s\S]*?)---/g,(n,i,r)=>`<div class="invitation-signature">${r}</div>`),console.log("[MarkdownService] 特殊标记处理完成"),e}catch(t){return console.error("处理特殊标记失败:",t),e}},fixHeaderFormat(e){try{return!e||typeof e!="string"?e:e.replace(/^# +/gm,"# ").replace(/^## +/gm,"## ").replace(/^### +/gm,"### ").replace(/^# # /gm,"## ").replace(/^# # # /gm,"### ").replace(/^# {2,}/gm,"## ").trim()}catch(t){return console.error("修复标题格式失败:",t),e}},fixRenderedHtmlHeaders(e){try{return!e||typeof e!="string"?e:e.replace(/<h([1-6])>\s*#+\s*/g,"<h$1>").replace(/<h([1-6])>(.*?)#\s+/g,"<h$1>$2").replace(/<h([1-6])>(.*?)#\s+#\s+/g,"<h$1>$2")}catch(t){return console.error("修复渲染后HTML标题失败:",t),e}},generateErrorHtml(e="内容渲染错误",t="/",n="返回首页"){return`<div class="error-message">
<h3>${e}</h3>
<p>抱歉,无法渲染请求的内容。</p>
<a href="${t}" class="back-button">
${n}
</a>
</div>`},getBackLinkByPathname(e){try{const t={link:"/",text:"返回首页"};return e?e.includes("/citizens-voice")||e.includes("/news")?{link:"/citizens-voice",text:"返回公民之声"}:e.includes("/cases")?{link:"/cases",text:"返回案件列表"}:t:t}catch(t){return console.error("获取返回链接失败:",t),{link:"/",text:"返回首页"}}},extractTocFromHtml(e){try{const t={tocHtml:"",contentHtml:e};if(!e)return t;const n=/<ul class="markdown-toc">([\s\S]*?)<\/ul>/,i=e.match(n);return i&&i[0]&&(t.tocHtml=i[0],t.contentHtml=e.replace(i[0],"")),t}catch(t){return console.error("提取目录失败:",t),{tocHtml:"",contentHtml:e}}}},L={name:"MarkdownRenderer",props:{content:{type:String,required:!0},showToc:{type:Boolean,default:!1},fixedToc:{type:Boolean,default:!0},tocTitle:{type:String,default:""},showMetadata:{type:Boolean,default:!1}},data(){return{htmlContent:"",tocHtml:"",metadata:null}},watch:{content:{immediate:!0,handler(e){this.renderMarkdown(e)}}},methods:{async renderMarkdown(e){if(!e){this.htmlContent="",this.tocHtml="",this.metadata=null;return}try{if(e=String(e),!this.showMetadata&&e.trim().startsWith("---")){const a=e.indexOf("---",3);a>0&&(e=e.substring(a+3).trim())}const t=h.parseFrontMatter(e);this.metadata=t.data;let n=h.processSpecialTags(t.content);(!n||n.trim()==="")&&(n="内容为空,请检查源文件。"),n=h.fixHeaderFormat(n);const i=h.createMarkdownRenderer(),r=this.showToc?`${n}
[[toc]]`:n;let s;try{s=i.render(r)}catch(a){console.error("Markdown渲染错误:",a),s=`<p>${n}</p>`}if(this.showToc){const{tocHtml:a,contentHtml:o}=h.extractTocFromHtml(s);this.tocHtml=a,s=o}s=h.fixRenderedHtmlHeaders(s),this.showMetadata&&Object.keys(this.metadata).length>0&&(s=this.generateMetadataHtml(this.metadata)+s),this.htmlContent=s}catch(t){console.error("Markdown渲染错误:",t);try{const n=window.location.pathname,{link:i,text:r}=h.getBackLinkByPathname(n);this.htmlContent=h.generateErrorHtml("内容渲染错误",i,r)}catch{this.htmlContent=h.generateErrorHtml()}this.tocHtml=""}},generateMetadataHtml(e){let t='<div class="metadata-container">';if(e.title&&(t+=`<h1 class="metadata-title">${e.title}</h1>`),t+='<div class="metadata-info">',e.date){const i=new Date(e.date).toLocaleDateString("zh-CN",{year:"numeric",month:"long",day:"numeric"});t+=`<div class="metadata-item"><span>发布日期:</span>${i}</div>`}if(e.author&&(t+=`<div class="metadata-item"><span>作者:</span>${e.author}</div>`),e.category&&(t+=`<div class="metadata-item"><span>分类:</span>${e.category}</div>`),e.tags&&Array.isArray(e.tags)&&e.tags.length>0){const n=e.tags.map(i=>`<span class="metadata-tag">${i}</span>`).join(" ");t+=`<div class="metadata-item"><span>标签:</span>${n}</div>`}return e.summary&&(t+=`<div class="metadata-summary">${e.summary}</div>`),t+="</div></div>",t}}},E={class:"markdown-container"},A={key:0,class:"toc-title"},F=["innerHTML"],N=["innerHTML"];function q(e,t,n,i,r,s){return w(),M("div",E,[n.showToc?(w(),M("div",{key:0,class:_(["toc-container",{"fixed-toc":n.fixedToc}])},[n.tocTitle?(w(),M("div",A,[B(R(n.tocTitle)+" ",1),t[0]||(t[0]=H("div",{class:"title-underline"},null,-1))])):$("",!0),H("div",{class:"toc-content",innerHTML:r.tocHtml},null,8,F)],2)):$("",!0),H("div",{class:"markdown-content markdown-body",innerHTML:r.htmlContent},null,8,N)])}const z=O(L,[["render",q]]);export{z as M};