diff --git a/CommonMark.xcodeproj/project.pbxproj b/CommonMark.xcodeproj/project.pbxproj index 5dfd002..c95f937 100644 --- a/CommonMark.xcodeproj/project.pbxproj +++ b/CommonMark.xcodeproj/project.pbxproj @@ -3,12 +3,22 @@ archiveVersion = "1"; objectVersion = "46"; objects = { + "CommonMark::Ccmark::ProductTarget" = { + isa = "PBXAggregateTarget"; + buildConfigurationList = "OBJ_25"; + buildPhases = ( + ); + dependencies = ( + ); + name = "Ccmark"; + productName = "Ccmark"; + }; "CommonMark::CommonMark" = { isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_17"; + buildConfigurationList = "OBJ_29"; buildPhases = ( - "OBJ_20", - "OBJ_24" + "OBJ_32", + "OBJ_37" ); dependencies = ( ); @@ -22,11 +32,42 @@ path = "CommonMark.framework"; sourceTree = "BUILT_PRODUCTS_DIR"; }; + "CommonMark::CommonMarkPackageTests::ProductTarget" = { + isa = "PBXAggregateTarget"; + buildConfigurationList = "OBJ_45"; + buildPhases = ( + ); + dependencies = ( + "OBJ_48" + ); + name = "CommonMarkPackageTests"; + productName = "CommonMarkPackageTests"; + }; + "CommonMark::CommonMarkTests" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_50"; + buildPhases = ( + "OBJ_53", + "OBJ_56" + ); + dependencies = ( + "OBJ_58" + ); + name = "CommonMarkTests"; + productName = "CommonMarkTests"; + productReference = "CommonMark::CommonMarkTests::Product"; + productType = "com.apple.product-type.bundle.unit-test"; + }; + "CommonMark::CommonMarkTests::Product" = { + isa = "PBXFileReference"; + path = "CommonMarkTests.xctest"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; "CommonMark::SwiftPMPackageDescription" = { isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_26"; + buildConfigurationList = "OBJ_39"; buildPhases = ( - "OBJ_29" + "OBJ_42" ); dependencies = ( ); @@ -37,6 +78,7 @@ "OBJ_1" = { isa = "PBXProject"; attributes = { + LastSwiftMigration = "9999"; LastUpgradeCheck = "9999"; }; buildConfigurationList = "OBJ_2"; @@ -47,58 +89,178 @@ "en" ); mainGroup = "OBJ_5"; - productRefGroup = "OBJ_14"; + productRefGroup = "OBJ_19"; projectDirPath = "."; targets = ( + "CommonMark::Ccmark::ProductTarget", "CommonMark::CommonMark", - "CommonMark::SwiftPMPackageDescription" + "CommonMark::SwiftPMPackageDescription", + "CommonMark::CommonMarkPackageTests::ProductTarget", + "CommonMark::CommonMarkTests" ); }; "OBJ_10" = { + isa = "PBXGroup"; + children = ( + "OBJ_11", + "OBJ_12", + "OBJ_13", + "OBJ_14" + ); + name = "CommonMark"; + path = "Sources/CommonMark"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_11" = { + isa = "PBXFileReference"; + path = "ASTOperations.swift"; + sourceTree = ""; + }; + "OBJ_12" = { isa = "PBXFileReference"; path = "Node.swift"; sourceTree = ""; }; - "OBJ_11" = { + "OBJ_13" = { + isa = "PBXFileReference"; + path = "Reduce.swift"; + sourceTree = ""; + }; + "OBJ_14" = { isa = "PBXFileReference"; path = "SwiftAST.swift"; sourceTree = ""; }; - "OBJ_12" = { + "OBJ_15" = { isa = "PBXGroup"; children = ( + "OBJ_16" ); name = "Tests"; path = ""; sourceTree = "SOURCE_ROOT"; }; - "OBJ_13" = { + "OBJ_16" = { isa = "PBXGroup"; children = ( + "OBJ_17", + "OBJ_18" ); - name = "Dependencies"; - path = ""; + name = "CommonMarkTests"; + path = "Tests/CommonMarkTests"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_17" = { + isa = "PBXFileReference"; + path = "CommonMarkTests.swift"; sourceTree = ""; }; - "OBJ_14" = { + "OBJ_18" = { + isa = "PBXFileReference"; + path = "XCTestManifests.swift"; + sourceTree = ""; + }; + "OBJ_19" = { isa = "PBXGroup"; children = ( + "CommonMark::CommonMarkTests::Product", "CommonMark::CommonMark::Product" ); name = "Products"; path = ""; sourceTree = "BUILT_PRODUCTS_DIR"; }; - "OBJ_17" = { + "OBJ_2" = { isa = "XCConfigurationList"; buildConfigurations = ( - "OBJ_18", - "OBJ_19" + "OBJ_3", + "OBJ_4" ); defaultConfigurationIsVisible = "0"; defaultConfigurationName = "Release"; }; - "OBJ_18" = { + "OBJ_22" = { + isa = "PBXFileReference"; + path = "Package.pins"; + sourceTree = ""; + }; + "OBJ_23" = { + isa = "PBXFileReference"; + path = "README.md"; + sourceTree = ""; + }; + "OBJ_25" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_26", + "OBJ_27" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_26" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Debug"; + }; + "OBJ_27" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Release"; + }; + "OBJ_29" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_30", + "OBJ_31" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_3" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = "YES"; + COMBINE_HIDPI_IMAGES = "YES"; + COPY_PHASE_STRIP = "NO"; + DEBUG_INFORMATION_FORMAT = "dwarf"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_NS_ASSERTIONS = "YES"; + GCC_OPTIMIZATION_LEVEL = "0"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE=1", + "DEBUG=1" + ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; + ONLY_ACTIVE_ARCH = "YES"; + OTHER_SWIFT_FLAGS = ( + "-DXcode" + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = "macosx"; + SUPPORTED_PLATFORMS = ( + "macosx", + "iphoneos", + "iphonesimulator", + "appletvos", + "appletvsimulator", + "watchos", + "watchsimulator" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE", + "DEBUG" + ); + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + USE_HEADERMAP = "NO"; + }; + name = "Debug"; + }; + "OBJ_30" = { isa = "XCBuildConfiguration"; buildSettings = { ENABLE_TESTABILITY = "YES"; @@ -108,25 +270,27 @@ ); HEADER_SEARCH_PATHS = ( "$(inherited)", - "$(SRCROOT)/.build/checkouts/Ccmark.git--1076946679408688698" + "$(SRCROOT)/Sources/Ccmark" ); INFOPLIST_FILE = "CommonMark.xcodeproj/CommonMark_Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = "8.0"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; OTHER_CFLAGS = ( "$(inherited)", - "-I/usr/local/Cellar/commonmark/0.25.2/include" + "-I/usr/local/include" ); OTHER_LDFLAGS = ( "$(inherited)", - "-L/usr/local/Cellar/commonmark/0.25.2/lib", + "-L/usr/local/lib", "-lcmark" ); OTHER_SWIFT_FLAGS = ( "$(inherited)", - "-I/usr/local/Cellar/commonmark/0.25.2/include" + "-I/usr/local/include" ); PRODUCT_BUNDLE_IDENTIFIER = "CommonMark"; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -135,12 +299,14 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( "$(inherited)" ); - SWIFT_VERSION = "4.2"; + SWIFT_VERSION = "5.0"; TARGET_NAME = "CommonMark"; + TVOS_DEPLOYMENT_TARGET = "9.0"; + WATCHOS_DEPLOYMENT_TARGET = "2.0"; }; name = "Debug"; }; - "OBJ_19" = { + "OBJ_31" = { isa = "XCBuildConfiguration"; buildSettings = { ENABLE_TESTABILITY = "YES"; @@ -150,25 +316,27 @@ ); HEADER_SEARCH_PATHS = ( "$(inherited)", - "$(SRCROOT)/.build/checkouts/Ccmark.git--1076946679408688698" + "$(SRCROOT)/Sources/Ccmark" ); INFOPLIST_FILE = "CommonMark.xcodeproj/CommonMark_Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = "8.0"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; OTHER_CFLAGS = ( "$(inherited)", - "-I/usr/local/Cellar/commonmark/0.25.2/include" + "-I/usr/local/include" ); OTHER_LDFLAGS = ( "$(inherited)", - "-L/usr/local/Cellar/commonmark/0.25.2/lib", + "-L/usr/local/lib", "-lcmark" ); OTHER_SWIFT_FLAGS = ( "$(inherited)", - "-I/usr/local/Cellar/commonmark/0.25.2/include" + "-I/usr/local/include" ); PRODUCT_BUNDLE_IDENTIFIER = "CommonMark"; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -177,61 +345,96 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( "$(inherited)" ); - SWIFT_VERSION = "4.2"; + SWIFT_VERSION = "5.0"; TARGET_NAME = "CommonMark"; + TVOS_DEPLOYMENT_TARGET = "9.0"; + WATCHOS_DEPLOYMENT_TARGET = "2.0"; }; name = "Release"; }; - "OBJ_2" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_3", - "OBJ_4" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_20" = { + "OBJ_32" = { isa = "PBXSourcesBuildPhase"; files = ( - "OBJ_21", - "OBJ_22", - "OBJ_23" + "OBJ_33", + "OBJ_34", + "OBJ_35", + "OBJ_36" ); }; - "OBJ_21" = { + "OBJ_33" = { isa = "PBXBuildFile"; - fileRef = "OBJ_9"; + fileRef = "OBJ_11"; }; - "OBJ_22" = { + "OBJ_34" = { isa = "PBXBuildFile"; - fileRef = "OBJ_10"; + fileRef = "OBJ_12"; }; - "OBJ_23" = { + "OBJ_35" = { isa = "PBXBuildFile"; - fileRef = "OBJ_11"; + fileRef = "OBJ_13"; }; - "OBJ_24" = { + "OBJ_36" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_14"; + }; + "OBJ_37" = { isa = "PBXFrameworksBuildPhase"; files = ( ); }; - "OBJ_26" = { + "OBJ_39" = { isa = "XCConfigurationList"; buildConfigurations = ( - "OBJ_27", - "OBJ_28" + "OBJ_40", + "OBJ_41" ); defaultConfigurationIsVisible = "0"; defaultConfigurationName = "Release"; }; - "OBJ_27" = { + "OBJ_4" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = "YES"; + COMBINE_HIDPI_IMAGES = "YES"; + COPY_PHASE_STRIP = "YES"; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = "s"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE=1" + ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; + OTHER_SWIFT_FLAGS = ( + "-DXcode" + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = "macosx"; + SUPPORTED_PLATFORMS = ( + "macosx", + "iphoneos", + "iphonesimulator", + "appletvos", + "appletvsimulator", + "watchos", + "watchsimulator" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE" + ); + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + USE_HEADERMAP = "NO"; + }; + name = "Release"; + }; + "OBJ_40" = { isa = "XCBuildConfiguration"; buildSettings = { LD = "/usr/bin/true"; OTHER_SWIFT_FLAGS = ( "-swift-version", - "4.2", + "5", "-I", "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", "-target", @@ -239,17 +442,17 @@ "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" ); - SWIFT_VERSION = "4.2"; + SWIFT_VERSION = "5.0"; }; name = "Debug"; }; - "OBJ_28" = { + "OBJ_41" = { isa = "XCBuildConfiguration"; buildSettings = { LD = "/usr/bin/true"; OTHER_SWIFT_FLAGS = ( "-swift-version", - "4.2", + "5", "-I", "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", "-target", @@ -257,102 +460,183 @@ "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" ); - SWIFT_VERSION = "4.2"; + SWIFT_VERSION = "5.0"; }; name = "Release"; }; - "OBJ_29" = { + "OBJ_42" = { isa = "PBXSourcesBuildPhase"; files = ( - "OBJ_30" + "OBJ_43" ); }; - "OBJ_3" = { + "OBJ_43" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_6"; + }; + "OBJ_45" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_46", + "OBJ_47" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_46" = { isa = "XCBuildConfiguration"; buildSettings = { - CLANG_ENABLE_OBJC_ARC = "YES"; - COMBINE_HIDPI_IMAGES = "YES"; - COPY_PHASE_STRIP = "NO"; - DEBUG_INFORMATION_FORMAT = "dwarf"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_NS_ASSERTIONS = "YES"; - GCC_OPTIMIZATION_LEVEL = "0"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)" + }; + name = "Debug"; + }; + "OBJ_47" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Release"; + }; + "OBJ_48" = { + isa = "PBXTargetDependency"; + target = "CommonMark::CommonMarkTests"; + }; + "OBJ_5" = { + isa = "PBXGroup"; + children = ( + "OBJ_6", + "OBJ_7", + "OBJ_15", + "OBJ_19", + "OBJ_22", + "OBJ_23" + ); + path = ""; + sourceTree = ""; + }; + "OBJ_50" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_51", + "OBJ_52" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_51" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_MODULES = "YES"; + EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "$(SRCROOT)/Sources/Ccmark" + ); + INFOPLIST_FILE = "CommonMark.xcodeproj/CommonMarkTests_Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = "8.0"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/../Frameworks", + "@loader_path/Frameworks" ); MACOSX_DEPLOYMENT_TARGET = "10.10"; - ONLY_ACTIVE_ARCH = "YES"; - OTHER_SWIFT_FLAGS = ( - "-DXcode" + OTHER_CFLAGS = ( + "$(inherited)", + "-I/usr/local/include" ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = "macosx"; - SUPPORTED_PLATFORMS = ( - "macosx", - "iphoneos", - "iphonesimulator", - "appletvos", - "appletvsimulator", - "watchos", - "watchsimulator" + OTHER_LDFLAGS = ( + "$(inherited)", + "-L/usr/local/lib", + "-lcmark" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)", + "-I/usr/local/include" ); SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "SWIFT_PACKAGE", - "DEBUG" + "$(inherited)" ); - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - USE_HEADERMAP = "NO"; + SWIFT_VERSION = "5.0"; + TARGET_NAME = "CommonMarkTests"; + TVOS_DEPLOYMENT_TARGET = "9.0"; + WATCHOS_DEPLOYMENT_TARGET = "2.0"; }; name = "Debug"; }; - "OBJ_30" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_6"; - }; - "OBJ_4" = { + "OBJ_52" = { isa = "XCBuildConfiguration"; buildSettings = { - CLANG_ENABLE_OBJC_ARC = "YES"; - COMBINE_HIDPI_IMAGES = "YES"; - COPY_PHASE_STRIP = "YES"; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_OPTIMIZATION_LEVEL = "s"; + CLANG_ENABLE_MODULES = "YES"; + EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "$(SRCROOT)/Sources/Ccmark" + ); + INFOPLIST_FILE = "CommonMark.xcodeproj/CommonMarkTests_Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = "8.0"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/../Frameworks", + "@loader_path/Frameworks" + ); MACOSX_DEPLOYMENT_TARGET = "10.10"; - OTHER_SWIFT_FLAGS = ( - "-DXcode" + OTHER_CFLAGS = ( + "$(inherited)", + "-I/usr/local/include" ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = "macosx"; - SUPPORTED_PLATFORMS = ( - "macosx", - "iphoneos", - "iphonesimulator", - "appletvos", - "appletvsimulator", - "watchos", - "watchsimulator" + OTHER_LDFLAGS = ( + "$(inherited)", + "-L/usr/local/lib", + "-lcmark" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)", + "-I/usr/local/include" ); SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "SWIFT_PACKAGE" + "$(inherited)" ); - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - USE_HEADERMAP = "NO"; + SWIFT_VERSION = "5.0"; + TARGET_NAME = "CommonMarkTests"; + TVOS_DEPLOYMENT_TARGET = "9.0"; + WATCHOS_DEPLOYMENT_TARGET = "2.0"; }; name = "Release"; }; - "OBJ_5" = { - isa = "PBXGroup"; - children = ( - "OBJ_6", - "OBJ_7", - "OBJ_12", - "OBJ_13", - "OBJ_14" + "OBJ_53" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_54", + "OBJ_55" ); - path = ""; - sourceTree = ""; + }; + "OBJ_54" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_17"; + }; + "OBJ_55" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_18"; + }; + "OBJ_56" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + "OBJ_57" + ); + }; + "OBJ_57" = { + isa = "PBXBuildFile"; + fileRef = "CommonMark::CommonMark::Product"; + }; + "OBJ_58" = { + isa = "PBXTargetDependency"; + target = "CommonMark::CommonMark"; }; "OBJ_6" = { isa = "PBXFileReference"; @@ -363,7 +647,8 @@ "OBJ_7" = { isa = "PBXGroup"; children = ( - "OBJ_8" + "OBJ_8", + "OBJ_10" ); name = "Sources"; path = ""; @@ -372,17 +657,15 @@ "OBJ_8" = { isa = "PBXGroup"; children = ( - "OBJ_9", - "OBJ_10", - "OBJ_11" + "OBJ_9" ); - name = "CommonMark"; - path = "Sources/CommonMark"; + name = "Ccmark"; + path = "Sources/Ccmark"; sourceTree = "SOURCE_ROOT"; }; "OBJ_9" = { isa = "PBXFileReference"; - path = "ASTOperations.swift"; + path = "module.modulemap"; sourceTree = ""; }; }; diff --git a/CommonMark.xcodeproj/xcshareddata/xcschemes/CommonMark-Package.xcscheme b/CommonMark.xcodeproj/xcshareddata/xcschemes/CommonMark-Package.xcscheme index a26dbab..34787e8 100644 --- a/CommonMark.xcodeproj/xcshareddata/xcschemes/CommonMark-Package.xcscheme +++ b/CommonMark.xcodeproj/xcshareddata/xcschemes/CommonMark-Package.xcscheme @@ -28,6 +28,16 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 8f9a492..0000000 --- a/Package.resolved +++ /dev/null @@ -1,16 +0,0 @@ -{ - "object": { - "pins": [ - { - "package": "Ccmark", - "repositoryURL": "https://github.com/objcio/Ccmark.git", - "state": { - "branch": "master", - "revision": "2d2002db33c3f077635538031008c6893a4c0ec2", - "version": null - } - } - ] - }, - "version": 1 -} diff --git a/Package.swift b/Package.swift index a0d7ee3..529e2d9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,16 +1,23 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.5 import PackageDescription let package = Package( name: "CommonMark", products: [ - .library(name: "CommonMark", targets: ["CommonMark"]) - ], - dependencies: [ - .package(url: "https://github.com/objcio/Ccmark.git", .branch("master")) + .library(name: "CommonMark", targets: ["CommonMark"]), + .library(name: "Ccmark", targets: ["Ccmark"]), + ], + dependencies: [], targets: [ - .target(name: "CommonMark") + .target(name: "CommonMark", dependencies: ["Ccmark"]), + .systemLibrary( + name: "Ccmark", + pkgConfig: "libcmark", + providers: [ + .brew(["commonmark"]) + ]), + .testTarget(name: "CommonMarkTests", dependencies: ["CommonMark"]), ] ) diff --git a/Sources/Ccmark/module.modulemap b/Sources/Ccmark/module.modulemap new file mode 100644 index 0000000..fd0db12 --- /dev/null +++ b/Sources/Ccmark/module.modulemap @@ -0,0 +1,5 @@ +module Ccmark [system] { + header "/usr/local/include/cmark.h" + link "libcmark" + export * +} diff --git a/Sources/CommonMark/Node.swift b/Sources/CommonMark/Node.swift index 71abe48..1d82a8e 100644 --- a/Sources/CommonMark/Node.swift +++ b/Sources/CommonMark/Node.swift @@ -9,7 +9,9 @@ import Foundation import Ccmark -func markdownToHtml(string: String) -> String { + + +func markdowntoHTML(string: String) -> String { let outString = cmark_markdown_to_html(string, string.utf8.count, 0)! defer { free(outString) } return String(cString: outString) @@ -29,12 +31,49 @@ struct Markdown { } extension String { - init?(unsafeCString: UnsafePointer!) { + // We're going through Data instead of using init(cstring:) because that leaks memory on Linux. + + init?(unsafeCString: UnsafePointer!) { guard let cString = unsafeCString else { return nil } - self.init(cString: cString) + let data = cString.withMemoryRebound(to: UInt8.self, capacity: strlen(cString), { p in + return Data(UnsafeBufferPointer(start: p, count: strlen(cString))) + }) + self.init(data: data, encoding: .utf8) } + + init?(freeingCString str: UnsafeMutablePointer?) { + guard let cString = str else { return nil } + let data = cString.withMemoryRebound(to: UInt8.self, capacity: strlen(cString), { p in + return Data(UnsafeBufferPointer(start: p, count: strlen(cString))) + }) + str?.deallocate() + self.init(data: data, encoding: .utf8) + } +} + +/// A position in a Markdown document. Note that both `line` and `column` are 1-based. +public struct Position { + public var line: Int32 + public var column: Int32 } +public struct RenderingOptions: OptionSet { + public var rawValue: Int32 + public init(rawValue: Int32 = CMARK_OPT_DEFAULT) { + self.rawValue = rawValue + } + + static public let sourcePos = RenderingOptions(rawValue: CMARK_OPT_SOURCEPOS) + static public let hardBreaks = RenderingOptions(rawValue: CMARK_OPT_HARDBREAKS) + static public let safe = RenderingOptions(rawValue: CMARK_OPT_SAFE) + static public let unsafe = RenderingOptions(rawValue: CMARK_OPT_UNSAFE) + static public let noBreaks = RenderingOptions(rawValue: CMARK_OPT_NOBREAKS) + static public let normalize = RenderingOptions(rawValue: CMARK_OPT_NORMALIZE) + static public let validateUTF8 = RenderingOptions(rawValue: CMARK_OPT_VALIDATE_UTF8) + static public let smart = RenderingOptions(rawValue: CMARK_OPT_SMART) +} + + /// A node in a Markdown document. /// /// Can represent a full Markdown document (i.e. the document's root node) or @@ -47,13 +86,14 @@ public class Node: CustomStringConvertible { } public init?(filename: String) { - guard let node = cmark_parse_file(fopen(filename, "r"), 0) else { return nil } + guard let file = fopen(filename, "r"), + let node = cmark_parse_file(file, 0) else { return nil } self.node = node } - public init?(markdown: String) { + public init(markdown: String) { guard let node = cmark_parse_document(markdown, markdown.utf8.count, 0) else { - return nil + fatalError("cmark_parse_document returned NULL. Should never happen.") } self.node = node } @@ -63,25 +103,25 @@ public class Node: CustomStringConvertible { cmark_node_free(node) } - var type: cmark_node_type { + public var type: cmark_node_type { return cmark_node_get_type(node) } - var listType: cmark_list_type { + public var listType: cmark_list_type { get { return cmark_node_get_list_type(node) } set { cmark_node_set_list_type(node, newValue) } } - var listStart: Int { + public var listStart: Int { get { return Int(cmark_node_get_list_start(node)) } set { cmark_node_set_list_start(node, Int32(newValue)) } } - var typeString: String { - return String(cString: cmark_node_get_type_string(node)!) + public var typeString: String { + return String(unsafeCString: cmark_node_get_type_string(node)) ?? "" } - var literal: String? { + public var literal: String? { get { return String(unsafeCString: cmark_node_get_literal(node)) } set { if let value = newValue { @@ -92,12 +132,19 @@ public class Node: CustomStringConvertible { } } - var headerLevel: Int { + public var start: Position { + return Position(line: cmark_node_get_start_line(node), column: cmark_node_get_start_column(node)) + } + public var end: Position { + return Position(line: cmark_node_get_end_line(node), column: cmark_node_get_end_column(node)) + } + + public var headerLevel: Int { get { return Int(cmark_node_get_heading_level(node)) } set { cmark_node_set_heading_level(node, Int32(newValue)) } } - var fenceInfo: String? { + public var fenceInfo: String? { get { return String(unsafeCString: cmark_node_get_fence_info(node)) } set { @@ -109,7 +156,7 @@ public class Node: CustomStringConvertible { } } - var urlString: String? { + public var urlString: String? { get { return String(unsafeCString: cmark_node_get_url(node)) } set { if let value = newValue { @@ -120,7 +167,7 @@ public class Node: CustomStringConvertible { } } - var title: String? { + public var title: String? { get { return String(unsafeCString: cmark_node_get_title(node)) } set { if let value = newValue { @@ -131,7 +178,7 @@ public class Node: CustomStringConvertible { } } - var children: [Node] { + public var children: [Node] { var result: [Node] = [] var child = cmark_node_first_child(node) @@ -143,23 +190,25 @@ public class Node: CustomStringConvertible { } /// Renders the HTML representation - public var html: String { - return String(cString: cmark_render_html(node, 0)) + /// + + public func html(options: RenderingOptions = RenderingOptions()) -> String { + return String(freeingCString: cmark_render_html(node, options.rawValue)) ?? "" } /// Renders the XML representation - public var xml: String { - return String(cString: cmark_render_xml(node, 0)) + public func xml(options: RenderingOptions = RenderingOptions()) -> String { + return String(freeingCString: cmark_render_xml(node, options.rawValue)) ?? "" } /// Renders the CommonMark representation - public var commonMark: String { - return String(cString: cmark_render_commonmark(node, CMARK_OPT_DEFAULT, 80)) + public func commonMark(options: RenderingOptions = RenderingOptions()) -> String { + return String(freeingCString: cmark_render_commonmark(node, options.rawValue, 80)) ?? "" } /// Renders the LaTeX representation - public var latex: String { - return String(cString: cmark_render_latex(node, CMARK_OPT_DEFAULT, 80)) + public func latex(options: RenderingOptions = RenderingOptions()) -> String { + return String(freeingCString: cmark_render_latex(node, options.rawValue, 80)) ?? "" } public var description: String { diff --git a/Sources/CommonMark/Reduce.swift b/Sources/CommonMark/Reduce.swift new file mode 100644 index 0000000..3bfd8a5 --- /dev/null +++ b/Sources/CommonMark/Reduce.swift @@ -0,0 +1,112 @@ +// +// Reduce.swift +// CommonMark +// +// Created by Chris Eidhof on 02.04.19. +// + +import Foundation +import Ccmark + +/// An algebra for a block-level element +public struct InlineAlgebra { + public var text: (_ text: String) -> A + public var softBreak: A + public var lineBreak: A + public var code: (_ text: String) -> A + public var html: (_ text: String) -> A + public var emphasis: (_ children: [A]) -> A + public var strong: (_ children: [A]) -> A + public var custom: (_ literal: String) -> A + public var link: (_ children: [A], _ title: String?, _ url: String?) -> A + public var image: (_ children: [A], _ title: String?, _ url: String?) -> A +} + +/// An algebra for a block-level element +public struct BlockAlgebra { + public var inline: InlineAlgebra + public var list: (_ items: [A], _ type: ListType) -> A + public var listItem: (_ children: [A]) -> A + public var blockQuote: (_ items: [A]) -> A + public var codeBlock: (_ text: String, _ language: String?) -> A + public var html: (_ text: String) -> A + public var paragraph: (_ text: [A]) -> A + public var heading: (_ text: [A], _ level: Int) -> A + public var custom: (_ literal: String) -> A + public var thematicBreak: A + public var document: (_ children: [A]) -> A + public var defaultValue: A +} + +extension Node { + public func reduce(_ b: BlockAlgebra) -> R { + func r(_ node: Node) -> R { + var children: [R] { return node.children.map(r) } + var lit: String { return node.literal ?? "" } + switch node.type { + case CMARK_NODE_DOCUMENT: return b.document(children) + case CMARK_NODE_BLOCK_QUOTE: return b.blockQuote(children) + case CMARK_NODE_LIST: return b.list(children, node.listType == CMARK_BULLET_LIST ? .unordered : .ordered) + case CMARK_NODE_ITEM: return b.listItem(children) + case CMARK_NODE_CODE_BLOCK: return b.codeBlock(lit, node.fenceInfo) + case CMARK_NODE_HTML_BLOCK: return b.html(lit) + case CMARK_NODE_CUSTOM_BLOCK: return b.custom(lit) + case CMARK_NODE_PARAGRAPH: return b.paragraph(children) + case CMARK_NODE_HEADING: return b.heading(children, node.headerLevel) + case CMARK_NODE_THEMATIC_BREAK: return b.thematicBreak + case CMARK_NODE_FIRST_BLOCK: return b.defaultValue + case CMARK_NODE_LAST_BLOCK: return b.defaultValue + + /* Inline */ + case CMARK_NODE_TEXT: return b.inline.text(lit) + case CMARK_NODE_SOFTBREAK: return b.inline.softBreak + case CMARK_NODE_LINEBREAK: return b.inline.lineBreak + case CMARK_NODE_CODE: return b.inline.code(lit) + case CMARK_NODE_HTML_INLINE: return b.inline.html(lit) + case CMARK_NODE_CUSTOM_INLINE: return b.inline.custom(lit) + case CMARK_NODE_EMPH: return b.inline.emphasis(children) + case CMARK_NODE_STRONG: return b.inline.strong(children) + case CMARK_NODE_LINK: return b.inline.link(children, node.title, node.urlString) + case CMARK_NODE_IMAGE: return b.inline.image(children, node.title, node.urlString) + default: + return b.defaultValue + } + } + return r(self) + } +} + +public protocol Monoid { + init() + static func +(lhs: Self, rhs: Self) -> Self + mutating func append(_ value: Self) +} + +extension Monoid { + public mutating func append(_ value: Self) { + self = self + value + } +} + +extension Array: Monoid { } + +extension Array where Element: Monoid { + public func flatten() -> Element { + return reduce(into: .init(), { $0.append($1) }) + } +} + +extension String: Monoid { } + +/// This collects all elements into a result `M`. +/// +/// For example, to collect all links in a document: +/// +/// var links: BlockAlgebra<[String]> = collect() +/// links.inline.link = { _, _, url in url.map { [$0] } ?? [] } +/// let allLinks = Node(markdown: string)!.reduce(links) +public func collect() -> BlockAlgebra { + let inline: InlineAlgebra = InlineAlgebra(text: { _ in .init() }, softBreak: .init(), lineBreak: .init(), code: { _ in .init()}, html: { _ in .init() }, emphasis: { $0.flatten() }, strong: { $0.flatten() }, custom: { _ in .init() }, link: { x,_,_ in x.flatten() }, image: { x,_, _ in x.flatten() }) + + return BlockAlgebra(inline: inline, list: { x, _ in x.flatten() }, listItem: { $0.flatten() }, blockQuote: { $0.flatten() }, codeBlock: { _,_ in .init() }, html: { _ in .init() }, paragraph: { $0.flatten() }, heading: { x,_ in x.flatten() }, custom: { _ in .init() }, thematicBreak: .init(), document: { $0.flatten() }, defaultValue: .init()) +} diff --git a/Sources/CommonMark/SwiftAST.swift b/Sources/CommonMark/SwiftAST.swift index f25174e..6de8480 100644 --- a/Sources/CommonMark/SwiftAST.swift +++ b/Sources/CommonMark/SwiftAST.swift @@ -11,8 +11,8 @@ import Ccmark /// The type of a list in Markdown, represented by `Block.List`. public enum ListType { - case Unordered - case Ordered + case unordered + case ordered } /// An inline element in a Markdown abstract syntax tree. @@ -25,8 +25,8 @@ public enum Inline { case emphasis(children: [Inline]) case strong(children: [Inline]) case custom(literal: String) - case link(children: [Inline], title: String?, url: String?) - case image(children: [Inline], title: String?, url: String?) + case link(children: [Inline], title: String?, url: String) + case image(children: [Inline], title: String?, url: String) } extension Inline: ExpressibleByStringLiteral { @@ -96,7 +96,7 @@ extension Block { case CMARK_NODE_BLOCK_QUOTE: self = .blockQuote(items: parseBlockChildren()) case CMARK_NODE_LIST: - let type = node.listType == CMARK_BULLET_LIST ? ListType.Unordered : ListType.Ordered + let type = node.listType == CMARK_BULLET_LIST ? ListType.unordered : ListType.ordered self = .list(items: node.children.map { $0.listItem }, type: type) case CMARK_NODE_CODE_BLOCK: self = .codeBlock(text: node.literal!, language: node.fenceInfo) @@ -158,12 +158,12 @@ extension Node { /// The abstract syntax tree representation of a Markdown document. /// - returns: an array of block-level elements. public var elements: [Block] { - return children.map(Block.init) + children.map(Block.init) } } func tableOfContents(document: String) -> [Block] { - let blocks = Node(markdown: document)?.children.map(Block.init) ?? [] + let blocks = Node(markdown: document).children.map(Block.init) return blocks.filter { switch $0 { case .heading(_, let level) where level < 3: return true @@ -211,7 +211,7 @@ extension Node { case let .list(items, type): let listItems = items.map { Node(type: CMARK_NODE_ITEM, blocks: $0) } self.init(type: CMARK_NODE_LIST, children: listItems) - listType = type == .Unordered ? CMARK_BULLET_LIST : CMARK_ORDERED_LIST + listType = type == .unordered ? CMARK_BULLET_LIST : CMARK_ORDERED_LIST case .blockQuote(let items): self.init(type: CMARK_NODE_BLOCK_QUOTE, blocks: items) case let .codeBlock(text, language): diff --git a/Tests/CommonMarkTests/CommonMarkTests.swift b/Tests/CommonMarkTests/CommonMarkTests.swift index 09795b5..a07b599 100644 --- a/Tests/CommonMarkTests/CommonMarkTests.swift +++ b/Tests/CommonMarkTests/CommonMarkTests.swift @@ -12,14 +12,14 @@ class CommonMarkTests: XCTestCase { func testMarkdownToHTML() { let markdown = "*Hello World*" - let html = markdownToHtml(string: markdown) + let html = markdowntoHTML(string: markdown) XCTAssertEqual(html, "

Hello World

\n") } func testMarkdownToNode() { let markdown = "*Hello World*" let rootNode = Node(markdown: markdown) - XCTAssertNotNil(rootNode) + XCTAssertEqual(rootNode.elements.count, 1) } func testMarkdownToArrayOfBlocks() { @@ -33,8 +33,14 @@ class CommonMarkTests: XCTestCase { * List item 1 * List item 2 """ - let rootNode = Node(markdown: markdown)! + let rootNode = Node(markdown: markdown) let blocks = rootNode.elements XCTAssertEqual(blocks.count, 4) } + + func testReadMarkdownFromNonInvalidFilenameReturnsNil() { + let nonExistentFilename = "/lkjhgfdsa" + let rootNode = Node(filename: nonExistentFilename) + XCTAssertNil(rootNode) + } } diff --git a/Tests/CommonMarkTests/XCTestManifests.swift b/Tests/CommonMarkTests/XCTestManifests.swift new file mode 100644 index 0000000..b7cd9f5 --- /dev/null +++ b/Tests/CommonMarkTests/XCTestManifests.swift @@ -0,0 +1,21 @@ +#if !canImport(ObjectiveC) +import XCTest + +extension CommonMarkTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__CommonMarkTests = [ + ("testMarkdownToArrayOfBlocks", testMarkdownToArrayOfBlocks), + ("testMarkdownToHTML", testMarkdownToHTML), + ("testMarkdownToNode", testMarkdownToNode), + ("testReadMarkdownFromNonInvalidFilenameReturnsNil", testReadMarkdownFromNonInvalidFilenameReturnsNil), + ] +} + +public func __allTests() -> [XCTestCaseEntry] { + return [ + testCase(CommonMarkTests.__allTests__CommonMarkTests), + ] +} +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..20912dc --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,8 @@ +import XCTest + +import CommonMarkTests + +var tests = [XCTestCaseEntry]() +tests += CommonMarkTests.__allTests() + +XCTMain(tests)