Updates and fixes
This commit is contained in:
@@ -147,6 +147,43 @@ public class HTMLNode : XMLNode, IGlobalContainer {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func iterate(_ index:Int, _ skipTextNodes:Bool, _ cb:(HTMLNode, Int)->()) -> Int {
|
||||
if (skipTextNodes && self is HTMLText) {
|
||||
return index
|
||||
}
|
||||
cb(self, index)
|
||||
var newIndex = index + 1
|
||||
for eachChild in children {
|
||||
newIndex = eachChild.iterate(newIndex, skipTextNodes, cb)
|
||||
}
|
||||
return newIndex
|
||||
}
|
||||
|
||||
public func flatten() -> [HTMLNode] {
|
||||
let count = countElements()
|
||||
let result:[HTMLNode] = Array(unsafeUninitializedCapacity: count+1) { buffer, initializedCount in
|
||||
initializedCount = self.addTo(array: &buffer, index: 0)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public func countElements() -> Int {
|
||||
var result = 1
|
||||
for eachChild in children {
|
||||
result += eachChild.countElements()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private func addTo(array:inout UnsafeMutableBufferPointer<HTMLNode>, index:Int) -> Int {
|
||||
array.initializeElement(at: index, to: self)
|
||||
var newIndex = index + 1
|
||||
for eachChild in children {
|
||||
newIndex = eachChild.addTo(array: &array, index: newIndex)
|
||||
}
|
||||
return newIndex
|
||||
}
|
||||
|
||||
public override func renderAttributes() -> String {
|
||||
var result = super.renderAttributes()
|
||||
var first = result.count == 0
|
||||
|
||||
@@ -27,7 +27,7 @@ public class HTMLParser {
|
||||
}
|
||||
*/
|
||||
//TODO: Not really an html node..
|
||||
public class HTMLText : HTMLNode, IFlowContent {
|
||||
public class HTMLText : HTMLNode, IFlowContent, IPhrasing, IFlow {
|
||||
|
||||
public var content: String
|
||||
|
||||
|
||||
@@ -385,7 +385,7 @@ public class XMLParser
|
||||
return String(cString: buffer)
|
||||
}*/
|
||||
|
||||
init?(str:String) {
|
||||
public init?(str:String) {
|
||||
iterator = str.unicodeScalars.makeIterator()
|
||||
position = Position()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user