Skip to content

Commit

Permalink
Merge pull request #159 from JadedBlueEyes/jade/no-wrap-links
Browse files Browse the repository at this point in the history
Add option to disable wrapping links
  • Loading branch information
jugglerchris committed Jul 24, 2024
2 parents 466ac79 + a97ac8e commit e10dbe2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ struct HtmlContext {
min_wrap_width: usize,
raw: bool,
draw_borders: bool,
wrap_links: bool,
}

fn dom_to_render_tree_with_context<T: Write>(
Expand Down Expand Up @@ -1912,6 +1913,7 @@ pub mod config {
min_wrap_width: usize,
raw: bool,
draw_borders: bool,
wrap_links: bool,
}

impl<D: TextDecorator> Config<D> {
Expand All @@ -1929,6 +1931,7 @@ pub mod config {
min_wrap_width: self.min_wrap_width,
raw: self.raw,
draw_borders: self.draw_borders,
wrap_links: self.wrap_links,
}
}
/// Parse with context.
Expand Down Expand Up @@ -2086,6 +2089,11 @@ pub mod config {
self.draw_borders = false;
self
}
/// Do not wrap links
pub fn no_link_wrapping(mut self) -> Self {
self.wrap_links = false;
self
}
}

impl Config<RichDecorator> {
Expand Down Expand Up @@ -2158,6 +2166,7 @@ pub mod config {
min_wrap_width: MIN_WIDTH,
raw: false,
draw_borders: true,
wrap_links: true,
}
}

Expand All @@ -2175,6 +2184,7 @@ pub mod config {
min_wrap_width: MIN_WIDTH,
raw: false,
draw_borders: true,
wrap_links: true,
}
}

Expand All @@ -2192,6 +2202,7 @@ pub mod config {
min_wrap_width: MIN_WIDTH,
raw: false,
draw_borders: true,
wrap_links: true,
}
}
}
Expand Down Expand Up @@ -2220,6 +2231,7 @@ impl RenderTree {
allow_width_overflow: context.allow_width_overflow,
raw: context.raw,
draw_borders: context.draw_borders,
wrap_links: context.wrap_links,
};
let test_decorator = decorator.make_subblock_decorator();
let builder = SubRenderer::new(width, render_options, decorator);
Expand Down
6 changes: 5 additions & 1 deletion src/render/text_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,9 @@ pub(crate) struct RenderOptions {

/// Whether to draw table borders
pub draw_borders: bool,

/// Whether to wrap links as normal text
pub wrap_links: bool,
}

impl Default for RenderOptions {
Expand All @@ -949,6 +952,7 @@ impl Default for RenderOptions {
pad_block_width: Default::default(),
raw: false,
draw_borders: true,
wrap_links: true,
}
}
}
Expand Down Expand Up @@ -1046,7 +1050,7 @@ impl<D: TextDecorator> SubRenderer<D> {
let tag = vec![ts.tag];

let width = s.width();
if pos + width > self.width {
if self.options.wrap_links && pos + width > self.width {
// split the string and start a new line
let mut buf = String::new();
for c in s.chars() {
Expand Down

0 comments on commit e10dbe2

Please sign in to comment.