Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
johnxnguyen committed Mar 20, 2021
1 parent ded8259 commit 5087876
Show file tree
Hide file tree
Showing 80 changed files with 714 additions and 210 deletions.
16 changes: 8 additions & 8 deletions Down.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
EE3E7E702604010700170A52 /* StylerTestSuite.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE59C30122ECF0BD006EE8A8 /* StylerTestSuite.swift */; };
EE3E7E812604019300170A52 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = EE3E7E802604019300170A52 /* SnapshotTesting */; };
EE3E7E88260401F000170A52 /* VisitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE64FEEF225BEB3900A35B34 /* VisitorTests.swift */; };
EE408A39230338B600E5278A /* CGPoint_TranslateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE408A38230338B600E5278A /* CGPoint_TranslateTests.swift */; };
EE408A3B2303399B00E5278A /* CGRect_HelpersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE408A3A2303399B00E5278A /* CGRect_HelpersTests.swift */; };
EE408A39230338B600E5278A /* CGPointTranslateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE408A38230338B600E5278A /* CGPointTranslateTests.swift */; };
EE408A3B2303399B00E5278A /* CGRectHelpersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE408A3A2303399B00E5278A /* CGRectHelpersTests.swift */; };
EE408A3D23033B6B00E5278A /* ListItemPrefixGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE408A3C23033B6B00E5278A /* ListItemPrefixGeneratorTests.swift */; };
EE44848B2301E51C0065C836 /* CodeBlockOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE44848A2301E51C0065C836 /* CodeBlockOptions.swift */; };
EE4484912301F2920065C836 /* CGPoint+Translate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4484902301F2920065C836 /* CGPoint+Translate.swift */; };
Expand Down Expand Up @@ -268,8 +268,8 @@
EE0E54F72300800E0070C83F /* BlockBackgroundColorAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockBackgroundColorAttribute.swift; sourceTree = "<group>"; };
EE335C4922EDC85900648842 /* ListItemStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemStyleTests.swift; sourceTree = "<group>"; };
EE39B28026063E0D002C4F8D /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
EE408A38230338B600E5278A /* CGPoint_TranslateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGPoint_TranslateTests.swift; sourceTree = "<group>"; };
EE408A3A2303399B00E5278A /* CGRect_HelpersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGRect_HelpersTests.swift; sourceTree = "<group>"; };
EE408A38230338B600E5278A /* CGPointTranslateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGPointTranslateTests.swift; sourceTree = "<group>"; };
EE408A3A2303399B00E5278A /* CGRectHelpersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGRectHelpersTests.swift; sourceTree = "<group>"; };
EE408A3C23033B6B00E5278A /* ListItemPrefixGeneratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemPrefixGeneratorTests.swift; sourceTree = "<group>"; };
EE44848A2301E51C0065C836 /* CodeBlockOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeBlockOptions.swift; sourceTree = "<group>"; };
EE4484902301F2920065C836 /* CGPoint+Translate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGPoint+Translate.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -512,8 +512,8 @@
EE408A3E23033DFE00E5278A /* Helpers */ = {
isa = PBXGroup;
children = (
EE408A3A2303399B00E5278A /* CGRect_HelpersTests.swift */,
EE408A38230338B600E5278A /* CGPoint_TranslateTests.swift */,
EE408A3A2303399B00E5278A /* CGRectHelpersTests.swift */,
EE408A38230338B600E5278A /* CGPointTranslateTests.swift */,
EE97254222C14B79004D3B3A /* NSAttributedString+HelpersTests.swift */,
EE97253D22C130D8004D3B3A /* NSMutableAttributedString+AttributesTests.swift */,
);
Expand Down Expand Up @@ -1025,8 +1025,8 @@
EE8F38CC22BFB2420056270E /* NodeTests.swift in Sources */,
EE3E7E3F260400EE00170A52 /* LinkStyleTests.swift in Sources */,
EE3E7E38260400E800170A52 /* DownDebugLayoutManagerTests.swift in Sources */,
EE408A39230338B600E5278A /* CGPoint_TranslateTests.swift in Sources */,
EE408A3B2303399B00E5278A /* CGRect_HelpersTests.swift in Sources */,
EE408A39230338B600E5278A /* CGPointTranslateTests.swift in Sources */,
EE408A3B2303399B00E5278A /* CGRectHelpersTests.swift in Sources */,
EE3E7E88260401F000170A52 /* VisitorTests.swift in Sources */,
8AFAEB071E6E331700E09B68 /* DownViewTests.swift in Sources */,
8AFAEB061E6E331700E09B68 /* BindingTests.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/BaseNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import libcmark

public class BaseNode: Node {

// MARK: - Properties

public let cmarkNode: CMarkNode

public private(set) lazy var children: [Node] = Array(childSequence)
Expand All @@ -26,6 +28,8 @@ public class BaseNode: Node {
return depth
}()

// MARK: - Life cycle

init(cmarkNode: CMarkNode) {
self.cmarkNode = cmarkNode
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Down/AST/Nodes/BlockQuote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ extension BlockQuote: CustomDebugStringConvertible {
public var debugDescription: String {
return "Block Quote"
}

}
29 changes: 24 additions & 5 deletions Sources/Down/AST/Nodes/ChildSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@

import libcmark

/// Sequence of child nodes
/// Sequence of child nodes.

public struct ChildSequence: Sequence {

// MARK: - Properties

let node: CMarkNode

public struct Iterator: IteratorProtocol {
// MARK: - Methods

public func makeIterator() -> Iterator {
return Iterator(node: cmark_node_first_child(node))
}

}

// MARK: - Iterator

public extension ChildSequence {

struct Iterator: IteratorProtocol {

// MARK: - Properties

var node: CMarkNode?

// MARK: - Methods

public mutating func next() -> Node? {
guard let node = node else { return nil }
defer { self.node = cmark_node_next(node) }
Expand All @@ -25,9 +46,7 @@ public struct ChildSequence: Sequence {

return result
}
}

public func makeIterator() -> Iterator {
return Iterator(node: cmark_node_first_child(node))
}

}
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/Code.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class Code: BaseNode {

// MARK: - Properties

/// The code content, if present.

public private(set) lazy var literal: String? = cmarkNode.literal

}
Expand All @@ -22,4 +25,5 @@ extension Code: CustomDebugStringConvertible {
public var debugDescription: String {
return "Code - \(literal ?? "nil")"
}

}
5 changes: 5 additions & 0 deletions Sources/Down/AST/Nodes/CodeBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class CodeBlock: BaseNode {

// MARK: - Properties

/// The code content, if present.

public private(set) lazy var literal: String? = cmarkNode.literal

/// The fence info is an optional string that trails the opening sequence of backticks.
Expand All @@ -24,6 +27,7 @@ public class CodeBlock: BaseNode {
/// '''
/// ```
///

public private(set) lazy var fenceInfo: String? = cmarkNode.fenceInfo

}
Expand All @@ -36,4 +40,5 @@ extension CodeBlock: CustomDebugStringConvertible {
let content = (literal ?? "nil").replacingOccurrences(of: "\n", with: "\\n")
return "Code Block - fenceInfo: \(fenceInfo ?? "nil"), content: \(content)"
}

}
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/CustomBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class CustomBlock: BaseNode {

// MARK: - Properfies

/// The custom content, if present.

public private(set) lazy var literal: String? = cmarkNode.literal

}
Expand All @@ -22,4 +25,5 @@ extension CustomBlock: CustomDebugStringConvertible {
public var debugDescription: String {
return "Custom Block - \(literal ?? "nil")"
}

}
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/CustomInline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class CustomInline: BaseNode {

// MARK: - Properties

/// The custom content, if present.

public private(set) lazy var literal: String? = cmarkNode.literal
}

Expand All @@ -21,4 +24,5 @@ extension CustomInline: CustomDebugStringConvertible {
public var debugDescription: String {
return "Custom Inline - \(literal ?? "nil")"
}

}
7 changes: 6 additions & 1 deletion Sources/Down/AST/Nodes/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import libcmark

public class Document: BaseNode {

// MARK: - Life cycle

deinit {
// Frees the node and all its children.
cmark_node_free(cmarkNode)
}

// MARK: - Methods

/// Accepts the given visitor and return its result.

@discardableResult
public func accept<T: Visitor>(_ visitor: T) -> T.Result {
return visitor.visit(document: self)
Expand All @@ -30,4 +34,5 @@ extension Document: CustomDebugStringConvertible {
public var debugDescription: String {
return "Document"
}

}
1 change: 1 addition & 0 deletions Sources/Down/AST/Nodes/Emphasis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ extension Emphasis: CustomDebugStringConvertible {
public var debugDescription: String {
return "Emphasis"
}

}
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/Heading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class Heading: BaseNode {

// MARK: - Properties

/// The level of the heading, a value between 1 and 6.

public private(set) lazy var headingLevel: Int = cmarkNode.headingLevel
}

Expand All @@ -21,4 +24,5 @@ extension Heading: CustomDebugStringConvertible {
public var debugDescription: String {
return "Heading - L\(headingLevel)"
}

}
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/HtmlBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class HtmlBlock: BaseNode {

// MARK: - Properties

/// The html content, if present.

public private(set) lazy var literal: String? = cmarkNode.literal

}
Expand All @@ -23,4 +26,5 @@ extension HtmlBlock: CustomDebugStringConvertible {
let content = (literal ?? "nil").replacingOccurrences(of: "\n", with: "\\n")
return "Html Block - content: \(content)"
}

}
4 changes: 4 additions & 0 deletions Sources/Down/AST/Nodes/HtmlInline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import libcmark

public class HtmlInline: BaseNode {

// MARK: - Properties

/// The html tag, if present.

public private(set) lazy var literal: String? = cmarkNode.literal

}
Expand All @@ -22,4 +25,5 @@ extension HtmlInline: CustomDebugStringConvertible {
public var debugDescription: String {
return "Html Inline - \(literal ?? "nil")"
}

}
7 changes: 5 additions & 2 deletions Sources/Down/AST/Nodes/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import libcmark

public class Image: BaseNode {

// MARK: - Properties

/// The title of the image, if present.
///
/// In the example below, the first line is a reference link, with the reference at the
Expand All @@ -21,7 +23,7 @@ public class Image: BaseNode {
/// ...
/// [<id>]: <url> "<title>"
/// ```
///

public private(set) lazy var title: String? = cmarkNode.title

/// The url of the image, if present.
Expand All @@ -31,7 +33,7 @@ public class Image: BaseNode {
/// ```
/// ![<text>](<url>)
/// ```
///

public private(set) lazy var url: String? = cmarkNode.url

}
Expand All @@ -43,4 +45,5 @@ extension Image: CustomDebugStringConvertible {
public var debugDescription: String {
return "Image - title: \(title ?? "nil"), url: \(url ?? "nil"))"
}

}
1 change: 1 addition & 0 deletions Sources/Down/AST/Nodes/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ extension Item: CustomDebugStringConvertible {
public var debugDescription: String {
return "Item"
}

}
1 change: 1 addition & 0 deletions Sources/Down/AST/Nodes/LineBreak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ extension LineBreak: CustomDebugStringConvertible {
public var debugDescription: String {
return "Line Break"
}

}
7 changes: 5 additions & 2 deletions Sources/Down/AST/Nodes/Link.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import libcmark

public class Link: BaseNode {

// MARK: - Properties

/// The title of the link, if present.
///
/// In the example below, the first line is a reference link, with the reference at the
Expand All @@ -21,7 +23,7 @@ public class Link: BaseNode {
/// ...
/// [<id>]: <url> "<title>"
/// ```
///

public private(set) lazy var title: String? = cmarkNode.title

/// The url of the link, if present.
Expand All @@ -31,7 +33,7 @@ public class Link: BaseNode {
/// ```
/// [<text>](<url>)
/// ```
///

public private(set) lazy var url: String? = cmarkNode.url

}
Expand All @@ -43,4 +45,5 @@ extension Link: CustomDebugStringConvertible {
public var debugDescription: String {
return "Link - title: \(title ?? "nil"), url: \(url ?? "nil"))"
}

}
Loading

0 comments on commit 5087876

Please sign in to comment.