All Projects → csonchen → Wxparse

csonchen / Wxparse

Licence: mit
微信小程序富文本解析

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Wxparse

Autocser
AutoCSer is a high-performance RPC framework. AutoCSer 是一个以高效率为目标向导的整体开发框架。主要包括 TCP 接口服务框架、TCP 函数服务框架、远程表达式链组件、前后端一体 WEB 视图框架、ORM 内存索引缓存框架、日志流内存数据库缓存组件、消息队列组件、二进制 / JSON / XML 数据序列化 等一系列无缝集成的高性能组件。
Stars: ✭ 140 (+3.7%)
Mutual labels:  html-parser, webview
RichEditorView
Android 基于WebView的富文本编辑器 - 仿简书编辑器
Stars: ✭ 77 (-42.96%)
Mutual labels:  webview, rich-text
html2any
🌀 parse and convert html string to anything
Stars: ✭ 43 (-68.15%)
Mutual labels:  html-parser, rich-text
Jupytergraffiti
Create interactive screencasts inside Jupyter Notebook that anybody can play back
Stars: ✭ 114 (-15.56%)
Mutual labels:  highlight
Pull To Refresh
ESPullToRefresh is developed and maintained by Vincent Li. If you have any questions or issues in using ESPullToRefresh, welcome to issue. If you want to contribute to ESPullToRefresh, Please submit Pull Request, I will deal with it as soon as possible.
Stars: ✭ 1,591 (+1078.52%)
Mutual labels:  webview
Mybrowser
我的浏览器,基于WKWebView实现的一个iOS浏览器,实现了无图模式、广告拦截、多窗口、扫描二维码、收藏夹/历史、无痕浏览、夜间模式等功能...
Stars: ✭ 127 (-5.93%)
Mutual labels:  webview
Kanban App
Kanban board built with Rust and Elm
Stars: ✭ 1,711 (+1167.41%)
Mutual labels:  webview
Spidereye
Cross platform .Net Core applications with a webview UI
Stars: ✭ 113 (-16.3%)
Mutual labels:  webview
Recylerviewmultiheaderview
解决webView滑动冲突,支持与WebView,VideoView(miniVideo), HeaderView 嵌套使用
Stars: ✭ 132 (-2.22%)
Mutual labels:  webview
Neotags.nvim
Tag highlight in neovim
Stars: ✭ 124 (-8.15%)
Mutual labels:  highlight
Webviewtbs
Android实现微信webview兼容Android 7.0。自带库文件不使用系统的可以全方位兼容各机型,实现二次封装,发布时间2017.
Stars: ✭ 124 (-8.15%)
Mutual labels:  webview
Electron Webview
💻 A simple electron webview with cool features.
Stars: ✭ 115 (-14.81%)
Mutual labels:  webview
Cosin
Android loading view library 📊🍭
Stars: ✭ 129 (-4.44%)
Mutual labels:  highlight
Save For Offline
Android app for saving webpages for offline reading.
Stars: ✭ 114 (-15.56%)
Mutual labels:  html-parser
Xam.plugin.webview
Xamarin Plugin for a HybridWebView in PCL projects.
Stars: ✭ 132 (-2.22%)
Mutual labels:  webview
Leader Line
Draw a leader line in your web page.
Stars: ✭ 1,872 (+1286.67%)
Mutual labels:  highlight
Hexo Theme Casper
New casper theme ported to hexo.
Stars: ✭ 132 (-2.22%)
Mutual labels:  highlight
Mp Html
小程序富文本组件,支持渲染和编辑 html,支持在微信、QQ、百度、支付宝、头条和 uni-app 平台使用
Stars: ✭ 2,027 (+1401.48%)
Mutual labels:  rich-text
Wysiwyg
Development ongoing as part of Press: https://github.com/saket/press
Stars: ✭ 119 (-11.85%)
Mutual labels:  rich-text
Vue Prism Component
highlight code using prism.js and vue component
Stars: ✭ 126 (-6.67%)
Mutual labels:  highlight

wxParse —— 微信小程序富文本解析

原因

由于原作者仓库 wxParse 不再维护,我们项目中商品信息展示又是以wxParse这个用做富文本解析的;

于是乎,决定采用 递归Component 的方式对其进行重构一番;

原项目使用的 template 模板的方式渲染节点,存在以下问题:

  1. 节点渲染支持到12层,超出会原样输出 html 代码;

  2. 每一层级的循环模板都重复了一遍所有的可解析标签,代码十分臃肿。

  3. li标签不支持 ol 有序列表渲染(统一采用的是 ul 无序列表),a标签无法实现跳转,也无法获取点击事件回调等等;

  4. 节点渲染没有绑定 key 值,一是在开发工具看到一堆的 warning信息(看着十分难受),二是节点频繁删除添加,无法比较key值,造成 dom 节点频繁操作。

功能标签

目前该项目已经可以支持以下标签的渲染:

  • [x] audio标签(可自行更换组件样式,暂时采用微信公众号文章的audio音乐播放器的样式处理)
  • [x] code标签
  • [x] video标签
  • [x] table标签
  • [x] ul标签
  • [x] ol标签
  • [x] li标签
  • [x] a标签
  • [x] img标签
  • [x] video标签
  • [x] br标签
  • [x] button标签
  • [x] h1, h2, h3, h4标签
  • [x] 文本节点
  • [x] hr标签
  • [x] 其余块级标签
  • [x] 其余行级标签

使用

1. 原生组件使用方法

  • 克隆 项目 代码,把 components目录 拷贝到你的小程序根目录下面;

  • 在你的 page页面 对应的 json 文件引入 wxParse 组件

{
  "usingComponents": {
    "wxParse": "/components/wxParse/wxParse"
  }
}
  • 组件调用
<wxParse nodes="{{ htmlText }}" />

2. npm组件使用方法

  • 安装组件
npm install --save wx-minicomponent
  • 小程序开发工具的 工具 栏找到 构建npm,点击构建;

  • 在页面的 json 配置文件中添加 wxParse 自定义组件的配置

{
  "usingComponents": {
    "wxParse": "/miniprogram_npm/wx-minicomponent/wxParse"
  }
}
  • wxml 文件中引用 wxParse
<wxParse nodes="{{ htmlText }}" />

参数文档

wxParse:富文本解析组件

参数 说明 类型 例子
nodes 富文本字符 String "<div>test</div>"
language 语言 String 可选:"html" | "markdown" ("md")

标签使用说明补充:

  1. a 标签的内外链跳转根据的是 http 字符判断;

  2. a 标签的跳转顺序为:

  • 如果page页面有定义 handleTagATap 方法,优先执行该方法

  • 如果page页面没有定义 handleTagATap 方法,将根据 a标签href 字段判断采用内外链跳转方式,外链跳转需要在 app.json 文件中新增 自定义webview 页面配置,如下所示:

webview页面配置:

  1. 原生webview页面配置:
// app.json
{
  "pages" [
    "components/wxParse/webviewPage/webviewPage"
  ]
}
  1. npm 包webview配置:
// app.json
{
  "pages" [
    "miniprogram_npm/wx-minicomponent/wxParse/webviewPage/webviewPage"
  ]
}
  1. code 标签代码高亮:
  • code 标签添加 lang属性,默认值是javascript ;支持 javascript|typescript|css|xml|sql|markdown|c++|c 可选值

  • 支持高亮解析结构如下:

<pre>
<code lang="javascript">
  const name = 'csonchen'
</code>
</pre>

受信任的节点

节点 例子
audio <audio title="我是标题" desc="我是小标题" src="https://media.lycheer.net/lecture/25840237/5026279_1509614610000.mp3?0.1" />
a <a href="https://www.baidu.com"> 跳转到百度 </a> <a href="/pages/highLightPage/highLightPage"> 站内跳转 </a>
code <code lang="javascript"> const name = "csonchen"; </code>
p
div
span
li
ul
ol
img
button
hr
h1
h2
h3
h4
table
tr
th
td
....

highLight:代码高亮解析组件

参数 说明 类型 例子
codeText 原始高亮代码字符 String "var num = 10;"
language 代码语言类型 String 可选值:"javascript/typescript/css/xml/sql/markdown/c++/c"

提示:如果是html语言,language的值为xml

wxAudio:仿微信公众号文章音频播放组件

参数 说明 类型 例子
title 标题 String "test"
desc 副标题 String "sub test"
src 音频地址 String

示例展示

  1. 富文本解析
  • html文本解析实例
  • markdown文本解析实例
  1. 代码高亮(highLight组件)

更新历史

  • 2021-2-6: fix 修复单层元素(如:img标签)渲染时候获取不到组件实例唯一id,导致大图预览失败的bug

  • 2021-1-19:

  1. fix 修复 page页面wxParse组件 实例绑定唯一性的bug

  2. feat 新增 hr标签解析实现

  • 2020-12-10:fix 修复页面跳转之后图片预览大图失效的bug

  • 2020-12-8: feat 新增 code 标签的代码高亮功能,并修复解析语言注册失败的bug

  • 2020-12-7:fix 修复 code 标签解析错误以及换行符被替换成空字符的bug

  • 2020-8-17:feat 增加设置image标签的width,height属性以及内联样式属性设置

  • 2020-8-10: feat 文本节点添加选中复制功能

  • 2020-8-6:fix table,tr,td等相关元素标签去掉style样式内嵌,避免表格样式错乱问题

  • 2020-8-5: feat 新增支持a标签的内外链跳转功能,并支持page页面点击方法回调控制

  • 2020-6-18:fix 修复table渲染错位和image图片在个别情况无法预览的问题

  • 2020-5-31: reflator

  1. 迁移utils目录到wxParse目录下;

  2. 富文本增加markdown文本解析支持;

  • 2020-5-21: reflator 富文本组件image标签添加loading过渡态,优化图片加载体验

  • 2020-5-17: doc 完善组件参数文档,增加wxParse对audio标签标题,副标题的解析功能

  • 2020-5-13: feat 增加css,html,ts,sql,markdown代码高亮提示支持

  • 2020-5-6:feat 增加图片预览功能

TODO

  • [x] 图片占位图优化,优化 image标签加载,避免出现一闪而过,优化加载体验;
  • [ ] 编写插件,小程序可以通过插件方式引入;
  • [ ] 支持 template 方式渲染(因为递归组件会引入组件生命周期,节点过多可能对性能有影响);
  • [ ] 尽可能多的修复原 wxParse 项目中的 issue
  • [ ] ....
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].