Skip to content

Commit b4fee92

Browse files
author
Ben Zörb
authored
Merge pull request #49 from jungvonmatt/fix-floating-point-svg-issue
fix(core): respect floating point numbers in svg viewbox, width and height attributes
2 parents 7a25248 + 89d8cd6 commit b4fee92

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

hugo-modules/core/utils/svg/parse.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@
8888
{{/* {{ $height_markup }}
8989
{{ $viewbox_markup }} */}}
9090
{{ with $width_markup }}
91-
{{ $width = replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*width=\"(\\d+)[^\"]*\".*$" "${1}" . }}
91+
{{ $width = replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*width=\"([\\d\\.]+)[^\"]*\".*$" "${1}" . }}
9292
{{ else }}
9393
{{ with $viewbox_markup }}
94-
{{ $w1 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*(\\d+)\\s+\\d+\\s+\\d+\\s+\\d+\\s*\".*" "${1}" . }}
95-
{{ $w2 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*\\d+\\s+\\d+\\s+(\\d+)\\s+\\d+\\s*\".*" "${1}" . }}
94+
{{ $w1 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*([\\d\\.]+)\\s+[\\d\\.]+\\s+[\\d\\.]+\\s+[\\d\\.]+\\s*\".*" "${1}" . }}
95+
{{ $w2 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*[\\d\\.]+\\s+[\\d\\.]+\\s+([\\d\\.]+)\\s+[\\d\\.]+\\s*\".*" "${1}" . }}
9696
{{ $width = sub (float $w2) (float $w1) }}
9797
{{ end }}
9898
{{ end }}
9999

100100
{{ with $height_markup }}
101-
{{ $height = replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*height=\"(\\d+)[^\"]*\".*" "${1}" . }}
101+
{{ $height = replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*height=\"([\\d\\.]+)[^\"]*\".*" "${1}" . }}
102102
{{ else }}
103103
{{ with $viewbox_markup }}
104-
{{ $h1 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*\\d+\\s+(\\d+)\\s+\\d+\\s+\\d+\\s*\".*" "${1}" . }}
105-
{{ $h2 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*\\d+\\s+\\d+\\s+\\d+\\s+(\\d+)\\s*\".*" "${1}" . }}
104+
{{ $h1 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*[\\d\\.]+\\s+([\\d\\.]+)\\s+[\\d\\.]+\\s+[\\d\\.]+\\s*\".*" "${1}" . }}
105+
{{ $h2 := replaceRE "<\\s*\\/?\\s*svg\\s*[^>]*view[bB]ox=\"\\s*[\\d\\.]+\\s+[\\d\\.]+\\s+[\\d\\.]+\\s+([\\d\\.]+)\\s*\".*" "${1}" . }}
106106
{{ $height = sub (float $h2) (float $h1) }}
107107
{{ end }}
108108
{{ end }}

0 commit comments

Comments
 (0)