微信小程序中Towxml解析Markdown及html

一、Towxml

Towxml 是一个让小程序可以解析Markdown、HTML的解析库。

二、引入

2.1 clone代码

bash 复制代码
git clone https://github.com/sbfkcel/towxml.git

2.2 安装依赖

bash 复制代码
npm install

2.3 打包

bash 复制代码
npm run build

2.4 引入文件

将dist文件复制到微信小程序根目录,改名为towxml

三、使用

3.1 app.js引入

js 复制代码
//app.js
App({
    // 引入`towxml`解析方法
    towxml:require('/towxml/index')
})

3.2 页面配置文件json中引用

json 复制代码
{
  "usingComponents": {
    "towxml": "../towxml/towxml"
  }
}

3.3 页面js使用

js 复制代码
const app = getApp();
Page({
    data: {
        content: ''
    },
    onLoad: function (options) {
        // todo 库中返回markdown
        const contentMd = '# 一级标题';
        let result = app.towxml(contentMd, 'markdown', {
        	theme: 'light'
        });
        this.setData({
            content: result
        });
    }
})

3.4 wxml展示

xml 复制代码
<towxml nodes="{{content}}"/>

3.5 效果


相关推荐
cyforkk41 分钟前
Spring Boot 3 集成 Swagger 踩坑实录:解决 doc.html 404 与 Unauthorized 拦截
spring boot·后端·html
ZHOUPUYU1 小时前
PHP与WebSocket实时通信的原理到生产级应用
开发语言·html·php
uimaker1 小时前
uimaker响应式jQuery Easyui+Bootstrap多配色主题设计
前端框架·bootstrap·html·jquery·easyui·后台模版
焦糖玛奇朵婷3 小时前
盲盒小程序开发|解锁开箱新体验[特殊字符]
大数据·开发语言·程序人生·小程序·软件需求
左师佑图3 小时前
微信小程序组件事件冒泡问题排查与解决方案
微信小程序·小程序
Predestination王瀞潞3 小时前
6.5.2 软件->W3C HTML5、CSS3标准(W3C Recommendation):HTML(HyperText Markup Language)
html·css3·html5
树下水月4 小时前
微信小程序接口,必须使用https的443端口吗?
微信小程序·小程序·https
#麻辣小龙虾#4 小时前
html浏览器自动播放视频策略
前端·html·音视频
毕设源码-邱学长4 小时前
【开题答辩全过程】以 灵山水牛奶配送小程序的设计与实现为例,包含答辩的问题和答案
小程序
这儿有一堆花5 小时前
从技术标准到营销概念:深度解析 HTML5 与 H5 的演变与区别
前端·html·html5