sbfkcel / towxml

微信小程序HTML、Markdown渲染库
https://github.com/sbfkcel/towxml/wiki
2.5k stars 315 forks source link

无法解析带斜杠\的Latex数学公式 #173

Closed Ciao-yay closed 3 years ago

Ciao-yay commented 3 years ago

如题,在测试时发现towxml无法解析带斜杠\的Latex数学公式,下面是代码:

data: {
    isLoading: true, // 判断是否尚在加载中
    article: {
      content: "这是一个测试$x = {-b\pm\sqrt{b^2-4ac}\over 2a}.$看看效果如何"
    } // 内容数据
  },
  onLoad: function() {
    let result = app.towxml(this.data.article.content, 'markdown');
    console.log(result)
    // 更新解析数据
    this.setData({
      article: result,
      isLoading: false
    });
  }
Ciao-yay commented 3 years ago

已解决,参考作者wiki里的demo,改为wx请求就ok了,以下是代码:

const app = getApp();
const api = require('../../utils/api.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: true, // 判断是否尚在加载中
    article: {} // 内容数据
  },
  onLoad: function() {
    const _ts = this;
    app.getText(api.getLatexSubject, res => {
      console.log(res.data)
      let obj = app.towxml(res.data[0].question, 'markdown', {
        // theme:'dark',
        events: {
          tap: e => {
            console.log('tap', e);
          },
          change: e => {
            console.log('todo', e);
          }
        }
      });

      _ts.setData({
        article: obj,
        isLoading: false
      });
    });

  }
})