summaryrefslogtreecommitdiffstats
path: root/src/style.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-06-10 10:20:17 -0400
committerDan Davison <dandavison7@gmail.com>2020-06-10 10:23:33 -0400
commit312077ea9dd7ba5a1bd1718c5625b583735b90dc (patch)
treea46e28946d5351736112f2c5093e659ab8885df0 /src/style.rs
parentd874c5cba067bf7f5ab06e1c7d5770e02ce8645c (diff)
Don't interpret 'ul' and 'ol' specially in style strings
'underline' and 'overline' are interpreted specially (as a decoration directive), for backwards-compatibility with early versions of delta.
Diffstat (limited to 'src/style.rs')
-rw-r--r--src/style.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/style.rs b/src/style.rs
index 564da388..e2b68d5d 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -89,7 +89,7 @@ impl Style {
is_emph: bool,
) -> Self {
let (special_attributes_from_style_string, style_string) =
- extract_special_decoration_attributes(style_string);
+ extract_special_decoration_attributes_from_non_decoration_style_string(style_string);
let mut style = Style::from_str(
&style_string,
foreground_default,
@@ -328,6 +328,22 @@ fn parse_ansi_term_style(
/// Extract set of 'special decoration attributes' and return it along with modified style string.
fn extract_special_decoration_attributes(style_string: &str) -> (DecorationAttributes, String) {
+ _extract_special_decoration_attributes(style_string, true)
+}
+
+fn extract_special_decoration_attributes_from_non_decoration_style_string(
+ style_string: &str,
+) -> (DecorationAttributes, String) {
+ _extract_special_decoration_attributes(style_string, false)
+}
+
+// If this is being called in the context of processing a decoration style string then we treat
+// ul/ol as a request for an underline/overline decoration respectively. Otherwise they are
+// conventional character style attributes.
+fn _extract_special_decoration_attributes(
+ style_string: &str,
+ is_decoration_style_string: bool,
+) -> (DecorationAttributes, String) {
let mut attributes = DecorationAttributes::EMPTY;
let mut new_style_string = Vec::new();
let style_string = style_string.to_lowercase();
@@ -337,10 +353,10 @@ fn extract_special_decoration_attributes(style_string: &str) -> (DecorationAttri
{
match token {
"box" => attributes |= DecorationAttributes::BOX,
- token if token == "ol" || token == "overline" => {
+ token if token == "overline" || is_decoration_style_string && token == "ol" => {
attributes |= DecorationAttributes::OVERLINE
}
- token if token == "ul" || token == "underline" => {
+ token if token == "underline" || is_decoration_style_string && token == "ul" => {
attributes |= DecorationAttributes::UNDERLINE
}
token if token == "none" || token == "plain" => {}