You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
if (!global.towxml)
|
|
global.towxml = require('../../towxml/index');
|
|
|
|
Component({
|
|
externalClasses: ['my-class'],
|
|
properties: {
|
|
nodes:{
|
|
type:String,
|
|
observer:function(nodes){
|
|
this.process(nodes);
|
|
}
|
|
},
|
|
theme:{
|
|
type:String,
|
|
value:"light"
|
|
},
|
|
base:{
|
|
type:String,
|
|
value: "https://www.educoder.net/"
|
|
},
|
|
type:{
|
|
type:String,
|
|
value: ""
|
|
}
|
|
},
|
|
|
|
data: {
|
|
},
|
|
|
|
methods: {
|
|
process(nodes){
|
|
let {type} = this.data;
|
|
//console.log(type);
|
|
if(!type){
|
|
if (nodes.match(/<img .*src=.*>/))
|
|
type = "html"
|
|
else 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(/```latex\n(.*)\n```/g,"$$$$\n$1\n$$$$");
|
|
//console.log(nodes);
|
|
var _nodes = global.towxml(nodes, type, { theme:this.data.theme,base: this.data.base });
|
|
this.setData({_nodes, type});
|
|
}else{
|
|
this.setData({nodes, type})
|
|
}
|
|
}
|
|
}
|
|
})
|