Skip to content

Commit c057bf1

Browse files
committed
Encode predefined XML entities also for code blocks in HTML generator.
1 parent 5a5bf00 commit c057bf1

File tree

10 files changed

+28
-9
lines changed

10 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.1.3 (2022-02-07)
4+
- Fix build breakage for Linux
5+
- Encode predefined XML entities also for code blocks
6+
- Migrate framework to Xcode 13
7+
38
## 1.1.2 (2021-06-30)
49
- Allow creation of definition lists outside of MarkdownKit
510

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// `swift test`
1414
//
1515
// Created by Matthias Zenger on 09/08/2019.
16-
// Copyright © 2019-2021 Google LLC.
16+
// Copyright © 2019-2022 Google LLC.
1717
//
1818
// Licensed under the Apache License, Version 2.0 (the "License");
1919
// you may not use this file except in compliance with the License.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,5 +376,5 @@ _Swift Package Manager_ is not needed.
376376
## Copyright
377377

378378
Author: Matthias Zenger (<matthias@objecthub.net>)
379-
Copyright © 2019-2021 Google LLC.
379+
Copyright © 2019-2022 Google LLC.
380380
_Please note: This is not an official Google product._

Sources/MarkdownKit/CustomBlock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public protocol CustomBlock: CustomStringConvertible, CustomDebugStringConvertib
2828
func equals(to other: CustomBlock) -> Bool
2929
func parse(via parser: InlineParser) -> Block
3030
func generateHtml(via htmlGen: HtmlGenerator, tight: Bool) -> String
31-
#if !os(Linux)
31+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
3232
func generateHtml(via htmlGen: HtmlGenerator,
3333
and attGen: AttributedStringGenerator?,
3434
tight: Bool) -> String

Sources/MarkdownKit/CustomTextFragment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public protocol CustomTextFragment: CustomStringConvertible, CustomDebugStringCo
2828
func equals(to other: CustomTextFragment) -> Bool
2929
func transform(via transformer: InlineTransformer) -> TextFragment
3030
func generateHtml(via htmlGen: HtmlGenerator) -> String
31-
#if !os(Linux)
31+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
3232
func generateHtml(via htmlGen: HtmlGenerator, and attrGen: AttributedStringGenerator?) -> String
3333
#endif
3434
var rawDescription: String { get }

Sources/MarkdownKit/HTML/HtmlGenerator.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,18 @@ open class HtmlGenerator {
7575
let tag = "h\(n > 0 && n < 7 ? n : 1)>"
7676
return "<\(tag)\(self.generate(text: text))</\(tag)\n"
7777
case .indentedCode(let lines):
78-
return "<pre><code>" + self.generate(lines: lines) + "</code></pre>\n"
78+
return "<pre><code>" +
79+
self.generate(lines: lines).encodingPredefinedXmlEntities() +
80+
"</code></pre>\n"
7981
case .fencedCode(let lang, let lines):
8082
if let language = lang {
8183
return "<pre><code class=\"\(language)\">" +
82-
self.generate(lines: lines, separator: "") +
84+
self.generate(lines: lines, separator: "").encodingPredefinedXmlEntities() +
8385
"</code></pre>\n"
8486
} else {
85-
return "<pre><code>" + self.generate(lines: lines, separator: "") + "</code></pre>\n"
87+
return "<pre><code>" +
88+
self.generate(lines: lines, separator: "").encodingPredefinedXmlEntities() +
89+
"</code></pre>\n"
8690
}
8791
case .htmlBlock(let lines):
8892
return self.generate(lines: lines)

Sources/MarkdownKit/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>
22-
<string>Copyright © 2019-2021 Google LLC.</string>
22+
<string>Copyright © 2019-2022 Google LLC.</string>
2323
</dict>
2424
</plist>

Tests/MarkdownKitTests/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.4</string>
18+
<string>1.1.3</string>
1919
<key>CFBundleVersion</key>
2020
<string>1</string>
2121
</dict>

Tests/MarkdownKitTests/MarkdownBlockTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ class MarkdownBlockTests: XCTestCase, MarkdownKitFactory {
141141
indentedCode(" foo\n", "bar\n"),
142142
paragraph("goo"),
143143
paragraph("two")))
144+
XCTAssertEqual(parseBlocks("one\n\n \n <b>foo</b>\n <i>bar</i>\n \n\n\ntwo"),
145+
document(paragraph("one"),
146+
indentedCode("<b>foo</b>\n", "<i>bar</i>\n"),
147+
paragraph("two")))
144148
}
145149

146150
func testListItem() {

Tests/MarkdownKitTests/MarkdownHtmlTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class MarkdownHtmlTests: XCTestCase, MarkdownKitFactory {
9696
"<p>Test <a href=\"http://www.example.com\">http://www.example.com</a> test</p>")
9797
}
9898

99+
func testCodeBlocks() {
100+
XCTAssertEqual(generateHtml("Test\n\n```\nThis should <b>not be bold</b>.\n```\n"),
101+
"<p>Test</p>\n<pre><code>This should &lt;b&gt;not be bold&lt;/b&gt;.\n" +
102+
"</code></pre>")
103+
}
104+
99105
static let allTests = [
100106
("testBasics", testBasics),
101107
("testLists", testLists),

0 commit comments

Comments
 (0)