From ee4687bf8d668f8cb6b76e5a518de7016a5ef7bd Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Mon, 3 Jan 2022 15:57:04 +0000 Subject: [PATCH] Remove parsing of __ in title strings, fixes #53 --- src/display_list/from_snippet.rs | 21 +++++---------------- tests/dl_from_snippet.rs | 18 ++++-------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/display_list/from_snippet.rs b/src/display_list/from_snippet.rs index faf48f2..98683fb 100644 --- a/src/display_list/from_snippet.rs +++ b/src/display_list/from_snippet.rs @@ -53,22 +53,11 @@ fn format_label( ) -> Vec> { let mut result = vec![]; if let Some(label) = label { - for (idx, element) in label.split("__").enumerate() { - let element_style = match style { - Some(s) => s, - None => { - if idx % 2 == 0 { - DisplayTextStyle::Regular - } else { - DisplayTextStyle::Emphasis - } - } - }; - result.push(DisplayTextFragment { - content: element, - style: element_style, - }); - } + let element_style = style.unwrap_or(DisplayTextStyle::Regular); + result.push(DisplayTextFragment { + content: label, + style: element_style, + }); } result } diff --git a/tests/dl_from_snippet.rs b/tests/dl_from_snippet.rs index 0dcfcfa..d6b79ff 100644 --- a/tests/dl_from_snippet.rs +++ b/tests/dl_from_snippet.rs @@ -262,20 +262,10 @@ fn test_format_label() { annotation: dl::Annotation { annotation_type: dl::DisplayAnnotationType::Error, id: None, - label: vec![ - dl::DisplayTextFragment { - content: "This ", - style: dl::DisplayTextStyle::Regular, - }, - dl::DisplayTextFragment { - content: "is", - style: dl::DisplayTextStyle::Emphasis, - }, - dl::DisplayTextFragment { - content: " a title", - style: dl::DisplayTextStyle::Regular, - }, - ], + label: vec![dl::DisplayTextFragment { + content: "This __is__ a title", + style: dl::DisplayTextStyle::Regular, + }], }, source_aligned: true, continuation: false,