search
HomeWeChat AppletMini Program DevelopmentWeChat applet parsing H5 file method

Abstract: Netizens often ask how to let WeChat applet parse H5 files or encapsulate H5 web pages into APP? I thought this was impossible at first, because the official answer is this: Each mini program page is composed of four different suffix files with the same name in the same path, such as: index.js, index.wxm...

Netizens often ask how to let WeChat applet parse H5 files or encapsulate H5 web pages into APP? I thought this was impossible at first, because the official answer is this:

##Every The mini program page is composed of four different suffix files with the same name in the same path, such as: index.js, index.wxml, index.wxss, and index.json. Files with the .js suffix are script files, files with the .json suffix are configuration files, files with the .wxss suffix are style sheet files, and files with the .wxml suffix are page structure files.

The above meaning is already very clear. Translated:
  • .js is javascript

  • ##.wxss is equivalent to css
  • .wxml is equivalent to html

However, the syntax of wxml and wxss is defined by WeChat itself, which is different from the syntax of html and css. Since the syntax is different, the WeChat applet cannot load the H5 page. WeChat can only load pages that have been registered in the project, cannot open external links, and can only crawl data from the server##Some time ago,

due to The files written by WeChat are no longer in html format, so the html code cannot be parsed, which is really sad. When I used the online API interface to obtain data, I encountered a big pitfall, that is, the data returned by the API actually contained tags. string, I had no idea where to start. After trying regular expressions and failing, I kept looking online to see if there were any plug-ins that could parse them, and finally I found it, which is wxParse-WeChat Mini Program Rich Text Parsing Component. , it supports Html and markdown conversion to wxml visualization. Not much to say below, code contribution: Data returned by API:


WeChat applet parsing H5 file method
Note: The value corresponding to

message is


[AppleScript]

"<h2 id="材料-nbsp">材料 </h2><hr>  \n<p>雪梨一个、冰糖适量、牙签几根</p>   <h2 id="做法-nbsp">做法 </h2><hr>  \n<p>1、雪梨洗好,用刀切去尾部,用勺子挖出梨核,最好挖干净,不然影响口感。 </p> \n<p>2、放几颗冰糖进去,插几根牙签,隔水蒸30分钟左右就OK了。</p>",
      "name": "冰糖雪梨"


This applet cannot be parsed, so here’s the key point.

wxParse-WeChat applet rich text parsing component. Through this component, the applet can parse some html files including emoticons. The following is Big gift package, I will demonstrate how to use:


Download the official demo
  • Copy folder wxParse, which is at the same level as the pages file directory
  • //wxParse目录
    - wxParse/
      -wxParse.js(必须存在)
      -html2json.js(必须存在)
      -htmlparser.js(必须存在)
      -showdown.js(必须存在)
      -wxDiscode.js(必须存在)
      -wxParse.wxml(必须存在)
      -wxParse.wxss(必须存在)
      -emojis(可选)

3.Introduce necessary files

3.1 Add the following code in the target wxml file

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

3.2 Add the following code in the wxss file (can be the global wxss or the target wxss file)

@import "/wxParse/wxParse.wxss";


3.3 Data binding (add in the target js file)

//在 onLoad 函数里添加哦,
var article = &#39;<p>我是HTML代码</p>&#39;;
/**
* 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(&#39;article&#39;, &#39;html&#39;, article, that,5);

4. You have succeeded. If you don’t believe me, look at the simulator


WeChat applet parsing H5 file method



The above is the detailed content of WeChat applet parsing H5 file method. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use