├── LiterateSwift.xcodeproj └── project.pbxproj ├── LiterateSwift.xcworkspace └── contents.xcworkspacedata ├── LiterateSwift ├── AppDelegate.swift ├── Base.lproj │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── Latex.swift ├── LatexViewController.swift ├── MarkdownDocument.swift ├── PlaygroundViewController.swift ├── RenderViewController.swift └── SwiftViewController.swift ├── Podfile ├── Podfile.lock └── README.md /LiterateSwift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 38AEDE1ECA8E92FA1089C1F8 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 79038653B13468E0FDBBF5BC /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 11 | 835A46FE1B59391500CFD860 /* LatexViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A46FD1B59391500CFD860 /* LatexViewController.swift */; }; 12 | 835A47001B595C6400CFD860 /* Latex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A46FF1B595C6400CFD860 /* Latex.swift */; }; 13 | 837DB95B1B0F63B3007114EC /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 837DB95A1B0F63B3007114EC /* WebKit.framework */; }; 14 | 838B51741B0F5C7C00137358 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 838B51731B0F5C7C00137358 /* AppDelegate.swift */; }; 15 | 838B51761B0F5C7C00137358 /* RenderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 838B51751B0F5C7C00137358 /* RenderViewController.swift */; }; 16 | 838B51781B0F5C7C00137358 /* MarkdownDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 838B51771B0F5C7C00137358 /* MarkdownDocument.swift */; }; 17 | 838B517A1B0F5C7C00137358 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 838B51791B0F5C7C00137358 /* Images.xcassets */; }; 18 | 838B517D1B0F5C7C00137358 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 838B517B1B0F5C7C00137358 /* Main.storyboard */; }; 19 | 83D71E2E1B132AD5000395DE /* SwiftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D71E2D1B132AD5000395DE /* SwiftViewController.swift */; }; 20 | 83EE3D511B2B524800FFB51F /* PlaygroundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83EE3D501B2B524800FFB51F /* PlaygroundViewController.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 171DE05A00B0AEE85D9C1990 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 25 | 2EDCD4E6C331ECC1BC798717 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 26 | 79038653B13468E0FDBBF5BC /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 835A46FD1B59391500CFD860 /* LatexViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LatexViewController.swift; sourceTree = ""; }; 28 | 835A46FF1B595C6400CFD860 /* Latex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Latex.swift; sourceTree = ""; }; 29 | 837DB95A1B0F63B3007114EC /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 30 | 838B516E1B0F5C7C00137358 /* LiterateSwiftGUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LiterateSwiftGUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 838B51721B0F5C7C00137358 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 838B51731B0F5C7C00137358 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | 838B51751B0F5C7C00137358 /* RenderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenderViewController.swift; sourceTree = ""; }; 34 | 838B51771B0F5C7C00137358 /* MarkdownDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownDocument.swift; sourceTree = ""; }; 35 | 838B51791B0F5C7C00137358 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 36 | 838B517C1B0F5C7C00137358 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 37 | 83D71E2D1B132AD5000395DE /* SwiftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftViewController.swift; sourceTree = ""; }; 38 | 83EE3D501B2B524800FFB51F /* PlaygroundViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaygroundViewController.swift; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 838B516B1B0F5C7C00137358 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | 837DB95B1B0F63B3007114EC /* WebKit.framework in Frameworks */, 47 | 38AEDE1ECA8E92FA1089C1F8 /* Pods.framework in Frameworks */, 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 838B51651B0F5C7C00137358 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 837DB95A1B0F63B3007114EC /* WebKit.framework */, 58 | 838B51701B0F5C7C00137358 /* LiterateSwift */, 59 | 838B516F1B0F5C7C00137358 /* Products */, 60 | EF8F220F83C6FB0B2B7FA64C /* Pods */, 61 | D1B1FE73359F91FAFDFBDCA1 /* Frameworks */, 62 | ); 63 | sourceTree = ""; 64 | }; 65 | 838B516F1B0F5C7C00137358 /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 838B516E1B0F5C7C00137358 /* LiterateSwiftGUI.app */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | 838B51701B0F5C7C00137358 /* LiterateSwift */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 838B51731B0F5C7C00137358 /* AppDelegate.swift */, 77 | 838B51751B0F5C7C00137358 /* RenderViewController.swift */, 78 | 838B51771B0F5C7C00137358 /* MarkdownDocument.swift */, 79 | 838B51791B0F5C7C00137358 /* Images.xcassets */, 80 | 838B517B1B0F5C7C00137358 /* Main.storyboard */, 81 | 838B51711B0F5C7C00137358 /* Supporting Files */, 82 | 83D71E2D1B132AD5000395DE /* SwiftViewController.swift */, 83 | 83EE3D501B2B524800FFB51F /* PlaygroundViewController.swift */, 84 | 835A46FD1B59391500CFD860 /* LatexViewController.swift */, 85 | 835A46FF1B595C6400CFD860 /* Latex.swift */, 86 | ); 87 | path = LiterateSwift; 88 | sourceTree = ""; 89 | }; 90 | 838B51711B0F5C7C00137358 /* Supporting Files */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 838B51721B0F5C7C00137358 /* Info.plist */, 94 | ); 95 | name = "Supporting Files"; 96 | sourceTree = ""; 97 | }; 98 | D1B1FE73359F91FAFDFBDCA1 /* Frameworks */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 79038653B13468E0FDBBF5BC /* Pods.framework */, 102 | ); 103 | name = Frameworks; 104 | sourceTree = ""; 105 | }; 106 | EF8F220F83C6FB0B2B7FA64C /* Pods */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 171DE05A00B0AEE85D9C1990 /* Pods.debug.xcconfig */, 110 | 2EDCD4E6C331ECC1BC798717 /* Pods.release.xcconfig */, 111 | ); 112 | name = Pods; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXNativeTarget section */ 118 | 838B516D1B0F5C7C00137358 /* LiterateSwiftGUI */ = { 119 | isa = PBXNativeTarget; 120 | buildConfigurationList = 838B518C1B0F5C7C00137358 /* Build configuration list for PBXNativeTarget "LiterateSwiftGUI" */; 121 | buildPhases = ( 122 | 447EF41B9FF59D602F195450 /* Check Pods Manifest.lock */, 123 | 838B516A1B0F5C7C00137358 /* Sources */, 124 | 838B516B1B0F5C7C00137358 /* Frameworks */, 125 | 838B516C1B0F5C7C00137358 /* Resources */, 126 | 4C4CC8570ECDC7D6330EEC26 /* Embed Pods Frameworks */, 127 | 57B028FC9D86306C81B8B4F3 /* Copy Pods Resources */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = LiterateSwiftGUI; 134 | productName = LiterateSwift; 135 | productReference = 838B516E1B0F5C7C00137358 /* LiterateSwiftGUI.app */; 136 | productType = "com.apple.product-type.application"; 137 | }; 138 | /* End PBXNativeTarget section */ 139 | 140 | /* Begin PBXProject section */ 141 | 838B51661B0F5C7C00137358 /* Project object */ = { 142 | isa = PBXProject; 143 | attributes = { 144 | LastSwiftUpdateCheck = 0700; 145 | LastUpgradeCheck = 0630; 146 | ORGANIZATIONNAME = "Unsigned Integer"; 147 | TargetAttributes = { 148 | 838B516D1B0F5C7C00137358 = { 149 | CreatedOnToolsVersion = 6.3.1; 150 | }; 151 | }; 152 | }; 153 | buildConfigurationList = 838B51691B0F5C7C00137358 /* Build configuration list for PBXProject "LiterateSwift" */; 154 | compatibilityVersion = "Xcode 3.2"; 155 | developmentRegion = English; 156 | hasScannedForEncodings = 0; 157 | knownRegions = ( 158 | en, 159 | Base, 160 | ); 161 | mainGroup = 838B51651B0F5C7C00137358; 162 | productRefGroup = 838B516F1B0F5C7C00137358 /* Products */; 163 | projectDirPath = ""; 164 | projectRoot = ""; 165 | targets = ( 166 | 838B516D1B0F5C7C00137358 /* LiterateSwiftGUI */, 167 | ); 168 | }; 169 | /* End PBXProject section */ 170 | 171 | /* Begin PBXResourcesBuildPhase section */ 172 | 838B516C1B0F5C7C00137358 /* Resources */ = { 173 | isa = PBXResourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 838B517A1B0F5C7C00137358 /* Images.xcassets in Resources */, 177 | 838B517D1B0F5C7C00137358 /* Main.storyboard in Resources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXResourcesBuildPhase section */ 182 | 183 | /* Begin PBXShellScriptBuildPhase section */ 184 | 447EF41B9FF59D602F195450 /* Check Pods Manifest.lock */ = { 185 | isa = PBXShellScriptBuildPhase; 186 | buildActionMask = 2147483647; 187 | files = ( 188 | ); 189 | inputPaths = ( 190 | ); 191 | name = "Check Pods Manifest.lock"; 192 | outputPaths = ( 193 | ); 194 | runOnlyForDeploymentPostprocessing = 0; 195 | shellPath = /bin/sh; 196 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 197 | showEnvVarsInLog = 0; 198 | }; 199 | 4C4CC8570ECDC7D6330EEC26 /* Embed Pods Frameworks */ = { 200 | isa = PBXShellScriptBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | ); 204 | inputPaths = ( 205 | ); 206 | name = "Embed Pods Frameworks"; 207 | outputPaths = ( 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | shellPath = /bin/sh; 211 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; 212 | showEnvVarsInLog = 0; 213 | }; 214 | 57B028FC9D86306C81B8B4F3 /* Copy Pods Resources */ = { 215 | isa = PBXShellScriptBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | ); 219 | inputPaths = ( 220 | ); 221 | name = "Copy Pods Resources"; 222 | outputPaths = ( 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | shellPath = /bin/sh; 226 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; 227 | showEnvVarsInLog = 0; 228 | }; 229 | /* End PBXShellScriptBuildPhase section */ 230 | 231 | /* Begin PBXSourcesBuildPhase section */ 232 | 838B516A1B0F5C7C00137358 /* Sources */ = { 233 | isa = PBXSourcesBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | 83D71E2E1B132AD5000395DE /* SwiftViewController.swift in Sources */, 237 | 838B51761B0F5C7C00137358 /* RenderViewController.swift in Sources */, 238 | 838B51741B0F5C7C00137358 /* AppDelegate.swift in Sources */, 239 | 83EE3D511B2B524800FFB51F /* PlaygroundViewController.swift in Sources */, 240 | 835A47001B595C6400CFD860 /* Latex.swift in Sources */, 241 | 838B51781B0F5C7C00137358 /* MarkdownDocument.swift in Sources */, 242 | 835A46FE1B59391500CFD860 /* LatexViewController.swift in Sources */, 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | /* End PBXSourcesBuildPhase section */ 247 | 248 | /* Begin PBXVariantGroup section */ 249 | 838B517B1B0F5C7C00137358 /* Main.storyboard */ = { 250 | isa = PBXVariantGroup; 251 | children = ( 252 | 838B517C1B0F5C7C00137358 /* Base */, 253 | ); 254 | name = Main.storyboard; 255 | sourceTree = ""; 256 | }; 257 | /* End PBXVariantGroup section */ 258 | 259 | /* Begin XCBuildConfiguration section */ 260 | 838B518A1B0F5C7C00137358 /* Debug */ = { 261 | isa = XCBuildConfiguration; 262 | buildSettings = { 263 | ALWAYS_SEARCH_USER_PATHS = NO; 264 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 265 | CLANG_CXX_LIBRARY = "libc++"; 266 | CLANG_ENABLE_MODULES = YES; 267 | CLANG_ENABLE_OBJC_ARC = YES; 268 | CLANG_WARN_BOOL_CONVERSION = YES; 269 | CLANG_WARN_CONSTANT_CONVERSION = YES; 270 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 271 | CLANG_WARN_EMPTY_BODY = YES; 272 | CLANG_WARN_ENUM_CONVERSION = YES; 273 | CLANG_WARN_INT_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | CODE_SIGN_IDENTITY = "-"; 278 | COPY_PHASE_STRIP = NO; 279 | DEBUG_INFORMATION_FORMAT = dwarf; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu99; 282 | GCC_DYNAMIC_NO_PIC = NO; 283 | GCC_NO_COMMON_BLOCKS = YES; 284 | GCC_OPTIMIZATION_LEVEL = 0; 285 | GCC_PREPROCESSOR_DEFINITIONS = ( 286 | "DEBUG=1", 287 | "$(inherited)", 288 | ); 289 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 290 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 291 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 292 | GCC_WARN_UNDECLARED_SELECTOR = YES; 293 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 294 | GCC_WARN_UNUSED_FUNCTION = YES; 295 | GCC_WARN_UNUSED_VARIABLE = YES; 296 | MACOSX_DEPLOYMENT_TARGET = 10.10; 297 | MTL_ENABLE_DEBUG_INFO = YES; 298 | ONLY_ACTIVE_ARCH = YES; 299 | SDKROOT = macosx; 300 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 301 | }; 302 | name = Debug; 303 | }; 304 | 838B518B1B0F5C7C00137358 /* Release */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ALWAYS_SEARCH_USER_PATHS = NO; 308 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 309 | CLANG_CXX_LIBRARY = "libc++"; 310 | CLANG_ENABLE_MODULES = YES; 311 | CLANG_ENABLE_OBJC_ARC = YES; 312 | CLANG_WARN_BOOL_CONVERSION = YES; 313 | CLANG_WARN_CONSTANT_CONVERSION = YES; 314 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 315 | CLANG_WARN_EMPTY_BODY = YES; 316 | CLANG_WARN_ENUM_CONVERSION = YES; 317 | CLANG_WARN_INT_CONVERSION = YES; 318 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 319 | CLANG_WARN_UNREACHABLE_CODE = YES; 320 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 321 | CODE_SIGN_IDENTITY = "-"; 322 | COPY_PHASE_STRIP = NO; 323 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 324 | ENABLE_NS_ASSERTIONS = NO; 325 | ENABLE_STRICT_OBJC_MSGSEND = YES; 326 | GCC_C_LANGUAGE_STANDARD = gnu99; 327 | GCC_NO_COMMON_BLOCKS = YES; 328 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 329 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 330 | GCC_WARN_UNDECLARED_SELECTOR = YES; 331 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 332 | GCC_WARN_UNUSED_FUNCTION = YES; 333 | GCC_WARN_UNUSED_VARIABLE = YES; 334 | MACOSX_DEPLOYMENT_TARGET = 10.10; 335 | MTL_ENABLE_DEBUG_INFO = NO; 336 | SDKROOT = macosx; 337 | }; 338 | name = Release; 339 | }; 340 | 838B518D1B0F5C7C00137358 /* Debug */ = { 341 | isa = XCBuildConfiguration; 342 | baseConfigurationReference = 171DE05A00B0AEE85D9C1990 /* Pods.debug.xcconfig */; 343 | buildSettings = { 344 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 345 | COMBINE_HIDPI_IMAGES = YES; 346 | FRAMEWORK_SEARCH_PATHS = ( 347 | "$(inherited)", 348 | "$(PROJECT_DIR)/CommonMark/build/Debug", 349 | "$(PROJECT_DIR)/LiterateSwiftFramework/build/Debug", 350 | ); 351 | INFOPLIST_FILE = LiterateSwift/Info.plist; 352 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 353 | PRODUCT_NAME = LiterateSwiftGUI; 354 | }; 355 | name = Debug; 356 | }; 357 | 838B518E1B0F5C7C00137358 /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | baseConfigurationReference = 2EDCD4E6C331ECC1BC798717 /* Pods.release.xcconfig */; 360 | buildSettings = { 361 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 362 | COMBINE_HIDPI_IMAGES = YES; 363 | FRAMEWORK_SEARCH_PATHS = ( 364 | "$(inherited)", 365 | "$(PROJECT_DIR)/CommonMark/build/Debug", 366 | "$(PROJECT_DIR)/LiterateSwiftFramework/build/Debug", 367 | ); 368 | INFOPLIST_FILE = LiterateSwift/Info.plist; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 370 | PRODUCT_NAME = LiterateSwiftGUI; 371 | }; 372 | name = Release; 373 | }; 374 | /* End XCBuildConfiguration section */ 375 | 376 | /* Begin XCConfigurationList section */ 377 | 838B51691B0F5C7C00137358 /* Build configuration list for PBXProject "LiterateSwift" */ = { 378 | isa = XCConfigurationList; 379 | buildConfigurations = ( 380 | 838B518A1B0F5C7C00137358 /* Debug */, 381 | 838B518B1B0F5C7C00137358 /* Release */, 382 | ); 383 | defaultConfigurationIsVisible = 0; 384 | defaultConfigurationName = Release; 385 | }; 386 | 838B518C1B0F5C7C00137358 /* Build configuration list for PBXNativeTarget "LiterateSwiftGUI" */ = { 387 | isa = XCConfigurationList; 388 | buildConfigurations = ( 389 | 838B518D1B0F5C7C00137358 /* Debug */, 390 | 838B518E1B0F5C7C00137358 /* Release */, 391 | ); 392 | defaultConfigurationIsVisible = 0; 393 | defaultConfigurationName = Release; 394 | }; 395 | /* End XCConfigurationList section */ 396 | }; 397 | rootObject = 838B51661B0F5C7C00137358 /* Project object */; 398 | } 399 | -------------------------------------------------------------------------------- /LiterateSwift.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /LiterateSwift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LiterateSwift2 4 | // 5 | // Created by Chris Eidhof on 22/05/15. 6 | // Copyright (c) 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import CommonMark 11 | 12 | @NSApplicationMain 13 | class AppDelegate: NSObject, NSApplicationDelegate { 14 | 15 | 16 | func applicationDidFinishLaunching(aNotification: NSNotification) { 17 | // Insert code here to initialize your application 18 | } 19 | 20 | func applicationWillTerminate(aNotification: NSNotification) { 21 | // Insert code here to tear down your application 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /LiterateSwift/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | Default 490 | 491 | 492 | 493 | 494 | 495 | 496 | Left to Right 497 | 498 | 499 | 500 | 501 | 502 | 503 | Right to Left 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | Default 515 | 516 | 517 | 518 | 519 | 520 | 521 | Left to Right 522 | 523 | 524 | 525 | 526 | 527 | 528 | Right to Left 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | -------------------------------------------------------------------------------- /LiterateSwift/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /LiterateSwift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | md 13 | 14 | CFBundleTypeIconFile 15 | 16 | CFBundleTypeName 17 | DocumentType 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | $(PRODUCT_MODULE_NAME).MarkdownDocument 26 | 27 | 28 | CFBundleExecutable 29 | $(EXECUTABLE_NAME) 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | com.unsignedinteger.$(PRODUCT_NAME:rfc1034identifier) 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | $(PRODUCT_NAME) 38 | CFBundlePackageType 39 | APPL 40 | CFBundleShortVersionString 41 | 1.0 42 | CFBundleSignature 43 | ???? 44 | CFBundleVersion 45 | 1 46 | LSMinimumSystemVersion 47 | $(MACOSX_DEPLOYMENT_TARGET) 48 | NSHumanReadableCopyright 49 | Copyright © 2015 Unsigned Integer. All rights reserved. 50 | NSMainStoryboardFile 51 | Main 52 | NSPrincipalClass 53 | NSApplication 54 | 55 | 56 | -------------------------------------------------------------------------------- /LiterateSwift/Latex.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Latex.swift 3 | // LiterateSwift 4 | // 5 | // Created by Chris Eidhof on 17/07/15. 6 | // Copyright © 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CommonMark 11 | 12 | protocol ToLatex { 13 | var latex: Latex { get } 14 | } 15 | 16 | enum Escape { 17 | case Literal 18 | case Normal 19 | case URL 20 | } 21 | 22 | struct Latex { 23 | let raw: String 24 | init(raw l: String) { self.raw = l } 25 | init(escape str: String) { 26 | raw = escape(str, mode: .Normal) 27 | } 28 | init(literal str: String) { 29 | raw = str 30 | } 31 | init(urlEscape str: String) { 32 | raw = escape(str, mode: .URL) 33 | } 34 | } 35 | 36 | extension Latex: ToLatex { 37 | var latex: Latex { return self } 38 | } 39 | 40 | func +(x: Latex, y: Latex) -> Latex { 41 | return Latex(raw: x.raw + y.raw) 42 | } 43 | 44 | extension Array where Element: ToLatex { 45 | var joined: Latex { 46 | return Latex(raw: self.map { $0.latex.raw }.joinWithSeparator("")) 47 | } 48 | } 49 | 50 | extension String { 51 | func cmd() -> Latex { 52 | return Latex(raw:"\\\(self)") 53 | } 54 | func cmd(contents: String) -> Latex { 55 | return cmd(Latex(escape: contents)) 56 | } 57 | func cmd(contents: Latex) -> Latex { 58 | return Latex(raw: "\\\(self){\(contents.raw)}") 59 | } 60 | 61 | func cmd(param: Latex, children: [A]) -> Latex { 62 | return Latex(raw: "\\\(self){\(param.raw)}{\(children.joined.raw)}") 63 | } 64 | 65 | func cmd(contents: [A]) -> Latex { 66 | return Latex(raw: "\\\(self){\(contents.joined.raw)}") 67 | } 68 | 69 | func env(contents: Latex) -> Latex { 70 | return Latex(raw: "\\begin{\(self)}\n\(contents.raw)\n\\end{\(self)}\n\n") 71 | } 72 | 73 | func env(contents: [A]) -> Latex { 74 | return env(contents.joined) 75 | } 76 | } 77 | 78 | extension String { 79 | func contains(c: Character) -> Bool { 80 | return characters.contains(c) 81 | } 82 | } 83 | 84 | private let mapping: [Character:String] = [ 85 | "|": "\\textbar{}", 86 | "<": "\\textless{}", 87 | ">": "\\textgreater{}", 88 | "[": "{[}", 89 | "]": "{]}", 90 | // "\"": "\\textquotedbl{}", 91 | "'": "\\textquotesingle{}", 92 | "\u{a0}": "~", // nbsp 93 | "\u{2026}": "\\ldots{}", // hellip 94 | "ọ": "\\d{o}", 95 | "ọ̀": "\\d{ó}", 96 | // "🇬🇧": "$\\vcenter{\\hbox{\\includegraphics{uk-f}}}$", 97 | ] 98 | 99 | private let mappingInNormal: [Character: String] = [ // Only in normal mode 100 | "\u{2018}": "`", //lsquo 101 | "\u{2019}": "'", //rsquo 102 | "\u{201c}": "``", //ldquo 103 | "\u{201d}": "''", //rdquo 104 | "\u{2014}": "---", //emdash 105 | "\u{2013}": "--", //endash 106 | ] 107 | 108 | func escape(string: String, mode: Escape) -> String { 109 | var result: String = "" 110 | var previous: Character = "x" // Doesn't matter, as long as it's not - 111 | let f = escapeLatex(mode) 112 | for char in string.characters { 113 | result += f(char: char, next: previous) 114 | previous = char 115 | } 116 | return result 117 | } 118 | 119 | func escapeLatex(escape: Escape)(char: Character, next: Character) -> String { 120 | let str = String([char]) 121 | if "{}#%&".contains(char) { 122 | return "\\" + str 123 | } else if "$_".contains(char) && escape == .Normal { 124 | return "\\" + str 125 | } else if char == "-" && next == "-" { 126 | return "\\-" 127 | } else if char == "~" && escape == .Normal { 128 | return "\\textasciitilde{}" 129 | } else if char == "^" { 130 | return "\\^{}" 131 | } else if char == "\\" && escape != .URL { 132 | return "\\textbackslash{}" 133 | } else if let result = mapping[char] { 134 | return result 135 | } else if let result = mapping[char] where escape == .Normal { 136 | return result 137 | } 138 | return str 139 | } 140 | 141 | 142 | extension InlineElement: ToLatex { 143 | var latex: Latex { 144 | switch self { 145 | case let .Code(code): return "texttt".cmd(code) 146 | case let .Emphasis(children): return "emph".cmd(children) 147 | case let .Strong(children): return "textbf".cmd(children) 148 | case .Text(let t): return Latex(escape: t) 149 | case .SoftBreak: return Latex(raw: " ") 150 | case .LineBreak: return Latex(raw: "\\\\") 151 | case let .Link(children, _, url): return "href".cmd(Latex(urlEscape: url ?? ""), children: children) 152 | case let .Image(_, _, url): return "protect".cmd() + "includegraphics".cmd(Latex(urlEscape: url!)) 153 | case .InlineHtml(_): return Latex(raw: "") // Don't know how to process this 154 | } 155 | } 156 | } 157 | 158 | func header(level: Int) -> String? { 159 | let levels = ["chapter", 160 | "section", 161 | "subsection", 162 | "subsubsection", 163 | "paragraph", 164 | "subparagraph" 165 | ] 166 | guard level-1 < levels.count else { return nil } 167 | return levels[level-1] 168 | 169 | } 170 | 171 | extension Block: ToLatex { 172 | var latex: Latex { 173 | switch self { 174 | case .BlockQuote(let items): 175 | return "quote".env(items) 176 | case let .CodeBlock(text, language) where language == "swift": 177 | return "swiftlisting".env(Latex(literal: text)) 178 | case let .CodeBlock(text, _): 179 | return "verbatim".env(Latex(literal: text)) 180 | case let .Header(children, level): 181 | return header(level)!.cmd(children) + Latex(raw: "\n") 182 | case .HorizontalRule: 183 | return Latex(raw: "\n\n\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}\n\n") 184 | case .Html(_): 185 | return Latex(raw: "") // ? 186 | case let .List(items, type): 187 | let command = type == ListType.Unordered ? "itemize" : "enumerate" 188 | return command.env(items.map { 189 | return "item ".cmd() + $0.joined 190 | }) 191 | case .Paragraph(let text): 192 | return text.joined + Latex(raw: "\n\n") 193 | } 194 | } 195 | } 196 | 197 | public func latexString(x: [Block]) -> String { 198 | return x.joined.raw 199 | } -------------------------------------------------------------------------------- /LiterateSwift/LatexViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LatexViewController.swift 3 | // LiterateSwift 4 | // 5 | // Created by Chris Eidhof on 17/07/15. 6 | // Copyright © 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CommonMark 11 | import LiterateSwift 12 | 13 | 14 | class LatexViewController: NSViewController { 15 | @IBOutlet var textview: NSTextView? 16 | 17 | func loadNode(elements: [Block]) { 18 | let text = latexString(elements) 19 | let attributes: [String: AnyObject] = [NSFontAttributeName: NSFont(name: "Monaco", size: 14)!] 20 | let attributedString = NSAttributedString(string: text, attributes: attributes) 21 | textview?.textStorage?.setAttributedString(attributedString) 22 | } 23 | 24 | override func viewDidAppear() { 25 | guard let doc = view.window?.windowController?.document as? MarkdownDocument else { return } 26 | doc.callbacks.append(self.loadNode) 27 | loadNode(doc.elements) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LiterateSwift/MarkdownDocument.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Document.swift 3 | // LiterateSwift2 4 | // 5 | // Created by Chris Eidhof on 22/05/15. 6 | // Copyright (c) 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import CommonMark 11 | 12 | class MarkdownDocument: NSDocument { 13 | 14 | private var node: Node? { 15 | didSet { 16 | let theElements = elements 17 | dispatch_async(dispatch_get_main_queue()) { 18 | for callback in self.callbacks { 19 | callback(theElements) 20 | } 21 | } 22 | } 23 | } 24 | 25 | var elements: [Block] { 26 | return node?.elements ?? [] 27 | } 28 | 29 | var callbacks: [[Block] -> ()] = [] 30 | 31 | override func makeWindowControllers() { 32 | // Returns the Storyboard that contains your Document window. 33 | let storyboard = NSStoryboard(name: "Main", bundle: nil) 34 | let windowController = storyboard.instantiateControllerWithIdentifier("Document Window Controller") as! NSWindowController 35 | self.addWindowController(windowController) 36 | } 37 | 38 | func reload() { 39 | node = fileURL?.path.flatMap { Node(filename: $0) } 40 | } 41 | 42 | override func readFromURL(url: NSURL, ofType typeName: String) throws { 43 | reload() 44 | } 45 | 46 | override func presentedItemDidChange() { 47 | reload() 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /LiterateSwift/PlaygroundViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftViewController.swift 3 | // LiterateSwift2 4 | // 5 | // Created by Chris Eidhof on 25/05/15. 6 | // Copyright (c) 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CommonMark 11 | import LiterateSwift 12 | 13 | enum PlaygroundNode { 14 | case Comment(Block) 15 | case Code(String) 16 | } 17 | 18 | func convert(blocks: [Block]) -> [PlaygroundNode] { 19 | return blocks.map { 20 | if let code = codeBlock($0, { $0 == "swift" || $0 == "print-swift" }) { 21 | return .Code(code) 22 | } else if case let .CodeBlock(code, _) = $0 { 23 | return .Comment(Block.CodeBlock(text: code, language: nil)) // Remove the language annotations 24 | } else { 25 | return .Comment($0) 26 | } 27 | } 28 | } 29 | 30 | extension String { 31 | var lines: [String] { 32 | return componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) 33 | } 34 | } 35 | 36 | extension SequenceType where Generator.Element == String { 37 | func unlines() -> String { 38 | return self.joinWithSeparator("\n") 39 | } 40 | } 41 | 42 | 43 | func render(nodes: [PlaygroundNode]) -> String { 44 | let strings: [String] = nodes.map { 45 | switch $0 { 46 | case .Comment(let c): return Node(blocks: [c]).commonMark.lines.map { "//: " + $0 }.unlines() 47 | case .Code(let c): return c 48 | } 49 | } 50 | return strings.unlines() 51 | } 52 | 53 | class PlaygroundViewController: NSViewController { 54 | 55 | @IBOutlet var textview: NSTextView? 56 | 57 | 58 | func loadNode(elements: [Block]) { 59 | let text = render(convert(elements)) 60 | let attributes: [String: AnyObject] = [NSFontAttributeName: NSFont(name: "Monaco", size: 14)!] 61 | let attributedString = NSAttributedString(string: text, attributes: attributes) 62 | textview?.textStorage?.setAttributedString(attributedString) 63 | } 64 | 65 | override func viewDidAppear() { 66 | guard let doc = view.window?.windowController?.document as? MarkdownDocument else { return } 67 | doc.callbacks.append(self.loadNode) 68 | loadNode(doc.elements) 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /LiterateSwift/RenderViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LiterateSwift2 4 | // 5 | // Created by Chris Eidhof on 22/05/15. 6 | // Copyright (c) 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import WebKit 11 | import CommonMark 12 | import LiterateSwift 13 | 14 | func prependLanguage(child: Block) -> [Block] { 15 | guard case let .CodeBlock(_, language) = child where language != nil else { return [child] } 16 | 17 | let explanation = Block.Paragraph(text: [.Text(text: "Example: "), .Emphasis(children: [.Text(text: language!)])]) 18 | return [explanation, child] 19 | } 20 | 21 | func stripLink(child: InlineElement) -> [InlineElement] { 22 | if case let .Link(children, _, _) = child { 23 | return children 24 | } 25 | return [child] 26 | } 27 | 28 | func stripSampleImpl(child: Block) -> [Block] { 29 | guard case let .CodeBlock(code, language) = child where language == "swift" else { return [child] } 30 | 31 | let cleanCode = code.stringByReplacingOccurrencesOfString("_sample_impl", withString: "") 32 | return [.CodeBlock(text: cleanCode, language: language)] 33 | } 34 | 35 | 36 | func addFootnote() -> InlineElement -> [InlineElement] { 37 | var counter = 0 38 | return { child in 39 | if case let .Link(children, _, _) = child { 40 | counter++ 41 | return children + [InlineElement.InlineHtml(text: "\(counter)")] 42 | } else { 43 | return [child] 44 | } 45 | } 46 | } 47 | 48 | func linkURLs(blocks: [Block]) -> [String?] { 49 | return deepCollect(blocks) { (element: InlineElement) -> [String?] in 50 | guard case let .Link(_, _, url) = element else { return [] } 51 | return [url] 52 | } 53 | } 54 | 55 | func tableOfContents(blocks: [Block]) -> [Block] { 56 | let headers = deepCollect(blocks) { (b: Block) -> [Block] in 57 | guard case let .Header(text, level) = b else { return [] } 58 | let prepend = (Array(count: level, repeatedValue: "_")).joinWithSeparator("") + " " 59 | return [Block.Paragraph(text: [InlineElement.Code(text: prepend)] + text)] 60 | } 61 | return [Block.Paragraph(text: [InlineElement.Emphasis(children: ["Table of contents"])])] + headers + [Block.HorizontalRule] 62 | } 63 | 64 | func replaceOrError(s: String)(b: Block) -> [Block] { 65 | do { 66 | return try replaceSnippet(s)(child: b) 67 | } catch { 68 | return [Block.CodeBlock(text: "<>", language: "")] 69 | } 70 | } 71 | 72 | 73 | class RenderViewController: NSViewController { 74 | 75 | @IBOutlet var webview: WebView! 76 | 77 | func loadNode(fileName: String)(elements: [Block]) { 78 | let scrollTop = webview.mainFrame.javaScriptContext.evaluateScript("document.body.scrollTop") 79 | let restoreScrollTop = "" 80 | let directory = (fileName as NSString).stringByDeletingLastPathComponent 81 | let directoryURL = NSURL(fileURLWithPath: directory) 82 | let elements = evaluateAndReplacePrintSwift(tableOfContents(elements) + deepApply(elements, { stripSampleImpl($0).flatMap(replaceOrError(directory)) }), workingDirectory: directoryURL) 83 | let prelude = "" 84 | let html = prelude + (Node(blocks: elements).html ?? "") + "" + restoreScrollTop 85 | webview.mainFrame.loadHTMLString(html, baseURL: nil) 86 | } 87 | 88 | override func viewDidAppear() { 89 | if let doc = view.window?.windowController?.document as? MarkdownDocument, let fileName = doc.fileURL?.path { 90 | 91 | let load = self.loadNode(fileName) 92 | doc.callbacks.append(load) 93 | load(elements: doc.elements) 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /LiterateSwift/SwiftViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftViewController.swift 3 | // LiterateSwift2 4 | // 5 | // Created by Chris Eidhof on 25/05/15. 6 | // Copyright (c) 2015 Unsigned Integer. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CommonMark 11 | import LiterateSwift 12 | 13 | class SwiftViewController: NSViewController { 14 | 15 | @IBOutlet var textview: NSTextView? 16 | 17 | func loadNode(elements: [Block]) { 18 | let text = (deepCollect(elements, { toArray(codeBlock($0, { $0 == "swift" || $0 == "print-swift" })) })).unlines() 19 | let attributes: [String: AnyObject] = [NSFontAttributeName: NSFont(name: "Monaco", size: 14)!] 20 | let attributedString = NSAttributedString(string: text, attributes: attributes) 21 | textview?.textStorage?.setAttributedString(attributedString) 22 | } 23 | 24 | override func viewDidAppear() { 25 | guard let doc = view.window?.windowController?.document as? MarkdownDocument else { return } 26 | doc.callbacks.append(self.loadNode) 27 | loadNode(doc.elements) 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, 10.9 2 | 3 | use_frameworks! 4 | 5 | pod 'CommonMark', '>= 0.0.5' 6 | pod 'LiterateSwift' 7 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - cmark (0.21.0) 3 | - CommonMark (0.0.6): 4 | - cmark (= 0.21) 5 | - LiterateSwift (0.0.11): 6 | - CommonMark (>= 0.0.3) 7 | 8 | DEPENDENCIES: 9 | - CommonMark (>= 0.0.5) 10 | - LiterateSwift 11 | 12 | SPEC CHECKSUMS: 13 | cmark: 0868ab0d93af82a0f3f4b69a313b5d2089af51c3 14 | CommonMark: d0f39c0c38ef0d857e6832c616672e96a2947eae 15 | LiterateSwift: a430ccf64362718a131bb4ee0646c768343704ca 16 | 17 | COCOAPODS: 0.38.2 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LiterateSwift is a (GUI) tool to edit your literate swift files. 2 | 3 | A literate swift file is written in CommonMark, written with fenced code blocks. A code block can be either of three things: swift, highlight-swift, or print-swift. 4 | 5 | A file is transformed like this: first, all `swift` code-blocks are assembled into one big swift file. Then, for every print-swift block, a new file is generated, containing the `swift` code blocks and the contents of that print-swift block. 6 | 7 | To install, just run `pod install`, it will install the dependencies (cmark, CommonMark and LiterateSwift). For `cmark`, you need to have `cmake` installed. All code is written using the latest Xcode (Xcode 7, Beta 4). 8 | 9 | ### Weaving 10 | 11 | Additionally, you can include snippets from other swift files in subdirectories (or the same directory). 12 | 13 | If you surround your code like this: 14 | 15 | // <> 16 | class View { 17 | var window: Window 18 | init(window: Window) { 19 | self.window = window 20 | } 21 | } 22 | class Window { 23 | var view: View? 24 | } 25 | // <> 26 | 27 | And put it in a file with the extension .swift, somewhere in the same directory as the markdown file (or a subdirectory), you can then include it in your Markdown file, inside a code block: 28 | 29 | ```highlight-swift 30 | <> 31 | ``` 32 | --------------------------------------------------------------------------------