Skip to content

Commit 3de7eeb

Browse files
committed
fix: Fixed code block titles contained a dash
1 parent abf4122 commit 3de7eeb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/Parsley/Parsley.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private extension Parsley {
9595
/// Transforms: <pre><code class="language-xxx">&lt;!--code-title:filename--&gt;\n
9696
/// Into: <pre data-title="filename"><code class="language-xxx">
9797
static func processCodeTitleComments(_ html: String) -> String {
98-
let pattern = #"<pre><code([^>]*)>&lt;!--code-title:([^-]+)--&gt;\n"#
98+
let pattern = #"<pre><code([^>]*)>&lt;!--code-title:(.+?)--&gt;\n"#
9999
guard let regex = try? NSRegularExpression(pattern: pattern) else { return html }
100100
return regex.stringByReplacingMatches(
101101
in: html,

Tests/ParsleyTests/ParsleyTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ function test() {}
181181
XCTAssertEqual(markdown.body, expectedOutput)
182182
}
183183

184+
func testFencedCodeBlockWithTitleContainingDashes() throws {
185+
let input = """
186+
```nginx title="/etc/nginx/sites-enabled/deploy.example.com"
187+
server {
188+
listen 80;
189+
}
190+
```
191+
"""
192+
let expectedOutput = """
193+
<pre data-title="/etc/nginx/sites-enabled/deploy.example.com"><code class="language-nginx">server {
194+
listen 80;
195+
}
196+
</code></pre>
197+
"""
198+
199+
let markdown = try Parsley.parse(input)
200+
XCTAssertEqual(markdown.body, expectedOutput)
201+
}
202+
184203
func testFencedCodeBlockWithoutTitle() throws {
185204
let input = """
186205
```python
@@ -254,6 +273,7 @@ def test():
254273
("testFencedCodeBlock", testFencedCodeBlock),
255274
("testFencedCodeBlockWithTitle", testFencedCodeBlockWithTitle),
256275
("testFencedCodeBlockWithTitleAndPath", testFencedCodeBlockWithTitleAndPath),
276+
("testFencedCodeBlockWithTitleContainingDashes", testFencedCodeBlockWithTitleContainingDashes),
257277
("testFencedCodeBlockWithoutTitle", testFencedCodeBlockWithoutTitle),
258278
("testSmartQuotesOff", testSmartQuotesOff),
259279
("testSmartQuotesOn", testSmartQuotesOn),

0 commit comments

Comments
 (0)