Skip to content

Commit b3b9ab7

Browse files
committed
Merge branch 'release/3.1.0'
2 parents 70eeecb + fa0201f commit b3b9ab7

31 files changed

+779
-100
lines changed

.jazzy.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module: HTMLKit
2-
module_version: 3.0.0
2+
module_version: 3.1.0
33
author: Iskandar Abudiab
44
author_url: https://twitter.com/iabudiab
55
github_url: https://github.com/iabudiab/HTMLKit
@@ -33,6 +33,7 @@ custom_categories:
3333
- HTMLTemplate
3434
- HTMLDOMTokenList
3535
- HTMLRange
36+
- HTMLSerializer
3637

3738
- name: Iteration & Filtering
3839
children:
@@ -41,7 +42,9 @@ custom_categories:
4142
- HTMLNodeFilterShowOptions
4243
- HTMLNodeFilterValue
4344
- HTMLNodeFilterBlock
45+
- HTMLNodeVisitor
4446
- HTMLSelectorNodeFilter
47+
- HTMLTreeVisitor
4548
- HTMLTreeWalker
4649

4750
- name: Structures

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Change Log
22

3+
## [3.1.0](https://github.com/iabudiab/HTMLKit/releases/tag/3.1.0)
4+
5+
Release on 2019.08.20
6+
7+
### Added
8+
9+
- `HTMLTreeVisitor` that walks the DOM in tree order
10+
- New HTML serialization implementation based on visitor pattern
11+
12+
### Fixes
13+
14+
- HTML serialization for deeply nested DOM trees (issue #33)
15+
- Occasional Internal Consistency exceptions when deallocating node iterator (issue #36)
16+
17+
318
## [3.0.0](https://github.com/iabudiab/HTMLKit/releases/tag/3.0.0)
419

520
Released on 2019.03.28

Example/HTMLKitExample/HTMLKitExample/main.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ do {
112112
try scraper.load()
113113

114114
// Parse the selector
115-
let repositoryContent = try CSSSelectorParser.parseSelector("[role='main'] .repository-content > .file-wrap > .files tr.js-navigation-item")
115+
let repositoryContent = try CSSSelectorParser.parseSelector(".repository-content > .file-wrap > table.files tr.js-navigation-item")
116116

117117
// Query matching elements
118118
let files = try scraper.listElements(matching: repositoryContent)
@@ -131,13 +131,10 @@ do {
131131
// The following selector: "[role='main'] div.file table.js-file-line-container td:nth-child(2)"
132132
// can be defined in type-safe manner:
133133
let selector = allOf([
134-
descendantOfElementSelector(
135-
attributeSelector(.exactMatch, "role", "main")
136-
),
137134
descendantOfElementSelector(
138135
allOf([
139136
typeSelector("div"),
140-
classSelector("file")
137+
classSelector("repository-content")
141138
])
142139
),
143140
descendantOfElementSelector(

HTMLKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "HTMLKit"
3-
s.version = "3.0.0"
3+
s.version = "3.1.0"
44
s.summary = "HTMLKit, an Objective-C framework for your everyday HTML needs."
55
s.license = "MIT"
66
s.homepage = "https://github.com/iabudiab/HTMLKit"

HTMLKit.xcodeproj/project.pbxproj

Lines changed: 87 additions & 3 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ To add `HTMLKit` as a dependency into your project using CocoaPods just add the
7777

7878
```ruby
7979
target 'MyTarget' do
80-
pod 'HTMLKit', '~> 2.1'
80+
pod 'HTMLKit', '~> 3.1'
8181
end
8282
```
8383

@@ -94,7 +94,7 @@ $ pod install
9494
Add `HTMLKit` to your `Package.swift` dependecies:
9595

9696
```swift
97-
.Package(url: "https://github.com/iabudiab/HTMLKit", majorVersion: 2)
97+
.Package(url: "https://github.com/iabudiab/HTMLKit", majorVersion: 3)
9898
```
9999

100100
Then run:

Sources/HTMLComment.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ - (instancetype)initWithData:(NSString *)data
2121
return [super initWithName:@"#comment" type:HTMLNodeComment data:data];
2222
}
2323

24-
#pragma mark - Serialization
25-
26-
- (NSString *)outerHTML
27-
{
28-
return [NSString stringWithFormat:@"<!--%@-->", self.data];
29-
}
30-
3124
#pragma mark - Description
3225

3326
- (NSString *)description

Sources/HTMLDocument.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ - (void)attachNodeIterator:(HTMLNodeIterator *)iterator
141141

142142
- (void)detachNodeIterator:(HTMLNodeIterator *)iterator
143143
{
144-
[_nodeIterators removeObject:iterator];
144+
// NOOP
145145
}
146146

147147
#pragma mark - Ranges
@@ -153,7 +153,7 @@ - (void)attachRange:(HTMLRange *)range
153153

154154
- (void)detachRange:(HTMLRange *)range
155155
{
156-
[_ranges removeObject:range];
156+
// NOOP
157157
}
158158

159159
- (void)didRemoveCharacterDataInNode:(HTMLCharacterData *)node atOffset:(NSUInteger)offset withLength:(NSUInteger)length

Sources/HTMLDocumentType.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,6 @@ - (id)copyWithZone:(NSZone *)zone
144144
return copy;
145145
}
146146

147-
#pragma mark - Serialization
148-
149-
- (NSString *)outerHTML
150-
{
151-
return [NSString stringWithFormat:@"<!DOCTYPE %@>", self.name];
152-
}
153-
154147
#pragma mark - Description
155148

156149
- (NSString *)description

Sources/HTMLElement.m

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -149,42 +149,6 @@ - (id)copyWithZone:(NSZone *)zone
149149
return copy;
150150
}
151151

152-
#pragma mark - Serialization
153-
154-
- (NSString *)outerHTML
155-
{
156-
NSMutableString *result = [NSMutableString string];
157-
158-
[result appendFormat:@"<%@", self.tagName];
159-
[self.attributes enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
160-
NSMutableString *escaped = [value mutableCopy];
161-
[escaped replaceOccurrencesOfString:@"&" withString:@"&amp;" options:0 range:NSMakeRange(0, escaped.length)];
162-
[escaped replaceOccurrencesOfString:@"0x00A0" withString:@"&nbsp;" options:0 range:NSMakeRange(0, escaped.length)];
163-
[escaped replaceOccurrencesOfString:@"\"" withString:@"&quot;" options:0 range:NSMakeRange(0, escaped.length)];
164-
165-
[result appendFormat:@" %@=\"%@\"", key, escaped];
166-
}];
167-
168-
[result appendString:@">"];
169-
170-
if ([self.tagName isEqualToAny:@"area", @"base", @"basefont", @"bgsound", @"br", @"col", @"embed",
171-
@"frame", @"hr", @"img", @"input", @"keygen", @"link", @"menuitem", @"meta", @"param", @"source",
172-
@"track", @"wbr", nil]) {
173-
return result;
174-
}
175-
176-
if ([self.tagName isEqualToAny:@"pre", @"textarea", @"listing", nil] && self.firstChild.nodeType == HTMLNodeText) {
177-
HTMLText *textNode = (HTMLText *)self.firstChild;
178-
if ([textNode.data hasPrefix:@"\n"]) {
179-
[result appendString:@"\n"];
180-
}
181-
}
182-
[result appendString:self.innerHTML];
183-
[result appendFormat:@"</%@>", self.tagName];
184-
185-
return result;
186-
}
187-
188152
#pragma mark - Description
189153

190154
- (NSString *)description

0 commit comments

Comments
 (0)