Skip to content

jsCONFIG/btag-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BTag Parser

======

用于解析简单的字符串为对应的标签树,支持自定义标签

Options - btagParser

tagList (default: ['b', 'i', 'u']);

要解析的标签列表

brSym (default: 'br');

换行符,设置 null 来忽略;

API

var parser = btagParser();

parser(str[, translateCharacter]);

translateCharacter用于确定是否将特殊字符转义,默认为false

Example

var str = '<i>To be</i> or <i><b>not</b> to be</i>, That is a <b>question</b>';
var parser = btagParser();
parser(str);
/*
[
    {
        "type": "i",
        "value": [
            {
                "type": "normal",
                "value": "To be"
            }
        ]
    },
    {
        "type": "normal",
        "value": " or "
    },
    {
        "type": "i",
        "value": [
            {
                "type": "b",
                "value": [
                    {
                        "type": "normal",
                        "value": "not"
                    }
                ]
            },
            {
                "type": "normal",
                "value": " to be"
            }
        ]
    },
    {
        "type": "normal",
        "value": ", That is a "
    },
    {
        "type": "b",
        "value": [
            {
                "type": "normal",
                "value": "question"
            }
        ]
    }
]
*/

About

将简单的标签字符串解析成标签树

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors