diff options
Diffstat (limited to 'src/tui/markdown.rs')
-rw-r--r-- | src/tui/markdown.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/tui/markdown.rs b/src/tui/markdown.rs index 369380e..c913e9d 100644 --- a/src/tui/markdown.rs +++ b/src/tui/markdown.rs @@ -35,7 +35,8 @@ pub fn preprocess(input: String) -> String { } /// Preview markdown of the given length -/// **Note**: Assumes preprocessing has taken place +/// Currently removes any color (i.e. code highlighting) to avoid +/// the jarring issue of a fragmented highlight style on focused items. pub fn preview(width: usize, input: &StyledString) -> StyledString { let mut w = 0; let mut new_spans = Vec::new(); @@ -43,14 +44,14 @@ pub fn preview(width: usize, input: &StyledString) -> StyledString { // Filter newlines if span.width == 0 { w += 1; - new_spans.push(IndexedSpan { + new_spans.push(drop_color(IndexedSpan { content: IndexedCow::Owned(" ".to_owned()), width: 1, ..*span - }); + })); } else { w += span.width; - new_spans.push(span.clone()); + new_spans.push(drop_color(span.clone())); } if w > width { break; @@ -61,6 +62,16 @@ pub fn preview(width: usize, input: &StyledString) -> StyledString { prev } +fn drop_color(span: StyledIndexedSpan) -> StyledIndexedSpan { + IndexedSpan { + attr: Style { + color: None, + ..span.attr + }, + ..span + } +} + /// Parse the given markdown text into a list of spans. /// This is a shortcut for `Parser::new(preprocessed_input).collect()`. fn parse_spans(input: &str) -> Vec<StyledIndexedSpan> { |