Convert Figma logo to code with AI

icindy logowxParse

wxParse-微信小程序富文本解析自定义组件,支持HTML及markdown解析

7,747
1,817
7,747
219

Top Related Projects

1,283

微信小程序Markdown渲染库

2,499

微信小程序HTML、Markdown渲染库

13,048

Web Components Framework - Web组件框架

3,264

小程序富文本组件,支持渲染和编辑 html,支持在微信、QQ、百度、支付宝、头条和 uni-app 平台使用

Quick Overview

wxParse is a WeChat Mini Program component for rendering rich text content, including HTML and Markdown. It provides a solution for displaying complex formatted text within WeChat Mini Programs, which natively lack support for rich text rendering.

Pros

  • Supports both HTML and Markdown parsing
  • Easy integration into WeChat Mini Program projects
  • Customizable styling options for rendered content
  • Active community and ongoing maintenance

Cons

  • Performance may degrade with large amounts of complex content
  • Limited support for advanced HTML features
  • Occasional rendering inconsistencies across different devices
  • Requires additional setup compared to native text display

Code Examples

  1. Basic HTML parsing:
<template>
  <view>
    <wxparse data="{{htmlContent}}" />
  </view>
</template>

<script>
Page({
  data: {
    htmlContent: '<h1>Hello, World!</h1><p>This is a <strong>bold</strong> text.</p>'
  }
})
</script>
  1. Markdown parsing:
<template>
  <view>
    <wxparse data="{{markdownContent}}" type="md" />
  </view>
</template>

<script>
Page({
  data: {
    markdownContent: '# Hello, World!\n\nThis is a **bold** text.'
  }
})
</script>
  1. Customizing styles:
<template>
  <view>
    <wxparse data="{{htmlContent}}" tag-style="{{tagStyle}}" />
  </view>
</template>

<script>
Page({
  data: {
    htmlContent: '<h1>Styled Heading</h1><p>Colored paragraph.</p>',
    tagStyle: {
      h1: 'color: #ff0000;',
      p: 'color: #00ff00;'
    }
  }
})
</script>

Getting Started

  1. Install wxParse in your WeChat Mini Program project:

    npm install wxparse
    
  2. Import and register the component in your page:

    import wxParse from 'wxparse';
    
    Component({
      components: {
        wxparse: wxParse
      }
    })
    
  3. Use the component in your WXML:

    <wxparse data="{{content}}" />
    
  4. Set the content in your page's data:

    Page({
      data: {
        content: '<h1>Hello, wxParse!</h1>'
      }
    })
    

Competitor Comparisons

1,283

微信小程序Markdown渲染库

Pros of wemark

  • Lighter weight and more focused on Markdown parsing
  • Actively maintained with more recent updates
  • Better performance for rendering large documents

Cons of wemark

  • Less feature-rich compared to wxParse
  • Limited support for complex HTML structures
  • Fewer customization options for styling

Code Comparison

wxParse:

var wxParse = require('../../wxParse/wxParse.js');
Page({
  onLoad: function () {
    var article = '<div>Hello World</div>';
    wxParse.wxParse('article', 'html', article, this, 5);
  }
})

wemark:

var wemark = require('wemark');
Page({
  onLoad: function () {
    wemark.parse('# Hello World', this, {
      imageWidth: wx.getSystemInfoSync().windowWidth - 40,
      name: 'wemark'
    });
  }
})

Both wxParse and wemark are libraries for rendering rich text in WeChat Mini Programs. wxParse offers more comprehensive HTML parsing capabilities, while wemark focuses specifically on Markdown rendering. wxParse provides more flexibility for complex content but may be overkill for simpler use cases. wemark, on the other hand, is more lightweight and optimized for Markdown, making it a good choice for projects primarily dealing with Markdown content.

2,499

微信小程序HTML、Markdown渲染库

Pros of towxml

  • More actively maintained with recent updates
  • Supports both Markdown and HTML parsing
  • Offers a more comprehensive set of features, including LaTeX rendering

Cons of towxml

  • Larger file size and potentially higher resource usage
  • Steeper learning curve due to more complex configuration options

Code Comparison

wxParse:

var WxParse = require('../../wxParse/wxParse.js');
Page({
  onLoad: function () {
    var article = '<div>Hello World</div>';
    WxParse.wxParse('article', 'html', article, this, 5);
  }
})

towxml:

const Towxml = require('/towxml/index');
Page({
  onLoad: function () {
    let article = '# Hello World';
    let result = new Towxml().toJson(article, 'markdown');
    this.setData({ article: result });
  }
})

Both libraries aim to parse and render rich text content in WeChat Mini Programs. wxParse focuses primarily on HTML parsing, while towxml offers more versatility with support for both Markdown and HTML. towxml provides additional features like LaTeX rendering, making it more suitable for complex content. However, this comes at the cost of a larger file size and potentially more complex setup. wxParse, being simpler, may be easier to implement for basic use cases but lacks some advanced features found in towxml.

13,048

Web Components Framework - Web组件框架

Pros of omi

  • More comprehensive framework for building user interfaces
  • Supports multiple platforms beyond WeChat Mini Programs
  • Active development and larger community support

Cons of omi

  • Steeper learning curve due to its broader scope
  • May be overkill for simple parsing tasks
  • Requires more setup and configuration

Code Comparison

wxParse:

var wxParse = require('wxParse/wxParse.js');
Page({
  onLoad: function() {
    var article = '<div>Hello, wxParse!</div>';
    wxParse.wxParse('article', 'html', article, this, 5);
  }
});

omi:

import { define, WeElement, render } from 'omi';

define('my-component', class extends WeElement {
  render() {
    return <div>Hello, omi!</div>
  }
});

render(<my-component />, 'body');

Summary

wxParse is a lightweight solution specifically designed for parsing rich text in WeChat Mini Programs. It's easy to use and integrate but has limited functionality beyond parsing.

omi is a more robust framework for building user interfaces across multiple platforms. It offers greater flexibility and features but requires more setup and learning. Choose based on your project's complexity and requirements.

3,264

小程序富文本组件,支持渲染和编辑 html,支持在微信、QQ、百度、支付宝、头条和 uni-app 平台使用

Pros of mp-html

  • More actively maintained with frequent updates
  • Supports a wider range of HTML tags and attributes
  • Better performance, especially for complex HTML structures

Cons of mp-html

  • Slightly larger package size
  • May require more configuration for advanced use cases

Code Comparison

wxParse:

<import src="../../wxParse/wxParse.wxml"/>
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

mp-html:

<mp-html content="{{html}}" />

Key Differences

  1. Implementation: mp-html uses a more modern, component-based approach, while wxParse relies on older template-based rendering.
  2. Flexibility: mp-html offers more customization options and supports a broader range of HTML elements.
  3. Maintenance: mp-html is actively maintained and updated, whereas wxParse has been relatively stagnant.
  4. Performance: mp-html generally offers better performance, especially for complex HTML structures.
  5. Learning Curve: wxParse may be simpler to implement initially, but mp-html provides more powerful features for advanced users.

Both libraries serve the purpose of rendering HTML in WeChat Mini Programs, but mp-html offers more features and better long-term support. The choice between them depends on project requirements and complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

抱歉各位,本项目已经停止维护,为了不给您使用造成问题,请仅做参考使用,感谢各位支持

wxParse-微信小程序富文本解析组件

支持Html及markdown转wxml可视化

版本号:0.3

来源: [微信小程序开发论坛-weappdev](https://weappdev.com)

作用: 将Html/Markdown转换为微信小程序的可视化方案

特性

支持特性实验功能ToDo
- [x] HTML的大部分标签解析[x] 小表情emjio[x] table标签
- [x] 内联style[x] a标签跳转
- [x] 标签Class[x] 动态添加
- [x] 图片自适应规则
- [x] 图片多图片预览
- [x] 模版层级可扩展性
- [x] 多数据循环方式
- [x] 内联style

相关截图

相关截图

感谢

@stonewen| @Daissmentii | @wuyanwen | @vcxiaohan |

基本使用方法

    1. Copy文件夹wxParse
- wxParse/
  -wxParse.js(必须存在)
  -html2json.js(必须存在)
  -htmlparser.js(必须存在)
  -showdown.js(必须存在)
  -wxDiscode.js(必须存在)
  -wxParse.wxml(必须存在)
  -wxParse.wxss(必须存在)
  -emojis(可选)
    1. 引入必要文件
//在使用的View中引入WxParse模块
var WxParse = require('../../wxParse/wxParse.js');
//在使用的Wxss中引入WxParse.css,可以在app.wxss
@import "/wxParse/wxParse.wxss";
    1. 数据绑定
var article = '<div>我是HTML代码</div>';
/**
* WxParse.wxParse(bindName , type, data, target,imagePadding)
* 1.bindName绑定的数据名(必填)
* 2.type可以为html或者md(必填)
* 3.data为传入的具体数据(必填)
* 4.target为Page对象,一般为this(必填)
* 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
*/
var that = this;
WxParse.wxParse('article', 'html', article, that, 5);
    1. 模版引用
// 引入模板
<import src="你的路径/wxParse/wxParse.wxml"/>
//这里data中article为bindName
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

高级用法

  • 配置小表情emojis
/**
* WxParse.emojisInit(reg,baseSrc,emojis)
* 1.reg,如格式为[00]=>赋值 reg='[]'
* 2.baseSrc,为存储emojis的图片文件夹
* 3.emojis,定义表情键值对
*/
WxParse.emojisInit('[]', "/wxParse/emojis/", {
      "00": "00.gif",
      "01": "01.gif",
      "02": "02.gif",
      "03": "03.gif",
      "04": "04.gif",
      "05": "05.gif",
      "06": "06.gif",
      "07": "07.gif",
      "08": "08.gif",
      "09": "09.gif",
      "09": "09.gif",
      "10": "10.gif",
      "11": "11.gif",
      "12": "12.gif",
      "13": "13.gif",
      "14": "14.gif",
      "15": "15.gif",
      "16": "16.gif",
      "17": "17.gif",
      "18": "18.gif",
      "19": "19.gif",
    });
  • 多数据格式

FAQ

二次开发

  • 基础数据格式
parsedata:{
    view:{},//样式存储
    nodes:{},//展示需要的存储节点
    images:[],//存放图片对象数组
    imageUrls:[],//存放图片url数组
}

相关文章

捐献

来源

微信小程序开发论坛 垂直微信小程序开发交流社区

可在网站扫描二维码进入我们的微信小程序群,也可以微信搜索"weappmsg"进入"小码消息"公众号 小码消息-weappmsg 其他方式:合作qq群511389428

NPM DownloadsLast 30 Days