微信小程序中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 效果


相关推荐
precious。。。21 小时前
1.2.1 三角不等式演示
前端·javascript·html
星空1 天前
前段--A_2--HTML属性标签
前端·html
a1117761 天前
MapDesigner (html开源项目)六角格地图设计工具
开源·html
清风絮柳1 天前
65.少儿英语微信小程序
vue.js·spring boot·微信小程序·小程序·毕业设计
夜雨飘零11 天前
零门槛!用 AI 生成 HTML 并一键部署到云端桌面
人工智能·python·html
PieroPc1 天前
一个为 AI 助手设计的进销存管理系统,内置完整的 CLI 命令接口,让 AI 可以通过自然语言或命令行直接操作库存。技术栈 FastAPI+Html
人工智能·html·fastapi·cli
星空1 天前
前端--A_3--HTML区块_块元素与行内元素
前端·html
a1117761 天前
PreTeXt 开源推荐(应用demo)
前端·开源·html
tjsoft1 天前
unigui开发微信小程序
微信小程序·小程序
reasonsummer1 天前
【白板类-03-01】20260402画板01(html+希沃白板)
前端·html