mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-10 13:38:09 +08:00
Fix generating html id with special characters (#2495)
This commit is contained in:
parent
4105266ad2
commit
bd3232dedb
2 changed files with 8 additions and 3 deletions
|
@ -34,9 +34,14 @@ defmodule LivebookWeb.HTMLHelpers do
|
||||||
|
|
||||||
defp name_to_html_id(name) do
|
defp name_to_html_id(name) do
|
||||||
name
|
name
|
||||||
|> String.trim()
|
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|
|> String.replace(~r/[^\s\w]/u, "")
|
||||||
|
|> String.trim()
|
||||||
|> String.replace(~r/\s+/u, "-")
|
|> String.replace(~r/\s+/u, "-")
|
||||||
|
|> case do
|
||||||
|
"" -> Base.url_encode64(name, padding: false)
|
||||||
|
id -> id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -18,11 +18,11 @@ defmodule LivebookWeb.HTMLHelpersTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "emoji at end" do
|
test "emoji at end" do
|
||||||
assert HTMLHelpers.names_to_html_ids(["Test 🦦 "]) == ["test-🦦"]
|
assert HTMLHelpers.names_to_html_ids(["Test 🦦 "]) == ["test"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "emoji in middle" do
|
test "emoji in middle" do
|
||||||
assert HTMLHelpers.names_to_html_ids(["One 🥮 Two"]) == ["one-🥮-two"]
|
assert HTMLHelpers.names_to_html_ids(["One 🥮 Two"]) == ["one-two"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns empty list for an empty list" do
|
test "returns empty list for an empty list" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue