Skip to content

Commit

Permalink
headings: headings can have up to 3 leading whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Apr 25, 2024
1 parent 742ed5d commit 7f408d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ pub fn shift_headings(raw: &str, levels: usize) -> String {
}
}

if curr_fence.is_none() && raw_line.starts_with('#') {
let heading = handle_heading(raw_line, levels);
let heading_line = &trim_leading_whitespace(raw_line, 3);
if curr_fence.is_none() && heading_line.starts_with('#') {
let heading = handle_heading(heading_line, levels);
result.push_str(&heading);
} else {
result.push_str(raw_line);
Expand Down Expand Up @@ -145,7 +146,6 @@ pub fn get_fence(line: &str, allow_info: bool) -> Option<(usize, char)> {
pub fn handle_heading(line: &str, levels: usize) -> String {
let chars = line.chars();

// let mut leading_trivials: String = String::new();
let mut hashes = String::new();
let mut rest = String::new();
for char in chars {
Expand Down
14 changes: 14 additions & 0 deletions src/snapshots/nixdoc__test__headings.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ expression: output

#### h2-heading

3 leading whitespaces are okay for headings

#### h2 heading

# code block


#### h2-heading-with-id {#some-id}

Indented code block

# Code comment
a = 1;

##### h3-heading

```nix
Expand All @@ -23,6 +35,8 @@ map a from b -> 1

##### indented (0-3) fences

3 leading whitespaces are okay for code fences

``` lang info
# Some pseudocode
map a from b -> 1
Expand Down
14 changes: 14 additions & 0 deletions test/headings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

## h2-heading

3 leading whitespaces are okay for headings

## h2 heading

# code block


## h2-heading-with-id {#some-id}

Indented code block

# Code comment
a = 1;

### h3-heading

```nix
Expand All @@ -19,6 +31,8 @@ map a from b -> 1

### indented (0-3) fences

3 leading whitespaces are okay for code fences

``` lang info
# Some pseudocode
map a from b -> 1
Expand Down

0 comments on commit 7f408d0

Please sign in to comment.