Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Create default Styler for attributed string rendering #177

Merged
merged 198 commits into from Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from 168 commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
e6b4f3d
Add stubs
johnxnguyen Jun 22, 2019
687b0bf
Add some helper methods
johnxnguyen Jun 23, 2019
45b829f
Add very basic styling
johnxnguyen Jun 23, 2019
3fd3dc7
Add custom dynamic type for code
johnxnguyen Jun 23, 2019
06e580c
Clean up
johnxnguyen Jun 23, 2019
d914382
Allow DebugVisitor methods to be overridden
johnxnguyen Jun 23, 2019
3fbb5c8
Add method to calculate list depth
johnxnguyen Jun 23, 2019
f3f4085
Pass the list nest depth to the styler
johnxnguyen Jun 23, 2019
3d3ecc5
Move nest depth property to base node
johnxnguyen Jun 23, 2019
3ea078f
Add helper to get parent
johnxnguyen Jun 23, 2019
26325f1
Add property to check for top level paragraphs
johnxnguyen Jun 23, 2019
debc5e6
Add test
johnxnguyen Jun 23, 2019
b837995
Pass top level flag to paragraph styler
johnxnguyen Jun 23, 2019
b4c4b60
Only add pargraph style for top level paragraphs
johnxnguyen Jun 23, 2019
76710a8
Create ListItemPrefixGenerator
johnxnguyen Jun 23, 2019
8d856ee
Use list item prefix generator
johnxnguyen Jun 23, 2019
3e547b3
Fix debug description
johnxnguyen Jun 23, 2019
b0fb33b
WIP: list item styling
johnxnguyen Jun 23, 2019
3cd8cdd
Add tests
johnxnguyen Jun 24, 2019
e38f0e5
Tidy up
johnxnguyen Jun 24, 2019
838f7f2
Use paragraph separator code point
johnxnguyen Jun 24, 2019
48c17ae
Add list markers
johnxnguyen Jun 24, 2019
8479ff3
Add todo
johnxnguyen Jun 24, 2019
4ad103c
Add tests
johnxnguyen Jun 24, 2019
456c0f4
Tidy up
johnxnguyen Jun 24, 2019
6c34135
Calculate ranges of paragraphs excluding lists
johnxnguyen Jun 24, 2019
1bba0a5
Add item styling stubs
johnxnguyen Jun 24, 2019
0094dd2
Format indentation of nested liists
johnxnguyen Jun 24, 2019
f9b4de9
Refactor item styling
johnxnguyen Jun 25, 2019
f3f369e
Return self if prefix length exceeds bounds
johnxnguyen Jun 25, 2019
c8988f9
Add spacing after heading
johnxnguyen Jun 25, 2019
e8cc24c
Tidy up
johnxnguyen Jun 25, 2019
3d5298f
Add todo
johnxnguyen Jun 25, 2019
9957b3b
Organize tests
johnxnguyen Jun 27, 2019
b8d60e7
Rename method
johnxnguyen Jun 27, 2019
4a85fd0
Add test stubs
johnxnguyen Jun 27, 2019
5d8f884
Add tests
johnxnguyen Jun 27, 2019
fb873e9
Reorganize files
johnxnguyen Jun 27, 2019
e379878
Add tests
johnxnguyen Jun 27, 2019
c1f64f3
Loosen coupling between List and ListItemPrefixGenerator
johnxnguyen Jun 27, 2019
a8513b7
Add snapshot testing framework
johnxnguyen Jul 26, 2019
3e86941
Bump minimum deployment to iOS 10 for test target
johnxnguyen Jul 27, 2019
b4447dc
Refactor FontBook into FontCollection
johnxnguyen Jul 27, 2019
1738a45
Inject fonts into DefaultStyler
johnxnguyen Jul 27, 2019
c44bb7a
Create ParagraphStyleCollection & inject into DefaultStyler
johnxnguyen Jul 27, 2019
b2fdbff
Tidy up
johnxnguyen Jul 27, 2019
3961808
Create ColorCollection & inject into Default Styler
johnxnguyen Jul 27, 2019
367fae5
Style block quote
johnxnguyen Jul 27, 2019
fd7ea87
Style code blocks
johnxnguyen Jul 27, 2019
3ca77f2
Add colors to headings, text and inline code
johnxnguyen Jul 27, 2019
b23fc67
Move AttributeCollection into new file
johnxnguyen Jul 27, 2019
452b763
Organize file structure
johnxnguyen Jul 27, 2019
2ee7545
Rename item paragraph styler
johnxnguyen Jul 27, 2019
136103f
Style list item prefix in the styler
johnxnguyen Jul 27, 2019
e8eff28
Make ListItemParagraphStyler configurable
johnxnguyen Jul 27, 2019
1a241dd
Add base test suite for styler
johnxnguyen Jul 28, 2019
b2fbfa9
Tidy up
johnxnguyen Jul 28, 2019
33925f5
Add test stubs for list items
johnxnguyen Jul 28, 2019
6f040b2
Fix prefix indentation
johnxnguyen Jul 28, 2019
5b3d6aa
Add item prefix tests
johnxnguyen Jul 28, 2019
b518f3a
Allow styler properties to be externally configured
johnxnguyen Jul 28, 2019
873481d
Refactor styler test suite
johnxnguyen Jul 28, 2019
c03dcb6
Make ListItemParargraphStyler a class
johnxnguyen Jul 29, 2019
17119ad
Clean up
johnxnguyen Jul 29, 2019
4eeb912
Add new item styling tests
johnxnguyen Jul 29, 2019
0a08f3b
Ignore some test stubs
johnxnguyen Jul 29, 2019
9b33d86
Use snapshots for visitor tests
johnxnguyen Jul 29, 2019
9d01c6b
Add snapshots for strong, emphasized, code and html styles
johnxnguyen Jul 29, 2019
5c89342
Clean up
johnxnguyen Jul 29, 2019
19dea7a
Explicitly set point size after adding font trait
johnxnguyen Jul 30, 2019
787be63
Add monospace trait to font extension
johnxnguyen Jul 30, 2019
b4e57f4
Allow monospace font in headings
johnxnguyen Jul 30, 2019
daaf0af
Use heading level when styling
johnxnguyen Jul 30, 2019
1b918bc
Make test properties private
johnxnguyen Jul 30, 2019
97e5a88
Add heading style tests
johnxnguyen Jul 30, 2019
740e918
Add todos
johnxnguyen Jul 30, 2019
9f28df2
Use line separators in code blocks
johnxnguyen Jul 31, 2019
98503d0
Add code paragraph style
johnxnguyen Jul 31, 2019
e2290eb
Add support for custom thematic break attribute
johnxnguyen Aug 2, 2019
4caa30f
Add DownTextView
johnxnguyen Aug 3, 2019
7fbbab0
Add thematic break to color collection
johnxnguyen Aug 3, 2019
e8effa0
Add test for thematic break style
johnxnguyen Aug 3, 2019
74982b5
Append newline instead of line separator after thematic break
johnxnguyen Aug 3, 2019
45a8908
Add support for custom quote stripe attribute
johnxnguyen Aug 4, 2019
f88c793
Translate thematic break rect to container origin
johnxnguyen Aug 4, 2019
87e9ac9
Translate stripe by container origin
johnxnguyen Aug 4, 2019
cac3cc4
Clean up
johnxnguyen Aug 4, 2019
521c675
Remove insets property & use origin parameter
johnxnguyen Aug 4, 2019
43c9636
Clean up
johnxnguyen Aug 4, 2019
f4ce4e1
Add quote stripe options
johnxnguyen Aug 4, 2019
aad4e13
Move list item options to new file
johnxnguyen Aug 4, 2019
11b6bd1
Add quote styling tests
johnxnguyen Aug 4, 2019
1847652
Allow thematic break to be configured
johnxnguyen Aug 4, 2019
54a01f4
Test thematic break preservation in block quote
johnxnguyen Aug 4, 2019
a171246
Add todos
johnxnguyen Aug 4, 2019
1c63115
Add some more extension methods
johnxnguyen Aug 4, 2019
db9cf00
Add support for rendering quotes in a list
johnxnguyen Aug 4, 2019
2505415
Incrementally indent list items
johnxnguyen Aug 4, 2019
9b0aa3f
Fix quote indentation in list item
johnxnguyen Aug 4, 2019
53e5e01
Rename methods
johnxnguyen Aug 4, 2019
6d75a86
Clean up
johnxnguyen Aug 4, 2019
826f49a
Add test
johnxnguyen Aug 4, 2019
7995a08
Fix line break after code blocks
johnxnguyen Aug 6, 2019
f097c9e
Add code block style tests
johnxnguyen Aug 6, 2019
3f9bfa2
Add assert helper
johnxnguyen Aug 6, 2019
292a2e7
Clean up tests
johnxnguyen Aug 6, 2019
736978c
Set text container inset before fitting size to content
johnxnguyen Aug 6, 2019
a46e9ed
Extract DownDebugLayoutManager and DownDebugTextView
johnxnguyen Aug 6, 2019
458699e
Allow snapshots to show line fragments
johnxnguyen Aug 6, 2019
63134cb
Add color to links
johnxnguyen Aug 8, 2019
067b9f7
Add link style tests
johnxnguyen Aug 8, 2019
f04229c
Clean up file structure
johnxnguyen Aug 8, 2019
6e26db4
Remove redundant imports
johnxnguyen Aug 8, 2019
c272f4c
Clean up file structure
johnxnguyen Aug 8, 2019
f57a0f8
Fix DownTextView init
johnxnguyen Aug 8, 2019
bcd04b4
Draw line fragments in DownDebugLayoutManager
johnxnguyen Aug 8, 2019
66dee8b
Add debug style tests
johnxnguyen Aug 8, 2019
e25328c
Clean up file structure
johnxnguyen Aug 8, 2019
4204897
Remove isTopLevel from Paragraph
johnxnguyen Aug 8, 2019
4ba982d
Remove nestDepth from list item
johnxnguyen Aug 8, 2019
1892dc9
Remove unused extension method
johnxnguyen Aug 8, 2019
feb2cd3
Remove unused attribute keys
johnxnguyen Aug 8, 2019
d4517dc
Provide public init for ThematicBreakOptions
johnxnguyen Aug 8, 2019
541b3dc
Move max prefix width calculation to ListItemParagraphStyler
johnxnguyen Aug 10, 2019
4fb764d
Rename DefaultStyler to DownStyler
johnxnguyen Aug 10, 2019
4737f62
Extract styles into a configuration struct
johnxnguyen Aug 10, 2019
ff5ec88
Clean up
johnxnguyen Aug 10, 2019
cd16989
Clean up
johnxnguyen Aug 10, 2019
7f08651
Remove AttributeCollection
johnxnguyen Aug 10, 2019
1fa2045
Remove color from QuoteStripeOptions
johnxnguyen Aug 10, 2019
29a7bf7
Clean up
johnxnguyen Aug 10, 2019
05b41cf
Remove defaults from custom attributes
johnxnguyen Aug 10, 2019
6f3f64b
Render markdown within DownTextView
johnxnguyen Aug 11, 2019
72f7783
Fix quote stripe rendering
johnxnguyen Aug 11, 2019
f231029
Revert "Fix quote stripe rendering"
johnxnguyen Aug 11, 2019
4834ea6
Tidy up
johnxnguyen Aug 11, 2019
ee49032
Enrich code blocks with background color
johnxnguyen Aug 11, 2019
7d88d3d
Remove redundant initializers
johnxnguyen Aug 12, 2019
95d5035
Add CodeBlockOptions
johnxnguyen Aug 12, 2019
76413f8
Clean up
johnxnguyen Aug 12, 2019
01f5acf
Make extension local and private
johnxnguyen Aug 12, 2019
485cc06
Remove some duplication
johnxnguyen Aug 12, 2019
45f62ca
Rename method
johnxnguyen Aug 12, 2019
b86f052
Move non private extensions into new files
johnxnguyen Aug 12, 2019
758b37c
Remove duplication
johnxnguyen Aug 12, 2019
65cee19
Clean up
johnxnguyen Aug 12, 2019
8e28366
Add tests
johnxnguyen Aug 13, 2019
d816e3c
Rename method
johnxnguyen Aug 13, 2019
68fa461
Add tests
johnxnguyen Aug 13, 2019
80d6177
Fix prefix generation
johnxnguyen Aug 13, 2019
358d0ed
Add tests
johnxnguyen Aug 13, 2019
ee06f16
File organization
johnxnguyen Aug 13, 2019
8afe288
Add tests
johnxnguyen Aug 13, 2019
ec0dbd1
Clean up
johnxnguyen Aug 13, 2019
5463cf3
Remove duplicate comment
johnxnguyen Aug 13, 2019
32188d4
Flatten code & html block descriptions into single line
johnxnguyen Aug 13, 2019
f3ae6b7
Add tests
johnxnguyen Aug 13, 2019
ca97eef
Clean up
johnxnguyen Aug 13, 2019
a1059f8
Remove dynamic fonts
johnxnguyen Aug 15, 2019
d6461d0
Initial steps to support macOS & tvOS
johnxnguyen Aug 15, 2019
c15c007
Rename font traits
johnxnguyen Aug 15, 2019
c06f1da
Further support for macOS
johnxnguyen Aug 17, 2019
6eb9dd8
Clean up
johnxnguyen Aug 17, 2019
6276043
Use iPhone Xs simulator when testings on Travis
johnxnguyen Aug 17, 2019
a30c863
Merge branch 'master' into feature/default-styler
johnxnguyen Aug 21, 2019
4f409a9
Clean up old todos
johnxnguyen Sep 12, 2019
47a6a6f
Add Styler documentation
johnxnguyen Sep 12, 2019
de15557
Add documentation
johnxnguyen Sep 12, 2019
fd1fe2a
Make setter private
johnxnguyen Sep 19, 2019
856e52f
Remove duplication
johnxnguyen Sep 19, 2019
dece588
Fix typo
johnxnguyen Sep 19, 2019
89128d2
Name magic numbers
johnxnguyen Sep 19, 2019
48dc937
Make FontCollection and ColorCollection protocols
johnxnguyen Sep 24, 2019
72eaf19
Return self instead of nil
johnxnguyen Sep 24, 2019
c2f26b6
Mark feature unavailable for watchOS
johnxnguyen Sep 24, 2019
9dee485
Update to snapshot testing 1.6
johnxnguyen Oct 1, 2019
62b49fb
Check in snapshot testing framework for iOS
johnxnguyen Oct 1, 2019
cb70086
Re-record list item snapshots
johnxnguyen Oct 1, 2019
dcbe3e5
Remove old TODO
johnxnguyen Oct 1, 2019
5820994
Fix compiler error for macOS
johnxnguyen Oct 2, 2019
95b2bf1
Compile snapshot tests for iOS only
johnxnguyen Oct 2, 2019
eec775f
Specify Xcode 11 for CI
johnxnguyen Oct 2, 2019
af02d2a
Move snapshot tests into separate test target
johnxnguyen Oct 2, 2019
06d6bbe
Revert "Compile snapshot tests for iOS only"
johnxnguyen Oct 2, 2019
f06943f
Run snapshot tests on CI
johnxnguyen Oct 2, 2019
3caec5b
Fix travis config
johnxnguyen Oct 3, 2019
dd99de5
Fix travis config again
johnxnguyen Oct 3, 2019
d132285
Fix missing file error
johnxnguyen Oct 3, 2019
85c25ef
Re-record snapshots on iPhone 11
johnxnguyen Oct 3, 2019
6e59c22
Update travis config
johnxnguyen Oct 3, 2019
9949262
slather DownShapshotTests
johnxnguyen Oct 3, 2019
7975752
Provide explicit types in styler configuration
johnxnguyen Oct 4, 2019
9e8eac1
[Copyright] Update org name and years
iwasrobbed Oct 4, 2019
fd24ea9
[CI] Try using Codecov for merged reports
iwasrobbed Oct 4, 2019
ef8e685
[Travis] Try doing Codecov after each slather
iwasrobbed Oct 4, 2019
cc05978
[Xcode] Share DownSnapshotTests scheme w/ code coverage
iwasrobbed Oct 4, 2019
f2f003b
[CI] Use separate codecov report dirs
iwasrobbed Oct 4, 2019
a580178
[CI] Don't slather, just use codecov
iwasrobbed Oct 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
Carthage/
Pods/
.build/
.DS_Store
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -3,9 +3,9 @@ language: objective-c
before_install:
iwasrobbed marked this conversation as resolved.
Show resolved Hide resolved
- set -o pipefail
- gem install xcpretty slather -N
- xcrun simctl boot "iPhone 7" || echo "(Pre)Launched the simulator."
- xcrun simctl boot "iPhone Xs" || echo "(Pre)Launched the simulator."
script:
- travis_retry xcodebuild -project Down.xcodeproj -scheme "Down" -destination "platform=iOS Simulator,name=iPhone 7" -enableCodeCoverage YES ONLY_ACTIVE_ARCH=YES test | xcpretty -c
- travis_retry xcodebuild -project Down.xcodeproj -scheme "Down" -destination "platform=iOS Simulator,name=iPhone Xs" -enableCodeCoverage YES ONLY_ACTIVE_ARCH=YES test | xcpretty -c
- travis_retry xcodebuild -project Down.xcodeproj -scheme "Down" -sdk macosx -destination 'platform=OS X,arch=x86_64' -enableCodeCoverage YES test | xcpretty -c
- travis_retry xcodebuild -project Down.xcodeproj -scheme "Down" -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV' -enableCodeCoverage YES test | xcpretty -c
after_success:
Expand Down
1 change: 1 addition & 0 deletions Cartfile.private
@@ -0,0 +1 @@
github "pointfreeco/swift-snapshot-testing" ~> 1.5
1 change: 1 addition & 0 deletions Cartfile.resolved
@@ -0,0 +1 @@
github "pointfreeco/swift-snapshot-testing" "1.5.0"
iwasrobbed marked this conversation as resolved.
Show resolved Hide resolved
293 changes: 290 additions & 3 deletions Down.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Source/AST/Nodes/BaseNode.swift
Expand Up @@ -30,6 +30,17 @@ public class BaseNode: Node {

return result
}()

public lazy var nestDepth: Int = {
iwasrobbed marked this conversation as resolved.
Show resolved Hide resolved
var depth = 0
var next = cmarkNode.parent

while let current = next {
depth += current.type == cmarkNode.type ? 1 : 0
next = current.parent
}
return depth
}()

init(cmarkNode: CMarkNode) {
self.cmarkNode = cmarkNode
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/BlockQuote.swift
Expand Up @@ -13,6 +13,7 @@ public class BlockQuote: BaseNode {}
// MARK: - Debug

extension BlockQuote: CustomDebugStringConvertible {

public var debugDescription: String {
return "Block Quote"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Code.swift
Expand Up @@ -18,6 +18,7 @@ public class Code: BaseNode {
// MARK: - Debug

extension Code: CustomDebugStringConvertible {

public var debugDescription: String {
return "Code - \(literal ?? "nil")"
}
Expand Down
4 changes: 3 additions & 1 deletion Source/AST/Nodes/CodeBlock.swift
Expand Up @@ -31,7 +31,9 @@ public class CodeBlock: BaseNode {
// MARK: - Debug

extension CodeBlock: CustomDebugStringConvertible {

public var debugDescription: String {
return "Code Block - \(literal ?? "nil"), fenceInfo: \(fenceInfo ?? "nil")"
let content = (literal ?? "nil").replacingOccurrences(of: "\n", with: "\\n")
return "Code Block - fenceInfo: \(fenceInfo ?? "nil"), content: \(content)"
}
}
1 change: 1 addition & 0 deletions Source/AST/Nodes/CustomBlock.swift
Expand Up @@ -18,6 +18,7 @@ public class CustomBlock: BaseNode {
// MARK: - Debug

extension CustomBlock: CustomDebugStringConvertible {

public var debugDescription: String {
return "Custom Block - \(literal ?? "nil")"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/CustomInline.swift
Expand Up @@ -17,6 +17,7 @@ public class CustomInline: BaseNode {
// MARK: - Debug

extension CustomInline: CustomDebugStringConvertible {

public var debugDescription: String {
return "Custom Inline - \(literal ?? "nil")"
}
Expand Down
2 changes: 2 additions & 0 deletions Source/AST/Nodes/Document.swift
Expand Up @@ -16,6 +16,7 @@ public class Document: BaseNode {
}

/// 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 @@ -26,6 +27,7 @@ public class Document: BaseNode {
// MARK: - Debug

extension Document: CustomDebugStringConvertible {

public var debugDescription: String {
return "Document"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Emphasis.swift
Expand Up @@ -13,6 +13,7 @@ public class Emphasis: BaseNode {}
// MARK: - Debug

extension Emphasis: CustomDebugStringConvertible {

public var debugDescription: String {
return "Emphasis"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Heading.swift
Expand Up @@ -17,6 +17,7 @@ public class Heading: BaseNode {
// MARK: - Debug

extension Heading: CustomDebugStringConvertible {

public var debugDescription: String {
return "Heading - L\(headingLevel)"
}
Expand Down
4 changes: 3 additions & 1 deletion Source/AST/Nodes/HtmlBlock.swift
Expand Up @@ -18,7 +18,9 @@ public class HtmlBlock: BaseNode {
// MARK: - Debug

extension HtmlBlock: CustomDebugStringConvertible {

public var debugDescription: String {
return "Html Block - \(literal ?? "nil")"
let content = (literal ?? "nil").replacingOccurrences(of: "\n", with: "\\n")
return "Html Block - content: \(content)"
}
}
1 change: 1 addition & 0 deletions Source/AST/Nodes/HtmlInline.swift
Expand Up @@ -18,6 +18,7 @@ public class HtmlInline: BaseNode {
// MARK: - Debug

extension HtmlInline: CustomDebugStringConvertible {

public var debugDescription: String {
return "Html Inline - \(literal ?? "nil")"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Image.swift
Expand Up @@ -39,6 +39,7 @@ public class Image: BaseNode {
// MARK: - Debug

extension Image: CustomDebugStringConvertible {

public var debugDescription: String {
return "Image - title: \(title ?? "nil"), url: \(url ?? "nil"))"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Item.swift
Expand Up @@ -13,6 +13,7 @@ public class Item: BaseNode {}
// MARK: - Debug

extension Item: CustomDebugStringConvertible {

public var debugDescription: String {
return "Item"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/LineBreak.swift
Expand Up @@ -13,6 +13,7 @@ public class LineBreak: BaseNode {}
// MARK: - Debug

extension LineBreak: CustomDebugStringConvertible {

public var debugDescription: String {
return "Line Break"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Link.swift
Expand Up @@ -39,6 +39,7 @@ public class Link: BaseNode {
// MARK: - Debug

extension Link: CustomDebugStringConvertible {

public var debugDescription: String {
return "Link - title: \(title ?? "nil"), url: \(url ?? "nil"))"
}
Expand Down
44 changes: 23 additions & 21 deletions Source/AST/Nodes/List.swift
Expand Up @@ -9,18 +9,36 @@ import Foundation
import libcmark

public class List: BaseNode {

/// The type of the list, either bullet or ordered.
public lazy var listType: ListType = {
guard let type = ListType(cmarkNode: cmarkNode) else {
assertionFailure("Unsupported or missing list type. Defaulting to .bullet.")
return .bullet
}

return type
}()

public enum ListType: CustomDebugStringConvertible {
/// The number of items in the list.
public lazy var numberOfItems: Int = children.count
}

// MARK: - List Type

public extension List {

enum ListType: CustomDebugStringConvertible {
case bullet
case ordered(start: Int)

public var debugDescription: String {
switch self {
case .bullet: return "Bullet"
case .ordered(let start): return "Ordered (start: \(start)"
case .ordered(let start): return "Ordered (start: \(start))"
}
}

init?(cmarkNode: CMarkNode) {
switch cmarkNode.listType {
case CMARK_BULLET_LIST: self = .bullet
Expand All @@ -29,28 +47,12 @@ public class List: BaseNode {
}
}
}

///////////////////////////////////////////////////////////////////////////

/// The type of the list, either bullet or ordered.
public lazy var listType: ListType = {
guard let type = ListType(cmarkNode: cmarkNode) else {
assertionFailure("Unsupported or missing list type. Defaulting to .bullet.")
return .bullet
}

return type
}()

/// The number of items in the list.
public lazy var numberOfItems: Int = children.count

}


// MARK: - Debug

extension List: CustomDebugStringConvertible {

public var debugDescription: String {
return "List - type: \(listType)"
}
Expand Down
7 changes: 6 additions & 1 deletion Source/AST/Nodes/Node.swift
Expand Up @@ -57,7 +57,11 @@ public extension UnsafeMutablePointer where Pointee == cmark_node {
default: return nil
}
}


var parent: CMarkNode? {
return cmark_node_parent(self)
}

var type: cmark_node_type {
return cmark_node_get_type(self)
}
Expand Down Expand Up @@ -92,6 +96,7 @@ public extension UnsafeMutablePointer where Pointee == cmark_node {
}

private extension String {

init?(cString: UnsafePointer<Int8>?) {
guard let unwrapped = cString else { return nil }
let result = String(cString: unwrapped)
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Paragraph.swift
Expand Up @@ -13,6 +13,7 @@ public class Paragraph: BaseNode {}
// MARK: - Debug

extension Paragraph: CustomDebugStringConvertible {

public var debugDescription: String {
return "Paragraph"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/SoftBreak.swift
Expand Up @@ -13,6 +13,7 @@ public class SoftBreak: BaseNode {}
// MARK: - Debug

extension SoftBreak: CustomDebugStringConvertible {

public var debugDescription: String {
return "Soft Break"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Strong.swift
Expand Up @@ -13,6 +13,7 @@ public class Strong: BaseNode {}
// MARK: - Debug

extension Strong: CustomDebugStringConvertible {

public var debugDescription: String {
return "Strong"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/Text.swift
Expand Up @@ -18,6 +18,7 @@ public class Text: BaseNode {
// MARK: - Debug

extension Text: CustomDebugStringConvertible {

public var debugDescription: String {
return "Text - \(literal ?? "nil")"
}
Expand Down
1 change: 1 addition & 0 deletions Source/AST/Nodes/ThematicBreak.swift
Expand Up @@ -13,6 +13,7 @@ public class ThematicBreak: BaseNode {}
// MARK: - Debug

extension ThematicBreak: CustomDebugStringConvertible {

public var debugDescription: String {
return "Thematic Break"
}
Expand Down
40 changes: 0 additions & 40 deletions Source/AST/Stylers/Styler.swift

This file was deleted.

34 changes: 34 additions & 0 deletions Source/AST/Styling/Attribute Collections/ColorCollection.swift
@@ -0,0 +1,34 @@
//
// ColorCollection.swift
// Down
//
// Created by John Nguyen on 27.07.19.
// Copyright © 2019 Glazed Donut, LLC. All rights reserved.
//

#if canImport(UIKit)

import UIKit
public typealias DownColor = UIColor

#elseif canImport(AppKit)

import AppKit
public typealias DownColor = NSColor

#endif

public struct ColorCollection {

public var heading1 = DownColor.black
public var heading2 = DownColor.black
public var heading3 = DownColor.black
public var body = DownColor.black
public var code = DownColor.black
public var link = DownColor.systemBlue
public var quote = DownColor.darkGray
public var quoteStripe = DownColor.darkGray
public var thematicBreak = DownColor(white: 0.9, alpha: 1)
public var listItemPrefix = DownColor.lightGray
public var codeBlockBackground = DownColor(red: 0.96, green: 0.97, blue: 0.98, alpha: 1)
iwasrobbed marked this conversation as resolved.
Show resolved Hide resolved
}