Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Aztec.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
59FEA0751D8BDFA700D138DF /* NodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FEA0661D8BDFA700D138DF /* NodeTests.swift */; };
59FEA0781D8BDFA700D138DF /* HTMLToAttributedStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FEA06A1D8BDFA700D138DF /* HTMLToAttributedStringTests.swift */; };
59FEA07A1D8BDFA700D138DF /* InHTMLConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FEA06C1D8BDFA700D138DF /* InHTMLConverterTests.swift */; };
B542D6421E9EB122009D12D3 /* PreFormaterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B542D6411E9EB122009D12D3 /* PreFormaterTests.swift */; };
B551A4A01E770B3800EE3A7F /* UIFont+Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = B551A49F1E770B3800EE3A7F /* UIFont+Emoji.swift */; };
B572AC281E817CFE008948C2 /* CommentAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B572AC271E817CFE008948C2 /* CommentAttachment.swift */; };
B577DC651E7B18E90012A1F8 /* NodeDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B577DC641E7B18E90012A1F8 /* NodeDescriptor.swift */; };
Expand Down Expand Up @@ -184,6 +185,7 @@
59FEA06B1D8BDFA700D138DF /* InAttributeConverterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InAttributeConverterTests.swift; sourceTree = "<group>"; };
59FEA06C1D8BDFA700D138DF /* InHTMLConverterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InHTMLConverterTests.swift; sourceTree = "<group>"; };
59FEA06D1D8BDFA700D138DF /* InNodeConverterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InNodeConverterTests.swift; sourceTree = "<group>"; };
B542D6411E9EB122009D12D3 /* PreFormaterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreFormaterTests.swift; sourceTree = "<group>"; };
B551A49F1E770B3800EE3A7F /* UIFont+Emoji.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+Emoji.swift"; sourceTree = "<group>"; };
B572AC271E817CFE008948C2 /* CommentAttachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommentAttachment.swift; sourceTree = "<group>"; };
B577DC641E7B18E90012A1F8 /* NodeDescriptor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NodeDescriptor.swift; path = Descriptors/NodeDescriptor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -567,6 +569,7 @@
B5E607321DA56EC700C8A389 /* TextListFormatterTests.swift */,
E11B775F1DBA14B40024E455 /* BlockquoteFormatterTests.swift */,
FFD436971E3180A500A0E26F /* FontFormatterTests.swift */,
B542D6411E9EB122009D12D3 /* PreFormaterTests.swift */,
);
path = Formatters;
sourceTree = "<group>";
Expand Down Expand Up @@ -863,6 +866,7 @@
599F25951D8BDCFC002871D6 /* TextViewTests.swift in Sources */,
594C9D711D8BE6B800D74542 /* OutAttributeConverterTests.swift in Sources */,
59FEA06F1D8BDFA700D138DF /* OutHTMLConverterTests.swift in Sources */,
B542D6421E9EB122009D12D3 /* PreFormaterTests.swift in Sources */,
599F25941D8BDCFC002871D6 /* TextStorageTests.swift in Sources */,
59FEA0741D8BDFA700D138DF /* ElementNodeTests.swift in Sources */,
B5BC4FF21DA2D17000614582 /* NSAttributedStringListsTests.swift in Sources */,
Expand Down
13 changes: 8 additions & 5 deletions Aztec/Classes/Formatters/PreFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open class PreFormatter: ParagraphAttributeFormatter {
let monospaceFont: UIFont
let placeholderAttributes: [String : Any]?

init(monospaceFont: UIFont = UIFont(descriptor:UIFontDescriptor(name: "Courier", size: 12), size:12) ,placeholderAttributes: [String : Any]? = nil) {
init(monospaceFont: UIFont = UIFont(descriptor:UIFontDescriptor(name: "Courier", size: 12), size:12), placeholderAttributes: [String : Any]? = nil) {
self.monospaceFont = monospaceFont
self.placeholderAttributes = placeholderAttributes
}
Expand All @@ -21,11 +21,14 @@ open class PreFormatter: ParagraphAttributeFormatter {
return resultingAttributes
}

func remove(from attributes:[String: Any]) -> [String: Any] {
var resultingAttributes = attributes
func remove(from attributes: [String: Any]) -> [String: Any] {
guard let placeholderAttributes = placeholderAttributes else {
return attributes
}

if let attributes = placeholderAttributes {
resultingAttributes = attributes
var resultingAttributes = attributes
for (key, value) in placeholderAttributes {
resultingAttributes[key] = value
}

return resultingAttributes
Expand Down
3 changes: 3 additions & 0 deletions AztecTests/Formatters/BlockquoteFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import XCTest
import Gridicons
@testable import Aztec

// MARK: - BlockquoteFormatterTests Tests
//
class BlockquoteFormatterTests: XCTestCase {

func testApplyingBlockquoteOnFirstParagraph() {
let textView = testTextView
let storage = textView.storage
Expand Down
31 changes: 31 additions & 0 deletions AztecTests/Formatters/PreFormaterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import XCTest
import Gridicons
@testable import Aztec


// MARK: - PreFormatterTests Tests
//
class PreFormatterTests: XCTestCase {

/// Verifies that the PreFormatter is not interacting with NSTextAttachment Attributes, that are unrelated
/// to the formatter's behavior.
///
func testPreFormatterDoesNotLooseAttachmentAttribuesOnRemove() {
let placeholderAttributes: [String: Any] = [
NSFontAttributeName: "Value",
NSParagraphStyleAttributeName: NSParagraphStyle()
]

let stringAttributes: [String: Any] = [
NSAttachmentAttributeName: NSTextAttachment(),
]

let formatter = PreFormatter(placeholderAttributes: placeholderAttributes)
let updated = formatter.remove(from: stringAttributes)

let expectedValue = stringAttributes[NSAttachmentAttributeName] as! NSTextAttachment
let updatedValue = updated[NSAttachmentAttributeName] as! NSTextAttachment

XCTAssert(updatedValue == expectedValue)
}
}
4 changes: 2 additions & 2 deletions AztecTests/Formatters/TextListFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import XCTest

// MARK: - TextListFormatter Tests
//
class TextListFormatterTests: XCTestCase
{
class TextListFormatterTests: XCTestCase {
// Helpers #1:
// ===========
//
Expand Down