Skip to content

Commit

Permalink
Make the number of backticks in codeblocks configurable
Browse files Browse the repository at this point in the history
This is a breaking change because it adds a member to the publically
constructable `Options` struct.
  • Loading branch information
zacps authored and Byron committed Aug 2, 2020
1 parent 1240a59 commit c9267b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct Options {
pub newlines_after_list: usize,
pub newlines_after_blockquote: usize,
pub newlines_after_rest: usize,
pub code_block_backticks: usize,
}

impl Default for Options {
Expand All @@ -81,6 +82,7 @@ impl Default for Options {
newlines_after_list: 2,
newlines_after_blockquote: 2,
newlines_after_rest: 1,
code_block_backticks: 4,
}
}
}
Expand Down Expand Up @@ -296,7 +298,7 @@ where
CodeBlock(CodeBlockKind::Indented) => {
state.is_in_code_block = true;
formatter
.write_str("````")
.write_str(&"`".repeat(options.code_block_backticks))
.and(formatter.write_char('\n'))
.and(padding(&mut formatter, &state.padding))
}
Expand All @@ -310,7 +312,7 @@ where
Ok(())
};

s.and_then(|_| formatter.write_str("````"))
s.and_then(|_| formatter.write_str(&"`".repeat(options.code_block_backticks)))
.and_then(|_| formatter.write_str(info))
.and_then(|_| formatter.write_char('\n'))
.and_then(|_| padding(&mut formatter, &state.padding))
Expand Down Expand Up @@ -346,7 +348,7 @@ where
state.newlines_before_start = options.newlines_after_codeblock;
}
state.is_in_code_block = false;
formatter.write_str("````")
formatter.write_str(&"`".repeat(options.code_block_backticks))
}
Table(_) => {
if state.newlines_before_start < options.newlines_after_table {
Expand Down

0 comments on commit c9267b5

Please sign in to comment.