diff --git a/Sources/DocCArchive/Schema_0_1/Content/CodeListing.swift b/Sources/DocCArchive/Schema_0_1/Content/CodeListing.swift index 510975d..a444548 100644 --- a/Sources/DocCArchive/Schema_0_1/Content/CodeListing.swift +++ b/Sources/DocCArchive/Schema_0_1/Content/CodeListing.swift @@ -9,12 +9,14 @@ extension DocCArchive.DocCSchema_0_1.Content { public struct CodeListing: Equatable, CustomStringConvertible, Codable { - public var syntax : String + public var syntax : String? public var code : [ String ] public var description: String { - return syntax.isEmpty ? "" - : "" + guard let syntax = syntax, !syntax.isEmpty else { + return "" + } + return "" } } } diff --git a/Sources/DocCArchive/Schema_0_1/Content/Content.swift b/Sources/DocCArchive/Schema_0_1/Content/Content.swift index 84c55f7..a811f41 100644 --- a/Sources/DocCArchive/Schema_0_1/Content/Content.swift +++ b/Sources/DocCArchive/Schema_0_1/Content/Content.swift @@ -15,6 +15,10 @@ extension DocCArchive.DocCSchema_0_1 { public enum Style: String, Codable { case note + case warning + case important + case tip + case experiment } public struct Item: Equatable, Codable { diff --git a/Sources/DocCArchive/Schema_0_1/InlineContent.swift b/Sources/DocCArchive/Schema_0_1/InlineContent.swift index 84ddfc2..0c6e7b8 100644 --- a/Sources/DocCArchive/Schema_0_1/InlineContent.swift +++ b/Sources/DocCArchive/Schema_0_1/InlineContent.swift @@ -18,6 +18,7 @@ extension DocCArchive.DocCSchema_0_1 { overridingTitleInlineContent : [ InlineContent ]?) case image (identifier: String) case emphasis ([ InlineContent ]) + case strong ([ InlineContent ]) case codeVoice(code: String) public var description: String { @@ -27,6 +28,7 @@ extension DocCArchive.DocCSchema_0_1 { return "\(id)\(isActive ? "" : "-inactive")" case .image (let id) : return "" case .emphasis (let content) : return "*\(content)*" + case .strong (let content) : return "**\(content)**" case .codeVoice(let code) : return "`\(code)`" } } @@ -54,6 +56,9 @@ extension DocCArchive.DocCSchema_0_1 { case "emphasis": self = .emphasis(try container.decode([ InlineContent ].self, forKey: .inlineContent)) + case "strong": + self = .strong(try container.decode([ InlineContent ].self, + forKey: .inlineContent)) case "reference": self = .reference( identifier: @@ -90,6 +95,9 @@ extension DocCArchive.DocCSchema_0_1 { case .emphasis(let content): try container.encode("emphasis" , forKey: .type) try container.encode(content , forKey: .inlineContent) + case .strong(let content): + try container.encode("strong" , forKey: .type) + try container.encode(content , forKey: .inlineContent) case .reference(let identifier, let isActive, let ot, let otc): try container.encode("reference" , forKey: .type) try container.encode(identifier , forKey: .identifier) diff --git a/Tests/DocCArchiveTests/DocumentDecodingTests.swift b/Tests/DocCArchiveTests/DocumentDecodingTests.swift index 3f81df8..ef9d5a8 100644 --- a/Tests/DocCArchiveTests/DocumentDecodingTests.swift +++ b/Tests/DocCArchiveTests/DocumentDecodingTests.swift @@ -18,9 +18,40 @@ final class DocumentDecodingTests: XCTestCase { ( "testIssue10FailTypeMethodRoleHeading", testIssue10FailTypeMethodRoleHeading ), ( "testIssue11FailUnorderedList" , testIssue11FailUnorderedList ), - ( "testAllDataJSONInSlothCreator" , testAllDataJSONInSlothCreator ) + ( "testAllDataJSONInSlothCreator" , testAllDataJSONInSlothCreator ), + ( "testIssue12FailAsideWarningStyle", testIssue12FailAsideWarningStyle ) ] - + + func testIssue12FailAsideWarningStyle() throws { + let url = Fixtures.baseURL.appendingPathComponent("Issue12Fail.json") + let data = try Data(contentsOf: url) + + let document : DocCArchive.Document + + print("Decoding:", url.path) + do { + document = try JSONDecoder().decode(DocCArchive.Document.self, from: data) + + guard let section = document.primaryContentSections?.first else { + XCTAssert(false, "did not find primary content section"); return + } + guard case .content(let contents) = section.kind else { + XCTAssert(false, "did not find content section"); return + } + guard case .aside(style: let style, content: let asideContents) = contents.dropFirst().first else { + XCTAssert(false, "did not find aside"); return + } + XCTAssertEqual(style, .warning, "expected to find warning") + XCTAssert(asideContents.count == 1) + } + catch { + print("ERROR:", error) + XCTAssert(false, "failed to decode: \(error)") + return + } + XCTAssertEqual(document.schemaVersion, .init(major: 0, minor: 1, patch: 0)) + } + func testIssue11FailUnorderedList() throws { let url = Fixtures.baseURL.appendingPathComponent("Issue11Fail.json") let data = try Data(contentsOf: url) diff --git a/Tests/DocCArchiveTests/Fixtures/Issue12Fail.json b/Tests/DocCArchiveTests/Fixtures/Issue12Fail.json new file mode 100644 index 0000000..1cdf609 --- /dev/null +++ b/Tests/DocCArchiveTests/Fixtures/Issue12Fail.json @@ -0,0 +1,61 @@ +{ + "primaryContentSections": [ + { + "kind": "content", + "content": [ + { + "anchor": "discussion", + "level": 2, + "type": "heading", + "text": "Discussion" + }, + { + "type": "aside", + "style": "warning", + "content": [ + { + "type": "paragraph", + "inlineContent": [ + { + "type": "text", + "text": "Values above " + }, + { + "type": "codeVoice", + "code": "99" + }, + { + "type": "text", + "text": " will be shown as " + }, + { + "type": "codeVoice", + "code": "99+" + }, + { + "type": "text", + "text": "." + } + ] + } + ] + } + ] + } + ], + "schemaVersion":{"major":0,"minor":1,"patch":0}, + "identifier":{ + "url":"doc://ARI/documentation/Fail12", + "interfaceLanguage":"swift" + }, + "kind":"symbol", + "metadata": { + "title": "And then she kissed her", + "categoryPathComponent": "Songs", + "role": "project", + "category": "Songs" + }, + "hierarchy":{ "paths":[] }, + "sections":[], + "references":{} +}