yyxx9988/html-wxml-converter

A PHP library that can convert html into wxml and back.

v1.0.0 2017-03-13 02:40 UTC

This package is not auto-updated.

Last update: 2024-04-17 19:02:56 UTC


README

A PHP library that can convert html into wxml and back.

Requirement

  • PHP >= 5.4

Installation

$ composer require "yyxx9988/html-wxml-converter"

Usage

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>

Customize

  • 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();

License

MIT