if (!global.towxml) global.towxml = require('../../towxml/index'); import {navigateToUrl} from "../../../js/utils"; Component({ externalClasses: ['my-class',"class"], properties: { nodes:{ type:String, observer:function(nodes){ this.process(); } }, datakey:{ type:String, observer:function(key){ wx.getStorage({ key, success: res=>{ this.setData({_nodes:res.data}); wx.setStorage({ data: {}, key, }) }, }); return key; } }, theme:{ type:String, value:"light", observer:function(theme,old){ let {type} = this.data; if(this.ready&&theme!=old&&(type=='html'||type=='markdown')) this.process(); } }, base:{ type:String, value: "https://www.educoder.net/" }, type:{ type:String, value: "" } }, data: { }, methods: { handleTap(e){ console.log("onTap", e); var {target:{dataset:{data}},currentTarget:{dataset:{data:_data}}} = e; let {tag, attr} = _data; if(tag=='navigator'&&attr.href){ if(!navigateToUrl({url: attr.href})) wx.setClipboardData({ data: attr.href,success:res=>{ wx.showToast({ title: '链接已复制' }) } }); } //this.triggerEvent('click',{},{bubbles:true}); if(data&&data._e.tag=="code") data={attr:{class:"h2w__pre"},child:[data],tag:"view",type:"tag",_e:{type:"tag",attr:{},tag:"pre", child:[data]}} if(data&&data._e.tag=='pre'){ data = {theme:'light',child:[data],_e:{child:[data]}}; var key = "RICH_MD_STORAGE" wx.setStorage({ key,data,success:res=>{ wx.navigateTo({ url: `/markdown/components/rich-md/rich-md?datakey=${key}&type=html` }) } }) } }, /** * difficult: * 例如,`3.9E3`代表`3.9×$$10^{3}$$`,等同于`3900` * `$$S$$`为每`lbs/$$in^{2}$$`上的压力 * 每月还贷公式为`$$\\frac{Pr'(1+r')^{N'}}{(1+r')^{N'}-1}$$`,其中`r'`为月利息。(提示:`$$r'=\\frac{r}{1200}$$`,`N'=N*12`)。 * 该程序接收用户的`4`个输入$$x_1$$,$$y_1$$,$$x_2$$,$$y_2$$(分别表示地球上两个点的维度和经度,单位是度) * 计算公式为:$$r^{3}=\\frac{dp}{\\pi S}$$,其中 */ process(){ let {type, nodes} = this.data; ; if(!type){ if (nodes.match(/^\s*<.+>.*<\/.+>/s)) type = "rich-text"; else if(nodes.match(/##+|\*.+\*|- |`|\$|\[.*\]\(.+\)|\|.+\|/)) type = "markdown"; else if(nodes.match(/<.+>.*<\/.+>| /s)) type= "rich-text"; else type = "plain"; } if(type=="markdown"||type=="html"){ nodes = nodes.replace(/(#+)/g, "$1 ").replace(/`\$\$\s*([^\$`]*?)\s*\$\$`/g, "$$$1$$").replace(/\$\$\s*([^\$`]*?)\s*\$\$/g, "$$$1$$").replace(/```latex\n(.*?)\n```/g,"$$$$\n$1\n$$$$"); // ; var _nodes = global.towxml(nodes, type, { theme:this.data.theme,base: this.data.base,events:{ tap:e=>{ this.handleTap(e); } } }); ; this.setData({_nodes, type}); }else{ this.setData({nodes, type}) } this.ready = true; } } })