Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow quoting hypertext attribute values #14550

Merged
merged 4 commits into from May 5, 2024

Conversation

rubenwardy
Copy link
Member

@rubenwardy rubenwardy commented Apr 15, 2024

Hypertext markup attributes cannot contain spaces currently. This is a huge limitation, especially when showing images in the main menu - if the path to the image contains a space then it cannot be shown in current master.

This PR allows quoting hypertext attribute values, like in HTML.

To do

This PR is Ready for Review.

Should we deprecate unquoted attribute values? Or should we immediately remove support for unquoted attributes as hypertext is experimental? HTML supports unquoted attribute values

How to test

  • Checkout the ContentDB redesign. Build/install minetest on a path with space.
  • Open NodeCore in the CDB dialog, see broken img tags
  • Apply this PR and the following patch. The img tags should now work
diff --git a/builtin/mainmenu/content/dlg_package.lua b/builtin/mainmenu/content/dlg_package.lua
index ed1ab97ff..63b59a0cf 100644
--- a/builtin/mainmenu/content/dlg_package.lua
+++ b/builtin/mainmenu/content/dlg_package.lua
@@ -165,11 +165,11 @@ local function get_formspec(data)
                        local fs_to_px = winfo.size.x / winfo.max_formspec_size.x
                        for i, ss in ipairs(info.screenshots) do
                                local path = get_screenshot(data.package, ss.url, 2)
-                               hypertext = hypertext .. "<action name=ss_" .. i .. "><img name=" ..
-                                               core.hypertext_escape(path) .. " width=" .. (3 * fs_to_px) ..
+                               hypertext = hypertext .. "<action name=ss_" .. i .. "><img name=\"" ..
+                                               core.hypertext_escape(path) .. "\" width=" .. (3 * fs_to_px) ..
                                                " height=" .. (2 * fs_to_px) .. "></action>"
                                if i ~= #info.screenshots then
-                                       hypertext = hypertext .. "<img name=blank.png width=" .. (0.25 * fs_to_px) ..
+                                       hypertext = hypertext .. "<img name=\"blank.png\" width=" .. (0.25 * fs_to_px) ..
                                                        " height=" .. (2.25 * fs_to_px).. ">"
                                end
                        end
@@ -177,7 +177,7 @@ local function get_formspec(data)
                                        info.long_description.body
 
                        hypertext = hypertext:gsub("<img name=blank.png ",
-                                       "<img name=" .. core.hypertext_escape(defaulttexturedir) .. "blank.png ")
+                                       "<img name=\"" .. core.hypertext_escape(defaulttexturedir) .. "blank.png\" ")
 
                        table.insert_all(formspec, {
                                "hypertext[0.375,0;",

@rubenwardy
Copy link
Member Author

Updated to support single quotes (')

src/gui/guiHyperText.cpp Outdated Show resolved Hide resolved
src/gui/guiHyperText.cpp Show resolved Hide resolved
src/gui/guiHyperText.cpp Outdated Show resolved Hide resolved
doc/lua_api.md Outdated Show resolved Hide resolved
@rubenwardy rubenwardy requested a review from sfan5 May 4, 2024 09:43
@rubenwardy
Copy link
Member Author

You can no longer use the escape character to escape in unquoted attribute values

Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, not tested

@sfan5 sfan5 merged commit 3017b02 into minetest:master May 5, 2024
15 checks passed
@rubenwardy rubenwardy deleted the hypertext-quoted branch May 5, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants