Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the number of backticks in codeblocks configurable #18

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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