| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- const towxml = require('./index.js');
- Component({
- options:{
- styleIsolation:'shared'
- },
- properties:{
- nodes:{
- type:Object,
- value:{}
- },
- markdown:{
- type:String,
- value:''
- },
- theme:{
- type:String,
- value:'light'
- }
- },
- observers:{
- 'markdown': function(markdown){
- if(markdown && typeof markdown === 'string'){
- try{
- const nodes = towxml(markdown, 'markdown', {
- theme: this.data.theme || 'light',
- base: ''
- });
- this.setData({
- nodes: nodes
- });
- }catch(error){
- console.error('Markdown 转换失败:', error);
- }
- }
- }
- },
- data:{
- nodes:{}
- },
- lifetimes:{
- attached(){
- // 如果传入了 markdown 文本,进行转换
- if(this.properties.markdown){
- try{
- const nodes = towxml(this.properties.markdown, 'markdown', {
- theme: this.properties.theme || 'light',
- base: ''
- });
- this.setData({
- nodes: nodes
- });
- }catch(error){
- console.error('Markdown 转换失败:', error);
- }
- }
- }
- }
- })
|