Skip to content

Commit ceb9277

Browse files
committed
Add compact_html render option to suppress newlines in HTML output
1 parent 886dfb7 commit ceb9277

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Note that there is a distinction in comrak for "parse" options and "render" opti
181181
| `gfm_quirks` | Outputs HTML with GFM-style quirks; namely, not nesting `<strong>` inlines. | `false` |
182182
| `prefer_fenced` | Always output fenced code blocks, even where an indented one could be used. | `false` |
183183
| `tasklist_classes` | Add CSS classes to the HTML output of the tasklist extension | `false` |
184+
| `compact_html` | Suppress newlines in pretty-printed HTML output. | `false` |
184185

185186
As well, there are several extensions which you can toggle in the same manner:
186187

ext/commonmarker/src/options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const RENDER_IGNORE_EMPTY_LINKS: &str = "ignore_empty_links";
5353
const RENDER_GFM_QUIRKS: &str = "gfm_quirks";
5454
const RENDER_PREFER_FENCED: &str = "prefer_fenced";
5555
const RENDER_TASKLIST_CLASSES: &str = "tasklist_classes";
56+
const RENDER_COMPACT_HTML: &str = "compact_html";
5657

5758
pub fn iterate_render_options(comrak_options: &mut comrak::options::Render, options_hash: RHash) {
5859
options_hash
@@ -94,6 +95,9 @@ pub fn iterate_render_options(comrak_options: &mut comrak::options::Render, opti
9495
Cow::Borrowed(RENDER_TASKLIST_CLASSES) => {
9596
comrak_options.tasklist_classes = TryConvert::try_convert(value)?;
9697
}
98+
Cow::Borrowed(RENDER_COMPACT_HTML) => {
99+
comrak_options.compact_html = TryConvert::try_convert(value)?;
100+
}
97101
_ => {}
98102
}
99103
Ok(ForEach::Continue)

lib/commonmarker/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module Config
2626
gfm_quirks: false,
2727
prefer_fenced: false,
2828
tasklist_classes: false,
29+
compact_html: false,
2930
}.freeze,
3031
extension: {
3132
strikethrough: true,

test/rendering_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class RenderingTest < Minitest::Test
6+
def test_compact_html
7+
markdown = "# Hello\n\nWorld\n"
8+
9+
default_output = Commonmarker.to_html(markdown)
10+
compact_output = Commonmarker.to_html(markdown, options: { render: { compact_html: true } })
11+
12+
assert_operator(compact_output.count("\n"), :<, default_output.count("\n"))
13+
end
14+
end

0 commit comments

Comments
 (0)