Skip to content

Commit

Permalink
Feature: <li> tag transform (#2)
Browse files Browse the repository at this point in the history
* Add html `li` tag transform
  • Loading branch information
remarcus authored Oct 25, 2021
1 parent a6c2fe7 commit dd9420a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions VGHtmlParser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
359E208F256402DF006695C6 /* TFHpple.h in Headers */ = {isa = PBXBuildFile; fileRef = 359E2089256402DF006695C6 /* TFHpple.h */; settings = {ATTRIBUTES = (Public, ); }; };
359E2090256402DF006695C6 /* TFHppleElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 359E208A256402DF006695C6 /* TFHppleElement.m */; };
359E2091256402DF006695C6 /* XPathQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 359E208B256402DF006695C6 /* XPathQuery.m */; };
805E6F6A2718528A0068E2CB /* HtmlLiTagTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = 805E6F69271852790068E2CB /* HtmlLiTagTransform.h */; settings = {ATTRIBUTES = (Public, ); }; };
805E6F6C271852FD0068E2CB /* HtmlLiTagTransform.m in Sources */ = {isa = PBXBuildFile; fileRef = 805E6F6B271852FD0068E2CB /* HtmlLiTagTransform.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -54,6 +56,8 @@
359E208B256402DF006695C6 /* XPathQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XPathQuery.m; sourceTree = "<group>"; };
35A06E14255EE5860061BC41 /* VGHtmlParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = VGHtmlParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
35A06E18255EE5860061BC41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
805E6F69271852790068E2CB /* HtmlLiTagTransform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HtmlLiTagTransform.h; sourceTree = "<group>"; };
805E6F6B271852FD0068E2CB /* HtmlLiTagTransform.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HtmlLiTagTransform.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -96,6 +100,8 @@
359E20662563FF1C006695C6 /* HtmlBTagTransform.h */,
359E20672563FF1C006695C6 /* HtmlITagTransform.m */,
359E20682563FF1C006695C6 /* HtmlATagTransform.h */,
805E6F69271852790068E2CB /* HtmlLiTagTransform.h */,
805E6F6B271852FD0068E2CB /* HtmlLiTagTransform.m */,
);
path = VintedTransformers;
sourceTree = "<group>";
Expand Down Expand Up @@ -175,6 +181,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
805E6F6A2718528A0068E2CB /* HtmlLiTagTransform.h in Headers */,
359E207A2563FF1D006695C6 /* VGHtmlATagTransfom.h in Headers */,
359E208E256402DF006695C6 /* XPathQuery.h in Headers */,
359E20762563FF1D006695C6 /* HtmlBTagTransform.h in Headers */,
Expand Down Expand Up @@ -258,6 +265,7 @@
files = (
359E207D2563FF1D006695C6 /* VGHtmlATagTransfom.m in Sources */,
359E20772563FF1D006695C6 /* HtmlITagTransform.m in Sources */,
805E6F6C271852FD0068E2CB /* HtmlLiTagTransform.m in Sources */,
359E2091256402DF006695C6 /* XPathQuery.m in Sources */,
359E207C2563FF1D006695C6 /* VGHtmlPTagTransform.m in Sources */,
359E20722563FF1D006695C6 /* VGHtmlParser.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions VGHtmlParser/Classes/VGHtmlParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "HtmlATagTransform.h"
#import "HtmlITagTransform.h"
#import "HtmlBTagTransform.h"
#import "HtmlLiTagTransform.h"


NSString * const VGHtmlParserMissingTagNameException = @"VGHtmlParserMissingTagNameException";
Expand All @@ -34,6 +35,7 @@ + (instancetype)defaultParserWithHtmlData:(NSData *)htmlData linkAttributes:(NSD
[htmlParser addHtmlTagTransform:aTagTransform];
[htmlParser addHtmlTagTransform:[[HtmlITagTransform alloc] init]];
[htmlParser addHtmlTagTransform:[[HtmlBTagTransform alloc] init]];
[htmlParser addHtmlTagTransform:[[HtmlLiTagTransform alloc] init]];
return htmlParser;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
#import <VGHtmlParser/VGHtmlTagTransform.h>

@interface HtmlLiTagTransform : NSObject<VGHtmlTagTransform>

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import UIKit;
#import "HtmlLiTagTransform.h"

@implementation HtmlLiTagTransform

- (NSString *)tagName
{
return @"li";
}

- (NSAttributedString *)transformAttributedString:(NSAttributedString *)attrString element:(TFHppleElement *)element
{
if (!attrString.length) {
return attrString;
}

NSMutableAttributedString *newAttrString = [[NSMutableAttributedString alloc] initWithString:@" \u2022 "];
[newAttrString appendAttributedString:[attrString mutableCopy]];
[newAttrString appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
return [newAttrString copy];
}

@end

0 comments on commit dd9420a

Please sign in to comment.