aboutsummaryrefslogtreecommitdiffhomepage
path: root/markup/highlight
diff options
context:
space:
mode:
authorKhayyam Saleem <[email protected]>2023-02-05 14:06:25 -0500
committerGitHub <[email protected]>2023-02-05 20:06:25 +0100
commit73ece30d842ff2e814372f2003accd1bc25e78b6 (patch)
tree8887be0d8af81fdd6f5c82e378819cef38f8c9b2 /markup/highlight
parentf9fc0e045bc1f72ba61fdf4a79b10a75a240394e (diff)
downloadhugo-73ece30d842ff2e814372f2003accd1bc25e78b6.tar.gz
hugo-73ece30d842ff2e814372f2003accd1bc25e78b6.zip
markup: Fix linenos codeblock hl option case regression
This fixes a regression introduced in v0.93.0 where previously, a mixed-case key for lineNos would be successfully parsed. This change moves the configuration key lowercasing step into the configuration normalization stage, which is called whether the highlighting config is being parsed from a `string` or a `map`. Fixes #10682
Diffstat (limited to 'markup/highlight')
-rw-r--r--markup/highlight/config.go9
-rw-r--r--markup/highlight/config_test.go17
2 files changed, 24 insertions, 2 deletions
diff --git a/markup/highlight/config.go b/markup/highlight/config.go
index 9013dd072..b1f6d4603 100644
--- a/markup/highlight/config.go
+++ b/markup/highlight/config.go
@@ -198,7 +198,7 @@ func parseHightlightOptions(in string) (map[string]any, error) {
for _, v := range strings.Split(in, ",") {
keyVal := strings.Split(v, "=")
- key := strings.ToLower(strings.Trim(keyVal[0], " "))
+ key := strings.Trim(keyVal[0], " ")
if len(keyVal) != 2 {
return opts, fmt.Errorf("invalid Highlight option: %s", key)
}
@@ -216,6 +216,12 @@ func normalizeHighlightOptions(m map[string]any) {
return
}
+ // lowercase all keys
+ for k, v := range m {
+ delete(m, k)
+ m[strings.ToLower(k)] = v
+ }
+
baseLineNumber := 1
if v, ok := m[linosStartKey]; ok {
baseLineNumber = cast.ToInt(v)
@@ -232,7 +238,6 @@ func normalizeHighlightOptions(m map[string]any) {
if vs, ok := v.(string); ok {
m[k] = vs != "false"
}
-
case hlLinesKey:
if hlRanges, ok := v.([][2]int); ok {
for i := range hlRanges {
diff --git a/markup/highlight/config_test.go b/markup/highlight/config_test.go
index ab92ecf36..23da29ab6 100644
--- a/markup/highlight/config_test.go
+++ b/markup/highlight/config_test.go
@@ -53,4 +53,21 @@ func TestConfig(t *testing.T) {
c.Assert(cfg.LineNoStart, qt.Equals, 32)
c.Assert(cfg.Hl_Lines, qt.Equals, "3-8 10-20")
})
+
+ c.Run("applyOptionsFromMap", func(c *qt.C) {
+ cfg := DefaultConfig
+ err := applyOptionsFromMap(map[string]any{
+ "noclasses": true,
+ "lineNos": "inline", // mixed case key, should work after normalization
+ "linenostart": 32,
+ "hl_lines": "3-8 10-20",
+ }, &cfg)
+
+ c.Assert(err, qt.IsNil)
+ c.Assert(cfg.NoClasses, qt.Equals, true)
+ c.Assert(cfg.LineNos, qt.Equals, true)
+ c.Assert(cfg.LineNumbersInTable, qt.Equals, false)
+ c.Assert(cfg.LineNoStart, qt.Equals, 32)
+ c.Assert(cfg.Hl_Lines, qt.Equals, "3-8 10-20")
+ })
}