Latest 0.0.1
Homepage https://github.com/zhu410289616/RHParser
License MIT
Platforms ios 8.0
Frameworks UIKit, Foundation
Authors

html、xml等标记语言解析。可以方便的转换为NSAttributedString。

把html转换为NSAttributedString

NSString *htmlString = @"<font color="#fa8919" size='58'>43333333</font>";
RHHtmlParser *htmlParser = [[RHHtmlParser alloc] init];
NSAttributedString *attributedString = [htmlParser parseString:htmlString filter:nil];

自定义样式

NSString *htmlString = @"<username>我是username自定义样式</username><password size='20'>我是password自定义样式,注意属性内容</password>";
//自定义样式
NSDictionary *customStyles = @{
                               NSForegroundColorAttributeName: [UIColor orangeColor],
                               NSBackgroundColorAttributeName: [UIColor blueColor]
                               };
[htmlParser addStyle:customStyles forTag:@"username"];
[htmlParser addNodeBlock:^NSAttributedString *(RHNode *node, NSDictionary *defaultStyles) {
    NSString *theContent = node.content ?: @"";

    NSString *theSizeString = node.attributes[@"size"];
    NSDictionary *theStyle = @{
                               NSForegroundColorAttributeName: [UIColor redColor],
                               NSFontAttributeName: [UIFont systemFontOfSize:[theSizeString floatValue]]
                               };

    NSAttributedString *theAttributedString = [[NSAttributedString alloc] initWithString:theContent attributes:theStyle];

    return theAttributedString;
} forTag:@"password"];
NSAttributedString *attributedString = [htmlParser parseString:htmlString filter:nil];

0
1
2

Latest podspec

{
    "name": "RHParser",
    "version": "0.0.1",
    "summary": "htmlu3001xmlu7b49u6807u8bb0u8bedu8a00u89e3u6790u3002u53efu4ee5u65b9u4fbfu7684u8f6cu6362u4e3aNSAttributedStringu3002",
    "description": "htmlu3001xmlu7b49u6807u8bb0u8bedu8a00u89e3u6790u3002u53efu4ee5u65b9u4fbfu7684u628ahtmlu8f6cu6362u4e3aNSAttributedStringu3002u652fu6301u81eau5b9au4e49u6837u5f0fu3002",
    "homepage": "https://github.com/zhu410289616/RHParser",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "zhu410289616": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/zhu410289616/RHParser.git",
        "tag": "0.0.1"
    },
    "source_files": [
        "RHParser/*.{h,m}",
        "RHParser/**/*.{h,m}"
    ],
    "frameworks": [
        "UIKit",
        "Foundation"
    ],
    "libraries": "xml2",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2"
    }
}

Pin It on Pinterest

Share This