项目作者: yyxx9988

项目描述 :
A PHP library that can convert html into wxml and back.
高级语言: PHP
项目地址: git://github.com/yyxx9988/html-wxml-converter.git
创建时间: 2017-03-12T11:27:22Z
项目社区:https://github.com/yyxx9988/html-wxml-converter

开源协议:MIT License

下载


Html-Wxml Converter

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

Requirement

  • PHP >= 5.4

Installation

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

Usage

  1. use \yyxx9988\mlconverter\Converter;
  2. $converter = new Converter();
  3. $converter->setHtml('
  4. <div>
  5. <a>...</a>
  6. <p><img src="..."></p>
  7. </div>
  8. ');
  9. echo $converter->convert();
  10. // result
  11. <view data-htmltag="div">
  12. <view data-htmltag="a">...</view>
  13. <view data-htmltag="p"><image src="..."></image></view>
  14. </view>

Customize

  • Default supported tags

    1. [
    2. 'p' => 'view',
    3. 'h1' => 'view',
    4. 'h2' => 'view',
    5. 'h3' => 'view',
    6. 'h4' => 'view',
    7. 'h5' => 'view',
    8. 'h6' => 'view',
    9. 'ul' => 'view',
    10. 'ol' => 'view',
    11. 'li' => 'view',
    12. 'div' => 'view',
    13. 'nav' => 'view',
    14. 'pre' => 'view',
    15. 'code' => 'view',
    16. 'menu' => 'view',
    17. 'aside' => 'view',
    18. 'header' => 'view',
    19. 'footer' => 'view',
    20. 'legend' => 'view',
    21. 'section' => 'view',
    22. 'article' => 'view',
    23. 'caption' => 'view',
    24. 'details' => 'view',
    25. 'summary' => 'view',
    26. 'menuitem' => 'view',
    27. 'blockquote' => 'view',
    28. 'i' => 'text',
    29. 'b' => 'text',
    30. 's' => 'text',
    31. 'u' => 'text',
    32. 'big' => 'text',
    33. 'del' => 'text',
    34. 'sub' => 'text',
    35. 'sup' => 'text',
    36. 'ins' => 'text',
    37. 'font' => 'text',
    38. 'mark' => 'text',
    39. 'time' => 'text',
    40. 'span' => 'text',
    41. 'center' => 'text',
    42. 'strong' => 'text',
    43. 'strike' => 'text',
    44. ];
  • Customize special tags

  1. $converter = new Converter();
  2. // add a tag
  3. $converter->addHtmlTags('xxx', 'view');
  4. // change a tag
  5. $converter->setHtmlTags('li', 'text');
  6. // remove a tag
  7. $converter->removeHtmlTags('article');
  8. echo $converter->convert();

License

MIT