├── .gitignore ├── .travis.yml ├── Attributed.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── Attributed.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── WorkspaceSettings.xcsettings ├── xcshareddata │ └── xcschemes │ │ └── Attributed.xcscheme └── project.pbxproj ├── Package.swift ├── Attributed.podspec ├── AttributedTests ├── Info.plist └── AttributedTests.swift ├── Attributed ├── Info.plist ├── Attributed.h ├── MarkupElement.swift ├── SmallCaps.swift ├── Parse.swift ├── UIFont.swift ├── Modifiers.swift └── Modifier.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata 3 | *.xccheckout 4 | *.xcscmblueprint 5 | build 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: swift 2 | osx_image: xcode11.2 3 | xcode_project: Attributed.xcodeproj 4 | xcode_scheme: Attributed 5 | xcode_sdk: iphonesimulator 6 | xcode_destination: platform=iOS Simulator,OS=latest,name=iPhone 8 -------------------------------------------------------------------------------- /Attributed.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Attributed.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Attributed.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Attributed.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "Attributed", 6 | platforms: [ 7 | .iOS(.v9), .tvOS(.v9), .watchOS(.v2) 8 | ], 9 | products: [ 10 | .library(name: "Attributed", targets: ["Attributed"]) 11 | ], 12 | targets: [ 13 | .target( 14 | name: "Attributed", 15 | path: "Attributed" 16 | ), 17 | .testTarget( 18 | name: "AttributedTests", 19 | dependencies: ["Attributed"], 20 | path: "AttributedTests" 21 | ), 22 | ], 23 | swiftLanguageVersions: [.v5] 24 | ) 25 | -------------------------------------------------------------------------------- /Attributed.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "Attributed" 3 | s.version = "9.0.0" 4 | s.summary = "Convert XML to an NSAttributedString." 5 | s.author = 'Hilton Campbell' 6 | s.homepage = "https://github.com/CrossWaterBridge/Attributed" 7 | s.license = { :type => 'MIT', :file => 'LICENSE' } 8 | s.source = { :git => "https://github.com/CrossWaterBridge/Attributed.git", :tag => s.version.to_s } 9 | s.ios.deployment_target = '9.0' 10 | s.tvos.deployment_target = '9.0' 11 | s.watchos.deployment_target = '2.0' 12 | s.swift_version = '5.0' 13 | s.source_files = 'Attributed/*.swift' 14 | s.framework = 'UIKit' 15 | s.requires_arc = true 16 | end 17 | -------------------------------------------------------------------------------- /AttributedTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Attributed/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Hilton Campbell 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Attributed 2 | 3 | [![Pod Version](https://img.shields.io/cocoapods/v/Attributed.svg)](Attributed.podspec) 4 | [![Pod License](https://img.shields.io/cocoapods/l/Attributed.svg)](LICENSE) 5 | [![Pod Platform](https://img.shields.io/cocoapods/p/Attributed.svg)](Attributed.podspec) 6 | [![Build Status](https://img.shields.io/travis/CrossWaterBridge/Attributed.svg?branch=master)](https://travis-ci.org/CrossWaterBridge/Attributed) 7 | 8 | Convert HTML or XML to an NSAttributedString. 9 | 10 | ### Installation 11 | 12 | Install with CocoaPods by adding the following to your Podfile: 13 | 14 | ```ruby 15 | use_frameworks! 16 | 17 | pod 'Attributed' 18 | ``` 19 | 20 | Then run: 21 | 22 | ```bash 23 | pod install 24 | ``` 25 | 26 | ### Usage 27 | 28 | ```swift 29 | import Attributed 30 | 31 | let html = "Waltz, bad nymph, for quick jigs vex." 32 | 33 | let baseFont = UIFont.preferredFont(forTextStyle: .body) 34 | let modifier = modifierWithBaseAttributes([.font: baseFont], modifiers: [ 35 | selectMap("em", Modifiers.italic), 36 | selectMap("span.bold", Modifiers.bold), 37 | ]) 38 | 39 | let attributedString = NSAttributedString.attributedStringFromMarkup(html, withModifier: modifier) 40 | ``` 41 | 42 | ### License 43 | 44 | Attributed is released under the MIT license. See LICENSE for details. 45 | -------------------------------------------------------------------------------- /Attributed/Attributed.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | #import 24 | 25 | FOUNDATION_EXPORT double AttributedVersionNumber; 26 | FOUNDATION_EXPORT const unsigned char AttributedVersionString[]; 27 | -------------------------------------------------------------------------------- /Attributed/MarkupElement.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import Foundation 24 | 25 | public struct MarkupElement { 26 | public let name: String 27 | public let attributes: [String: String] 28 | 29 | public init(name: String, attributes: [String: String]) { 30 | self.name = name 31 | self.attributes = attributes 32 | } 33 | } 34 | 35 | public func ~= (pattern: String, element: MarkupElement) -> Bool { 36 | let scanner = Scanner(string: pattern) 37 | scanner.charactersToBeSkipped = nil 38 | 39 | var name: NSString? 40 | if scanner.scanUpTo(".", into: &name), let name = name as String?, name == element.name { 41 | if scanner.scanString(".", into: nil) { 42 | var className: NSString? 43 | if scanner.scanUpTo("", into: &className), let className = className as String?, let elementClassName = element.attributes["class"], elementClassName == className { 44 | return true 45 | } 46 | } else { 47 | return true 48 | } 49 | } 50 | 51 | return false 52 | } 53 | -------------------------------------------------------------------------------- /Attributed/SmallCaps.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import UIKit 24 | 25 | extension NSMutableAttributedString { 26 | public func simulateSmallCapsInRange(_ range: NSRange, withFont font: UIFont, attributes: [NSAttributedString.Key: Any]) { 27 | let replacement = NSMutableAttributedString() 28 | 29 | var smallAttributes = attributes 30 | smallAttributes[.font] = font.withSize(ceil(font.pointSize * 1.1 * font.xHeight / font.capHeight)) 31 | 32 | let lowercaseCharacterSet = CharacterSet.lowercaseLetters 33 | 34 | let scanner = Scanner(string: attributedSubstring(from: range).string) 35 | scanner.charactersToBeSkipped = nil 36 | while !scanner.isAtEnd { 37 | var value: NSString? 38 | if scanner.scanCharacters(from: lowercaseCharacterSet, into: &value), let value = value { 39 | replacement.append(NSAttributedString(string: value.uppercased, attributes: smallAttributes)) 40 | } 41 | if scanner.scanUpToCharacters(from: lowercaseCharacterSet, into: &value), let value = value { 42 | replacement.append(NSAttributedString(string: value as String, attributes: attributes)) 43 | } 44 | } 45 | 46 | replaceCharacters(in: range, with: replacement) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Attributed/Parse.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import Foundation 24 | 25 | extension NSAttributedString { 26 | public static func attributedStringFromMarkup(_ markup: String, withModifier modifier: @escaping Modifier) -> NSAttributedString? { 27 | if let data = "\(markup)".data(using: .utf8) { 28 | let parser = XMLParser(data: data) 29 | let parserDelegate = ParserDelegate(modifier: modifier) 30 | parser.delegate = parserDelegate 31 | parser.parse() 32 | return parserDelegate.result 33 | } else { 34 | return nil 35 | } 36 | } 37 | } 38 | 39 | private class ParserDelegate: NSObject, XMLParserDelegate { 40 | let result = NSMutableAttributedString() 41 | 42 | let modifier: Modifier 43 | 44 | var lastIndex = 0 45 | var stack = [MarkupElement]() 46 | 47 | init(modifier: @escaping Modifier) { 48 | self.modifier = modifier 49 | } 50 | 51 | @objc func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) { 52 | let range = NSMakeRange(lastIndex, result.length - lastIndex) 53 | let startElement = MarkupElement(name: elementName, attributes: attributeDict) 54 | modify(in: range, startElement: startElement, endElement: nil) 55 | 56 | lastIndex = result.length 57 | stack.append(startElement) 58 | } 59 | 60 | @objc func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { 61 | let range = NSMakeRange(lastIndex, result.length - lastIndex) 62 | let endElement = stack.last 63 | modify(in: range, startElement: nil, endElement: endElement) 64 | 65 | lastIndex = result.length 66 | stack.removeLast() 67 | } 68 | 69 | @objc func parser(_ parser: XMLParser, foundCharacters string: String) { 70 | result.append(NSAttributedString(string: string)) 71 | } 72 | 73 | func modify(in range: NSRange, startElement: MarkupElement?, endElement: MarkupElement?) { 74 | if !stack.isEmpty { 75 | let state = State(mutableAttributedString: result, range: range, stack: Array(stack[1.. 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Attributed/UIFont.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import UIKit 24 | 25 | extension UIFont { 26 | func fontWithRegular() -> UIFont { 27 | return fontDescriptor.withSymbolicTraits(fontDescriptor.symbolicTraits.subtracting(.traitBold)).flatMap { UIFont(descriptor: $0, size: pointSize) } ?? self 28 | } 29 | 30 | func fontWithBold() -> UIFont { 31 | return fontDescriptor.withSymbolicTraits(fontDescriptor.symbolicTraits.union(.traitBold)).flatMap { UIFont(descriptor: $0, size: pointSize) } ?? self 32 | } 33 | 34 | func fontWithItalic() -> UIFont { 35 | return fontDescriptor.withSymbolicTraits(fontDescriptor.symbolicTraits.union(.traitItalic)).flatMap { UIFont(descriptor: $0, size: pointSize) } ?? self 36 | } 37 | 38 | func fontWithMonospacedNumbers() -> UIFont { 39 | #if os(watchOS) 40 | return UIFont.monospacedDigitSystemFont(ofSize: pointSize, weight: UIFont.Weight(rawValue: 0)) 41 | #else 42 | if #available(iOS 9.0, *) { 43 | return UIFont.monospacedDigitSystemFont(ofSize: pointSize, weight: UIFont.Weight(rawValue: 0)) 44 | } else { 45 | return UIFont(descriptor: fontDescriptor.addingAttributes([ 46 | UIFontDescriptor.AttributeName.featureSettings: [ 47 | [ 48 | UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType, 49 | UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector, 50 | ], 51 | ], 52 | ]), size: pointSize) 53 | } 54 | #endif 55 | } 56 | 57 | var supportsSmallCaps: Bool { 58 | #if os(iOS) 59 | for feature in CTFontCopyFeatures(self) as NSArray? as? [[String: AnyObject]] ?? [] where feature[kCTFontFeatureTypeIdentifierKey as String] as? Int == kLowerCaseType { 60 | for featureSelector in feature[kCTFontFeatureTypeSelectorsKey as String] as? [[String: AnyObject]] ?? [] where featureSelector[kCTFontFeatureSelectorIdentifierKey as String] as? Int == kLowerCaseSmallCapsSelector { 61 | return true 62 | } 63 | } 64 | #endif 65 | 66 | return false 67 | } 68 | 69 | func fontWithSmallCaps() -> UIFont? { 70 | #if os(iOS) 71 | return UIFont(descriptor: fontDescriptor.addingAttributes([ 72 | UIFontDescriptor.AttributeName.featureSettings: [ 73 | [ 74 | UIFontDescriptor.FeatureKey.featureIdentifier: kLowerCaseType, 75 | UIFontDescriptor.FeatureKey.typeIdentifier: kLowerCaseSmallCapsSelector, 76 | ], 77 | ], 78 | ]), size: pointSize) 79 | #else 80 | return nil 81 | #endif 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Attributed/Modifiers.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import UIKit 24 | 25 | public enum Modifiers { 26 | public static func regular(_ attributedString: NSAttributedString) -> NSAttributedString { 27 | guard attributedString.length > 0, 28 | let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 29 | 30 | if let font = attributedString.attributes(at: 0, effectiveRange: nil)[.font] as? UIFont { 31 | let range = NSMakeRange(0, attributedString.length) 32 | result.addAttribute(.font, value: font.fontWithRegular(), range: range) 33 | } 34 | return result 35 | } 36 | 37 | public static func bold(_ attributedString: NSAttributedString) -> NSAttributedString { 38 | guard attributedString.length > 0, 39 | let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 40 | 41 | if let font = attributedString.attributes(at: 0, effectiveRange: nil)[.font] as? UIFont { 42 | let range = NSMakeRange(0, attributedString.length) 43 | result.addAttribute(.font, value: font.fontWithBold(), range: range) 44 | } 45 | return result 46 | } 47 | 48 | public static func italic(_ attributedString: NSAttributedString) -> NSAttributedString { 49 | guard attributedString.length > 0, 50 | let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 51 | 52 | if let font = attributedString.attributes(at: 0, effectiveRange: nil)[.font] as? UIFont { 53 | let range = NSMakeRange(0, attributedString.length) 54 | result.addAttribute(.font, value: font.fontWithItalic(), range: range) 55 | } 56 | return result 57 | } 58 | 59 | public static func monospacedNumbers(_ attributedString: NSAttributedString) -> NSAttributedString { 60 | guard attributedString.length > 0, 61 | let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 62 | 63 | if let font = attributedString.attributes(at: 0, effectiveRange: nil)[.font] as? UIFont { 64 | let range = NSMakeRange(0, attributedString.length) 65 | result.addAttribute(.font, value: font.fontWithMonospacedNumbers(), range: range) 66 | } 67 | return result 68 | } 69 | 70 | public static func smallCaps(_ attributedString: NSAttributedString) -> NSAttributedString { 71 | guard attributedString.length > 0, 72 | let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 73 | 74 | let attributes = attributedString.attributes(at: 0, effectiveRange: nil) 75 | if let font = attributes[.font] as? UIFont { 76 | let range = NSMakeRange(0, attributedString.length) 77 | if font.supportsSmallCaps, let smallCapsFont = font.fontWithSmallCaps() { 78 | result.addAttribute(.font, value: smallCapsFont, range: range) 79 | } else { 80 | result.simulateSmallCapsInRange(range, withFont: font, attributes: attributes) 81 | } 82 | } 83 | return result 84 | } 85 | 86 | public static func para(_ context: NSAttributedString, _ attributedString: NSAttributedString) -> NSAttributedString { 87 | guard let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 88 | 89 | result.insert(NSAttributedString(string: "\n", attributes: context.attributes(at: context.length - 1, effectiveRange: nil)), at: attributedString.length) 90 | return result 91 | } 92 | 93 | public static func lineBreak(_ context: NSAttributedString, attributedString: NSAttributedString) -> NSAttributedString { 94 | return NSAttributedString(string: "\n", attributes: context.attributes(at: context.length - 1, effectiveRange: nil)) 95 | } 96 | 97 | public static func link(urlAttributeName: String = "href") -> MapWithElement { 98 | return { element, attributedString in 99 | guard attributedString.length > 0, 100 | let result = attributedString.mutableCopy() as? NSMutableAttributedString, 101 | let href = element.attributes[urlAttributeName], 102 | let url = URL(string: href) else { return attributedString } 103 | 104 | let range = NSMakeRange(0, attributedString.length) 105 | result.addAttribute(.link, value: url, range: range) 106 | return result 107 | } 108 | } 109 | } 110 | 111 | private let widontRegex = try! NSRegularExpression(pattern: "\\S(\\s+)\\S+\\s*$", options: .anchorsMatchLines) 112 | 113 | extension Modifiers { 114 | public static func widont(_ attributedString: NSAttributedString) -> NSAttributedString { 115 | guard let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 116 | 117 | let string = result.string 118 | for match in widontRegex.matches(in: string, range: NSRange(location: 0, length: string.utf16.count)).reversed() { 119 | result.replaceCharacters(in: match.range(at: 1), with: "\u{00a0}") 120 | } 121 | return result 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Attributed/Modifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import Foundation 24 | 25 | public struct State { 26 | public var mutableAttributedString: NSMutableAttributedString 27 | public var range: NSRange 28 | public var stack: [MarkupElement] 29 | public var startElement: MarkupElement? 30 | public var endElement: MarkupElement? 31 | } 32 | 33 | public typealias Modifier = (_ state: State) -> Void 34 | 35 | public func modifierWithBaseAttributes(_ attributes: [NSAttributedString.Key: Any], modifiers: [Modifier]) -> Modifier { 36 | return { state in 37 | state.mutableAttributedString.addAttributes(attributes, range: state.range) 38 | 39 | for count in 0...state.stack.count { 40 | let localStack = Array(state.stack[0.. NSAttributedString 51 | 52 | public func selectMap(_ selector: String, _ map: @escaping Map) -> Modifier { 53 | return { state in 54 | guard let element = state.stack.last, selector ~= element else { return } 55 | 56 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 57 | state.mutableAttributedString.replaceCharacters(in: state.range, with: map(attributedString)) 58 | } 59 | } 60 | 61 | public func selectMapBefore(_ selector: String, _ map: @escaping Map) -> Modifier { 62 | return { state in 63 | guard let element = state.startElement, selector ~= element else { return } 64 | 65 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 66 | state.mutableAttributedString.replaceCharacters(in: state.range, with: map(attributedString)) 67 | } 68 | } 69 | 70 | public func selectMapAfter(_ selector: String, _ map: @escaping Map) -> Modifier { 71 | return { state in 72 | guard let element = state.endElement, state.stack.isEmpty, selector ~= element else { return } 73 | 74 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 75 | state.mutableAttributedString.replaceCharacters(in: state.range, with: map(attributedString)) 76 | } 77 | } 78 | 79 | public typealias MapWithContext = (NSAttributedString, NSAttributedString) -> NSAttributedString 80 | 81 | public func selectMap(_ selector: String, _ mapWithContext: @escaping MapWithContext) -> Modifier { 82 | return { state in 83 | guard let element = state.stack.last, selector ~= element else { return } 84 | 85 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 86 | state.mutableAttributedString.replaceCharacters(in: state.range, with: mapWithContext(state.mutableAttributedString, attributedString)) 87 | } 88 | } 89 | 90 | public func selectMapBefore(_ selector: String, _ mapWithContext: @escaping MapWithContext) -> Modifier { 91 | return { state in 92 | guard let element = state.startElement, selector ~= element else { return } 93 | 94 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 95 | state.mutableAttributedString.replaceCharacters(in: state.range, with: mapWithContext(state.mutableAttributedString, attributedString)) 96 | } 97 | } 98 | 99 | public func selectMapAfter(_ selector: String, _ mapWithContext: @escaping MapWithContext) -> Modifier { 100 | return { state in 101 | guard let element = state.endElement, state.stack.isEmpty, selector ~= element else { return } 102 | 103 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 104 | state.mutableAttributedString.replaceCharacters(in: state.range, with: mapWithContext(state.mutableAttributedString, attributedString)) 105 | } 106 | } 107 | 108 | public typealias MapWithElement = (MarkupElement, NSAttributedString) -> NSAttributedString 109 | 110 | public func selectMap(_ selector: String, _ mapWithElement: @escaping MapWithElement) -> Modifier { 111 | return { state in 112 | guard let element = state.stack.last, selector ~= element else { return } 113 | 114 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 115 | state.mutableAttributedString.replaceCharacters(in: state.range, with: mapWithElement(element, attributedString)) 116 | } 117 | } 118 | 119 | public func selectMapBefore(_ selector: String, _ mapWithElement: @escaping MapWithElement) -> Modifier { 120 | return { state in 121 | guard let element = state.startElement, selector ~= element else { return } 122 | 123 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 124 | state.mutableAttributedString.replaceCharacters(in: state.range, with: mapWithElement(element, attributedString)) 125 | } 126 | } 127 | 128 | public func selectMapAfter(_ selector: String, _ mapWithElement: @escaping MapWithElement) -> Modifier { 129 | return { state in 130 | guard let element = state.endElement, state.stack.isEmpty, selector ~= element else { return } 131 | 132 | let attributedString = state.mutableAttributedString.attributedSubstring(from: state.range) 133 | state.mutableAttributedString.replaceCharacters(in: state.range, with: mapWithElement(element, attributedString)) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /AttributedTests/AttributedTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2015 Hilton Campbell 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | // 22 | 23 | import XCTest 24 | import Attributed 25 | 26 | private let baseFont = UIFont.systemFont(ofSize: 10) 27 | private let boldFont = UIFont.boldSystemFont(ofSize: 10) 28 | private let modifier: Modifier = modifierWithBaseAttributes([.font: baseFont], modifiers: [ 29 | selectMap("regular", Modifiers.regular), 30 | selectMap("strong", Modifiers.bold), 31 | selectMap("p", Modifiers.para), 32 | selectMap("br", Modifiers.lineBreak), 33 | selectMapBefore("before", TestModifiers.marker), 34 | selectMapAfter("after", TestModifiers.marker), 35 | selectMap("widont", Modifiers.widont), 36 | selectMap("a", Modifiers.link()) 37 | ]) 38 | 39 | private enum TestModifiers { 40 | static func marker(_ context: NSAttributedString, _ attributedString: NSAttributedString) -> NSAttributedString { 41 | guard context.length > 0, 42 | let result = attributedString.mutableCopy() as? NSMutableAttributedString else { return attributedString } 43 | 44 | result.insert(NSAttributedString(string: "\n", attributes: context.attributes(at: context.length - 1, effectiveRange: nil)), at: attributedString.length) 45 | return result 46 | } 47 | } 48 | 49 | class AttributedTests: XCTestCase { 50 | func testEmpty() { 51 | let actual = NSAttributedString.attributedStringFromMarkup("", withModifier: modifier) 52 | let expected = NSAttributedString() 53 | XCTAssertEqual(actual, expected) 54 | } 55 | 56 | func testPlainText() { 57 | let actual = NSAttributedString.attributedStringFromMarkup("puppy", withModifier: modifier) 58 | let expected = NSAttributedString(string: "puppy", attributes: [.font: baseFont]) 59 | XCTAssertEqual(actual, expected) 60 | } 61 | 62 | func testElement() { 63 | let actual = NSAttributedString.attributedStringFromMarkup("kittens and puppies", withModifier: modifier) 64 | let expected = NSMutableAttributedString(string: "kittens ", attributes: [.font: baseFont]) 65 | expected.append(NSAttributedString(string: "and", attributes: [.font: boldFont])) 66 | expected.append(NSAttributedString(string: " puppies", attributes: [.font: baseFont])) 67 | XCTAssertEqual(actual, expected) 68 | } 69 | 70 | func testPara() { 71 | let actual = NSAttributedString.attributedStringFromMarkup("

kittens

puppies", withModifier: modifier) 72 | let expected = NSAttributedString(string: "kittens\npuppies", attributes: [.font: baseFont]) 73 | XCTAssertEqual(actual, expected) 74 | } 75 | 76 | func testLineBreak() { 77 | let actual = NSAttributedString.attributedStringFromMarkup("kittens
puppies", withModifier: modifier) 78 | let expected = NSAttributedString(string: "kittens\npuppies", attributes: [.font: baseFont]) 79 | XCTAssertEqual(actual, expected) 80 | } 81 | 82 | func testBefore() { 83 | let actual = NSAttributedString.attributedStringFromMarkup("bunnieskittenspuppies", withModifier: modifier) 84 | let expected = NSAttributedString(string: "bunnies\nkittenspuppies", attributes: [.font: baseFont]) 85 | XCTAssertEqual(actual, expected) 86 | } 87 | 88 | func testNestedBefore() { 89 | let actual = NSAttributedString.attributedStringFromMarkup("bunniescats and kittenspuppies", withModifier: modifier) 90 | let expected = NSMutableAttributedString(string: "bunnies\ncats ", attributes: [.font: baseFont]) 91 | expected.append(NSAttributedString(string: "and", attributes: [.font: boldFont])) 92 | expected.append(NSAttributedString(string: " kittenspuppies", attributes: [.font: baseFont])) 93 | XCTAssertEqual(actual, expected) 94 | } 95 | 96 | func testAfter() { 97 | let actual = NSAttributedString.attributedStringFromMarkup("bunnieskittenspuppies", withModifier: modifier) 98 | let expected = NSAttributedString(string: "bunnieskittens\npuppies", attributes: [.font: baseFont]) 99 | XCTAssertEqual(actual, expected) 100 | } 101 | 102 | func testNestedAfter() { 103 | let actual = NSAttributedString.attributedStringFromMarkup("bunniescats and kittenspuppies", withModifier: modifier) 104 | let expected = NSMutableAttributedString(string: "bunniescats ", attributes: [.font: baseFont]) 105 | expected.append(NSAttributedString(string: "and", attributes: [.font: boldFont])) 106 | expected.append(NSAttributedString(string: " kittens\npuppies", attributes: [.font: baseFont])) 107 | XCTAssertEqual(actual, expected) 108 | } 109 | 110 | func testOrder() { 111 | let actual = NSAttributedString.attributedStringFromMarkup("kittenspuppies", withModifier: modifier) 112 | let expected = NSMutableAttributedString(string: "kittens", attributes: [.font: boldFont]) 113 | expected.append(NSAttributedString(string: "puppies", attributes: [.font: baseFont])) 114 | XCTAssertEqual(actual, expected) 115 | } 116 | 117 | func testWidont() { 118 | let actual = NSAttributedString.attributedStringFromMarkup("

bunnies, kittens, and puppies

", withModifier: modifier) 119 | let expected = NSAttributedString(string: "bunnies, kittens, and\u{00a0}puppies\n", attributes: [.font: baseFont]) 120 | XCTAssertEqual(actual, expected) 121 | } 122 | 123 | func testLink() { 124 | let actual = NSAttributedString.attributedStringFromMarkup(#"bunnies, kittens, and puppies"#, withModifier: modifier) 125 | let expected = NSMutableAttributedString(string: "bunnies, ", attributes: [.font: baseFont]) 126 | expected.append(NSAttributedString(string: "kittens", attributes: [.font: baseFont, .link: URL(string: "https://www.apple.com/")!])) 127 | expected.append(NSAttributedString(string: ", and puppies", attributes: [.font: baseFont])) 128 | XCTAssertEqual(actual, expected) 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /Attributed.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D98DCCAA1C17BAE2004BFDB8 /* Attributed.h in Headers */ = {isa = PBXBuildFile; fileRef = D98DCCA91C17BAE2004BFDB8 /* Attributed.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | D98DCCB11C17BAE2004BFDB8 /* Attributed.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D98DCCA61C17BAE2004BFDB8 /* Attributed.framework */; }; 12 | D98DCCB61C17BAE2004BFDB8 /* AttributedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D98DCCB51C17BAE2004BFDB8 /* AttributedTests.swift */; }; 13 | D98DCCC11C17BC11004BFDB8 /* Parse.swift in Sources */ = {isa = PBXBuildFile; fileRef = D98DCCC01C17BC11004BFDB8 /* Parse.swift */; }; 14 | D98DCCC31C17BC18004BFDB8 /* SmallCaps.swift in Sources */ = {isa = PBXBuildFile; fileRef = D98DCCC21C17BC18004BFDB8 /* SmallCaps.swift */; }; 15 | D98DCCC51C18A514004BFDB8 /* Modifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D98DCCC41C18A514004BFDB8 /* Modifier.swift */; }; 16 | D98DCCC71C18A6E2004BFDB8 /* UIFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = D98DCCC61C18A6E2004BFDB8 /* UIFont.swift */; }; 17 | D98DCCC91C18A805004BFDB8 /* MarkupElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = D98DCCC81C18A805004BFDB8 /* MarkupElement.swift */; }; 18 | D994817521A0FA7A0059E516 /* Modifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D994817421A0FA7A0059E516 /* Modifiers.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | D98DCCB21C17BAE2004BFDB8 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = D98DCC9D1C17BAE2004BFDB8 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = D98DCCA51C17BAE2004BFDB8; 27 | remoteInfo = Attributed; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | D98DCCA61C17BAE2004BFDB8 /* Attributed.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Attributed.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | D98DCCA91C17BAE2004BFDB8 /* Attributed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Attributed.h; sourceTree = ""; }; 34 | D98DCCAB1C17BAE2004BFDB8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | D98DCCB01C17BAE2004BFDB8 /* AttributedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AttributedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | D98DCCB51C17BAE2004BFDB8 /* AttributedTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedTests.swift; sourceTree = ""; }; 37 | D98DCCB71C17BAE2004BFDB8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | D98DCCC01C17BC11004BFDB8 /* Parse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parse.swift; sourceTree = ""; }; 39 | D98DCCC21C17BC18004BFDB8 /* SmallCaps.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SmallCaps.swift; sourceTree = ""; }; 40 | D98DCCC41C18A514004BFDB8 /* Modifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Modifier.swift; sourceTree = ""; }; 41 | D98DCCC61C18A6E2004BFDB8 /* UIFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIFont.swift; sourceTree = ""; }; 42 | D98DCCC81C18A805004BFDB8 /* MarkupElement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarkupElement.swift; sourceTree = ""; }; 43 | D994817421A0FA7A0059E516 /* Modifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modifiers.swift; sourceTree = ""; }; 44 | /* End PBXFileReference section */ 45 | 46 | /* Begin PBXFrameworksBuildPhase section */ 47 | D98DCCA21C17BAE2004BFDB8 /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | D98DCCAD1C17BAE2004BFDB8 /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | D98DCCB11C17BAE2004BFDB8 /* Attributed.framework in Frameworks */, 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | D98DCC9C1C17BAE2004BFDB8 = { 66 | isa = PBXGroup; 67 | children = ( 68 | D98DCCA81C17BAE2004BFDB8 /* Attributed */, 69 | D98DCCB41C17BAE2004BFDB8 /* AttributedTests */, 70 | D98DCCA71C17BAE2004BFDB8 /* Products */, 71 | ); 72 | sourceTree = ""; 73 | }; 74 | D98DCCA71C17BAE2004BFDB8 /* Products */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | D98DCCA61C17BAE2004BFDB8 /* Attributed.framework */, 78 | D98DCCB01C17BAE2004BFDB8 /* AttributedTests.xctest */, 79 | ); 80 | name = Products; 81 | sourceTree = ""; 82 | }; 83 | D98DCCA81C17BAE2004BFDB8 /* Attributed */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | D98DCCC01C17BC11004BFDB8 /* Parse.swift */, 87 | D98DCCC81C18A805004BFDB8 /* MarkupElement.swift */, 88 | D98DCCC21C17BC18004BFDB8 /* SmallCaps.swift */, 89 | D98DCCC41C18A514004BFDB8 /* Modifier.swift */, 90 | D994817421A0FA7A0059E516 /* Modifiers.swift */, 91 | D98DCCC61C18A6E2004BFDB8 /* UIFont.swift */, 92 | D98DCCA91C17BAE2004BFDB8 /* Attributed.h */, 93 | D98DCCAB1C17BAE2004BFDB8 /* Info.plist */, 94 | ); 95 | path = Attributed; 96 | sourceTree = ""; 97 | }; 98 | D98DCCB41C17BAE2004BFDB8 /* AttributedTests */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | D98DCCB51C17BAE2004BFDB8 /* AttributedTests.swift */, 102 | D98DCCB71C17BAE2004BFDB8 /* Info.plist */, 103 | ); 104 | path = AttributedTests; 105 | sourceTree = ""; 106 | }; 107 | /* End PBXGroup section */ 108 | 109 | /* Begin PBXHeadersBuildPhase section */ 110 | D98DCCA31C17BAE2004BFDB8 /* Headers */ = { 111 | isa = PBXHeadersBuildPhase; 112 | buildActionMask = 2147483647; 113 | files = ( 114 | D98DCCAA1C17BAE2004BFDB8 /* Attributed.h in Headers */, 115 | ); 116 | runOnlyForDeploymentPostprocessing = 0; 117 | }; 118 | /* End PBXHeadersBuildPhase section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | D98DCCA51C17BAE2004BFDB8 /* Attributed */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = D98DCCBA1C17BAE2004BFDB8 /* Build configuration list for PBXNativeTarget "Attributed" */; 124 | buildPhases = ( 125 | D98DCCA11C17BAE2004BFDB8 /* Sources */, 126 | D98DCCA21C17BAE2004BFDB8 /* Frameworks */, 127 | D98DCCA31C17BAE2004BFDB8 /* Headers */, 128 | D98DCCA41C17BAE2004BFDB8 /* Resources */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | ); 134 | name = Attributed; 135 | productName = Attributed; 136 | productReference = D98DCCA61C17BAE2004BFDB8 /* Attributed.framework */; 137 | productType = "com.apple.product-type.framework"; 138 | }; 139 | D98DCCAF1C17BAE2004BFDB8 /* AttributedTests */ = { 140 | isa = PBXNativeTarget; 141 | buildConfigurationList = D98DCCBD1C17BAE2004BFDB8 /* Build configuration list for PBXNativeTarget "AttributedTests" */; 142 | buildPhases = ( 143 | D98DCCAC1C17BAE2004BFDB8 /* Sources */, 144 | D98DCCAD1C17BAE2004BFDB8 /* Frameworks */, 145 | D98DCCAE1C17BAE2004BFDB8 /* Resources */, 146 | ); 147 | buildRules = ( 148 | ); 149 | dependencies = ( 150 | D98DCCB31C17BAE2004BFDB8 /* PBXTargetDependency */, 151 | ); 152 | name = AttributedTests; 153 | productName = AttributedTests; 154 | productReference = D98DCCB01C17BAE2004BFDB8 /* AttributedTests.xctest */; 155 | productType = "com.apple.product-type.bundle.unit-test"; 156 | }; 157 | /* End PBXNativeTarget section */ 158 | 159 | /* Begin PBXProject section */ 160 | D98DCC9D1C17BAE2004BFDB8 /* Project object */ = { 161 | isa = PBXProject; 162 | attributes = { 163 | LastSwiftUpdateCheck = 0720; 164 | LastUpgradeCheck = 1120; 165 | ORGANIZATIONNAME = "Hilton Campbell"; 166 | TargetAttributes = { 167 | D98DCCA51C17BAE2004BFDB8 = { 168 | CreatedOnToolsVersion = 7.2; 169 | LastSwiftMigration = 1120; 170 | }; 171 | D98DCCAF1C17BAE2004BFDB8 = { 172 | CreatedOnToolsVersion = 7.2; 173 | LastSwiftMigration = 1120; 174 | }; 175 | }; 176 | }; 177 | buildConfigurationList = D98DCCA01C17BAE2004BFDB8 /* Build configuration list for PBXProject "Attributed" */; 178 | compatibilityVersion = "Xcode 3.2"; 179 | developmentRegion = en; 180 | hasScannedForEncodings = 0; 181 | knownRegions = ( 182 | en, 183 | Base, 184 | ); 185 | mainGroup = D98DCC9C1C17BAE2004BFDB8; 186 | productRefGroup = D98DCCA71C17BAE2004BFDB8 /* Products */; 187 | projectDirPath = ""; 188 | projectRoot = ""; 189 | targets = ( 190 | D98DCCA51C17BAE2004BFDB8 /* Attributed */, 191 | D98DCCAF1C17BAE2004BFDB8 /* AttributedTests */, 192 | ); 193 | }; 194 | /* End PBXProject section */ 195 | 196 | /* Begin PBXResourcesBuildPhase section */ 197 | D98DCCA41C17BAE2004BFDB8 /* Resources */ = { 198 | isa = PBXResourcesBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | ); 202 | runOnlyForDeploymentPostprocessing = 0; 203 | }; 204 | D98DCCAE1C17BAE2004BFDB8 /* Resources */ = { 205 | isa = PBXResourcesBuildPhase; 206 | buildActionMask = 2147483647; 207 | files = ( 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | /* End PBXResourcesBuildPhase section */ 212 | 213 | /* Begin PBXSourcesBuildPhase section */ 214 | D98DCCA11C17BAE2004BFDB8 /* Sources */ = { 215 | isa = PBXSourcesBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | D98DCCC71C18A6E2004BFDB8 /* UIFont.swift in Sources */, 219 | D98DCCC91C18A805004BFDB8 /* MarkupElement.swift in Sources */, 220 | D98DCCC11C17BC11004BFDB8 /* Parse.swift in Sources */, 221 | D98DCCC31C17BC18004BFDB8 /* SmallCaps.swift in Sources */, 222 | D994817521A0FA7A0059E516 /* Modifiers.swift in Sources */, 223 | D98DCCC51C18A514004BFDB8 /* Modifier.swift in Sources */, 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | }; 227 | D98DCCAC1C17BAE2004BFDB8 /* Sources */ = { 228 | isa = PBXSourcesBuildPhase; 229 | buildActionMask = 2147483647; 230 | files = ( 231 | D98DCCB61C17BAE2004BFDB8 /* AttributedTests.swift in Sources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXSourcesBuildPhase section */ 236 | 237 | /* Begin PBXTargetDependency section */ 238 | D98DCCB31C17BAE2004BFDB8 /* PBXTargetDependency */ = { 239 | isa = PBXTargetDependency; 240 | target = D98DCCA51C17BAE2004BFDB8 /* Attributed */; 241 | targetProxy = D98DCCB21C17BAE2004BFDB8 /* PBXContainerItemProxy */; 242 | }; 243 | /* End PBXTargetDependency section */ 244 | 245 | /* Begin XCBuildConfiguration section */ 246 | D98DCCB81C17BAE2004BFDB8 /* Debug */ = { 247 | isa = XCBuildConfiguration; 248 | buildSettings = { 249 | ALWAYS_SEARCH_USER_PATHS = NO; 250 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 256 | CLANG_WARN_BOOL_CONVERSION = YES; 257 | CLANG_WARN_COMMA = YES; 258 | CLANG_WARN_CONSTANT_CONVERSION = YES; 259 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 260 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 261 | CLANG_WARN_EMPTY_BODY = YES; 262 | CLANG_WARN_ENUM_CONVERSION = YES; 263 | CLANG_WARN_INFINITE_RECURSION = YES; 264 | CLANG_WARN_INT_CONVERSION = YES; 265 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 266 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 267 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 269 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 270 | CLANG_WARN_STRICT_PROTOTYPES = YES; 271 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 272 | CLANG_WARN_UNREACHABLE_CODE = YES; 273 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 274 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 275 | COPY_PHASE_STRIP = NO; 276 | CURRENT_PROJECT_VERSION = 1; 277 | DEBUG_INFORMATION_FORMAT = dwarf; 278 | ENABLE_STRICT_OBJC_MSGSEND = YES; 279 | ENABLE_TESTABILITY = YES; 280 | GCC_C_LANGUAGE_STANDARD = gnu99; 281 | GCC_DYNAMIC_NO_PIC = NO; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_OPTIMIZATION_LEVEL = 0; 284 | GCC_PREPROCESSOR_DEFINITIONS = ( 285 | "DEBUG=1", 286 | "$(inherited)", 287 | ); 288 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 289 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 290 | GCC_WARN_UNDECLARED_SELECTOR = YES; 291 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 292 | GCC_WARN_UNUSED_FUNCTION = YES; 293 | GCC_WARN_UNUSED_VARIABLE = YES; 294 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 295 | MTL_ENABLE_DEBUG_INFO = YES; 296 | ONLY_ACTIVE_ARCH = YES; 297 | SDKROOT = iphoneos; 298 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | VERSIONING_SYSTEM = "apple-generic"; 301 | VERSION_INFO_PREFIX = ""; 302 | }; 303 | name = Debug; 304 | }; 305 | D98DCCB91C17BAE2004BFDB8 /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ALWAYS_SEARCH_USER_PATHS = NO; 309 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 310 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 311 | CLANG_CXX_LIBRARY = "libc++"; 312 | CLANG_ENABLE_MODULES = YES; 313 | CLANG_ENABLE_OBJC_ARC = YES; 314 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 315 | CLANG_WARN_BOOL_CONVERSION = YES; 316 | CLANG_WARN_COMMA = YES; 317 | CLANG_WARN_CONSTANT_CONVERSION = YES; 318 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 319 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 320 | CLANG_WARN_EMPTY_BODY = YES; 321 | CLANG_WARN_ENUM_CONVERSION = YES; 322 | CLANG_WARN_INFINITE_RECURSION = YES; 323 | CLANG_WARN_INT_CONVERSION = YES; 324 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 325 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 326 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 327 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 328 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 329 | CLANG_WARN_STRICT_PROTOTYPES = YES; 330 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 331 | CLANG_WARN_UNREACHABLE_CODE = YES; 332 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 333 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 334 | COPY_PHASE_STRIP = NO; 335 | CURRENT_PROJECT_VERSION = 1; 336 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 337 | ENABLE_NS_ASSERTIONS = NO; 338 | ENABLE_STRICT_OBJC_MSGSEND = YES; 339 | GCC_C_LANGUAGE_STANDARD = gnu99; 340 | GCC_NO_COMMON_BLOCKS = YES; 341 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 342 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 343 | GCC_WARN_UNDECLARED_SELECTOR = YES; 344 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 345 | GCC_WARN_UNUSED_FUNCTION = YES; 346 | GCC_WARN_UNUSED_VARIABLE = YES; 347 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 348 | MTL_ENABLE_DEBUG_INFO = NO; 349 | SDKROOT = iphoneos; 350 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 351 | TARGETED_DEVICE_FAMILY = "1,2"; 352 | VALIDATE_PRODUCT = YES; 353 | VERSIONING_SYSTEM = "apple-generic"; 354 | VERSION_INFO_PREFIX = ""; 355 | }; 356 | name = Release; 357 | }; 358 | D98DCCBB1C17BAE2004BFDB8 /* Debug */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | CLANG_ENABLE_MODULES = YES; 362 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 363 | DEFINES_MODULE = YES; 364 | DYLIB_COMPATIBILITY_VERSION = 1; 365 | DYLIB_CURRENT_VERSION = 1; 366 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 367 | INFOPLIST_FILE = Attributed/Info.plist; 368 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 370 | PRODUCT_BUNDLE_IDENTIFIER = com.crosswaterbridge.Attributed; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | SKIP_INSTALL = YES; 373 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 374 | SWIFT_VERSION = 5.0; 375 | }; 376 | name = Debug; 377 | }; 378 | D98DCCBC1C17BAE2004BFDB8 /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | CLANG_ENABLE_MODULES = YES; 382 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 383 | DEFINES_MODULE = YES; 384 | DYLIB_COMPATIBILITY_VERSION = 1; 385 | DYLIB_CURRENT_VERSION = 1; 386 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 387 | INFOPLIST_FILE = Attributed/Info.plist; 388 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 389 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 390 | PRODUCT_BUNDLE_IDENTIFIER = com.crosswaterbridge.Attributed; 391 | PRODUCT_NAME = "$(TARGET_NAME)"; 392 | SKIP_INSTALL = YES; 393 | SWIFT_VERSION = 5.0; 394 | }; 395 | name = Release; 396 | }; 397 | D98DCCBE1C17BAE2004BFDB8 /* Debug */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | INFOPLIST_FILE = AttributedTests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_BUNDLE_IDENTIFIER = com.crosswaterbridge.AttributedTests; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | SWIFT_VERSION = 5.0; 405 | }; 406 | name = Debug; 407 | }; 408 | D98DCCBF1C17BAE2004BFDB8 /* Release */ = { 409 | isa = XCBuildConfiguration; 410 | buildSettings = { 411 | INFOPLIST_FILE = AttributedTests/Info.plist; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 413 | PRODUCT_BUNDLE_IDENTIFIER = com.crosswaterbridge.AttributedTests; 414 | PRODUCT_NAME = "$(TARGET_NAME)"; 415 | SWIFT_VERSION = 5.0; 416 | }; 417 | name = Release; 418 | }; 419 | /* End XCBuildConfiguration section */ 420 | 421 | /* Begin XCConfigurationList section */ 422 | D98DCCA01C17BAE2004BFDB8 /* Build configuration list for PBXProject "Attributed" */ = { 423 | isa = XCConfigurationList; 424 | buildConfigurations = ( 425 | D98DCCB81C17BAE2004BFDB8 /* Debug */, 426 | D98DCCB91C17BAE2004BFDB8 /* Release */, 427 | ); 428 | defaultConfigurationIsVisible = 0; 429 | defaultConfigurationName = Release; 430 | }; 431 | D98DCCBA1C17BAE2004BFDB8 /* Build configuration list for PBXNativeTarget "Attributed" */ = { 432 | isa = XCConfigurationList; 433 | buildConfigurations = ( 434 | D98DCCBB1C17BAE2004BFDB8 /* Debug */, 435 | D98DCCBC1C17BAE2004BFDB8 /* Release */, 436 | ); 437 | defaultConfigurationIsVisible = 0; 438 | defaultConfigurationName = Release; 439 | }; 440 | D98DCCBD1C17BAE2004BFDB8 /* Build configuration list for PBXNativeTarget "AttributedTests" */ = { 441 | isa = XCConfigurationList; 442 | buildConfigurations = ( 443 | D98DCCBE1C17BAE2004BFDB8 /* Debug */, 444 | D98DCCBF1C17BAE2004BFDB8 /* Release */, 445 | ); 446 | defaultConfigurationIsVisible = 0; 447 | defaultConfigurationName = Release; 448 | }; 449 | /* End XCConfigurationList section */ 450 | }; 451 | rootObject = D98DCC9D1C17BAE2004BFDB8 /* Project object */; 452 | } 453 | --------------------------------------------------------------------------------