Overview of Towxml
masterHTML and Markdown into WXML (WeiXin Markup Language). It is primarily used to solve the issue of rendering Markdown and HTML content directly within WeChat Mini Programs.repository·master·Indexed 25 days ago
https://github.com/sbfkcel/towxmlA rendering engine that converts HTML and Markdown into WXML (WeiXin Markup Language), enabling WeChat Mini Programs to display rich text content. Version 3.3.1 supports Echarts, LaTeX mathematical formulas, yuml flowcharts, code syntax highlighting, and multiple themes. It provides a parsing system to map standard HTML tags to WXML components and supports both pre-parsing and post-parsing data.
HTML and Markdown into WXML (WeiXin Markup Language). It is primarily used to solve the issue of rendering Markdown and HTML content directly within WeChat Mini Programs.Towxml 3.0 is the recommended version, offering a smaller footprint and faster speeds compared to 2.x. Key features include:
Do not pull the code directly for use in version 3.0. You must build the library according to your specific needs to obtain the final code.
To use Towxml 3.0, follow these steps in order:
If mathematical formulas are not rendering correctly:
http for the correct implementation pattern.When calling the parse function, you can provide an option object to control the output structure and behavior:
| Key | Type | Description |
|---|---|---|
theme | string | Sets the visual theme. Options: 'light' (default) or 'dark'. |
base | string | A base URL used to resolve relative src paths in tags like <img> or <audio>. |
events | object | An object containing event handlers. These are stored in a global _events object for components to access during runtime. |
Note: The theme value is stored in a global _theme variable during parsing.
The main entrypoint of towxml is a function that converts either Markdown or HTML strings into WXML (WeChat XML) format.
Parameters:
str (string): The source content to be parsed.type (string): The format of the source content. Supported values are 'markdown' and 'html'.option (object, optional): Configuration options for the parsing process. Defaults to an empty object {}.Returns:
Errors:
type is not 'markdown' or 'html'.The default export of parse/index.js is a function that takes an HTML string and an options object. It processes the HTML (extracting content from <body> tags if present) and converts it into a structured object suitable for WXML rendering.
Key features:
<a> becomes navigator, audio becomes audio-player).base path is provided in the options, relative src attributes in images or media are automatically resolved.theme option ('light' or 'dark').events object to map custom event handlers that components can trigger.h2w__[tagname] [original-class].