Skip to content

Commit

Permalink
Fix indented code blocks (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo authored Oct 7, 2024
1 parent 88a490c commit 27d0baa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
23 changes: 23 additions & 0 deletions features/codeblock_indented.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: indented codeblock

Background:
Given file "1.md" with content:
"""
# Title
[Two](2.md)
- point 1
```go
result := map[^0]
```
"""
And file "2.md" with content:
"""
# Two
[One](1.md)
"""

Scenario: check
When checking
Then it finds no issues
21 changes: 21 additions & 0 deletions features/codeblock_toplevel.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: top-level codeblock

Background:
Given file "1.md" with content:
"""
# Title
[Two](2.md)
```go
result := map[^0]
```
"""
And file "2.md" with content:
"""
# Two
[One](1.md)
"""

Scenario: check
When checking
Then it finds no issues
3 changes: 2 additions & 1 deletion src/database/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static MD_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(!?)\[[^\]]*\]\(([^)]*)\)"
static A_HTML_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"<a href="(.*)">(.*)</a>"#).unwrap());
static IMG_HTML_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"<img src="([^"]*)"[^>]*>"#).unwrap());
static FOOTNOTE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\[\^([\w-]+)\](:?)").unwrap());
static CODEBLOCK_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^\s*```").unwrap());

impl Line {
/// appends all footnote definitions and references to the given result structure
Expand Down Expand Up @@ -44,7 +45,7 @@ impl Line {

/// indicates whether this line is the beginning or end of a code block
pub fn is_code_block_boundary(&self) -> bool {
self.text.starts_with("```")
CODEBLOCK_RE.is_match(&self.text)
}

/// populates the given accumulator with all links and images in this line
Expand Down

0 comments on commit 27d0baa

Please sign in to comment.