A PHP library that can convert html into wxml and back.
- PHP >= 5.4
$ composer require "yyxx9988/html-wxml-converter"
use \yyxx9988\mlconverter\Converter;
$converter = new Converter();
$converter->setHtml('
<div>
<a>...</a>
<p><img src="..."></p>
</div>
');
echo $converter->convert();
// result
<view data-htmltag="div">
<view data-htmltag="a">...</view>
<view data-htmltag="p"><image src="..."></image></view>
</view>
- Default supported tags
[
'p' => 'view',
'h1' => 'view',
'h2' => 'view',
'h3' => 'view',
'h4' => 'view',
'h5' => 'view',
'h6' => 'view',
'ul' => 'view',
'ol' => 'view',
'li' => 'view',
'div' => 'view',
'nav' => 'view',
'pre' => 'view',
'code' => 'view',
'menu' => 'view',
'aside' => 'view',
'header' => 'view',
'footer' => 'view',
'legend' => 'view',
'section' => 'view',
'article' => 'view',
'caption' => 'view',
'details' => 'view',
'summary' => 'view',
'menuitem' => 'view',
'blockquote' => 'view',
'i' => 'text',
'b' => 'text',
's' => 'text',
'u' => 'text',
'big' => 'text',
'del' => 'text',
'sub' => 'text',
'sup' => 'text',
'ins' => 'text',
'font' => 'text',
'mark' => 'text',
'time' => 'text',
'span' => 'text',
'center' => 'text',
'strong' => 'text',
'strike' => 'text',
];
- Customize special tags
$converter = new Converter();
// add a tag
$converter->addHtmlTags('xxx', 'view');
// change a tag
$converter->setHtmlTags('li', 'text');
// remove a tag
$converter->removeHtmlTags('article');
echo $converter->convert();
MIT