How to convert html "nbsp" to normal space? #11754
Answered
by
jgm
VladimirAlexiev
asked this question in
Q&A
|
I have HTML with
function remove_gunk (x)
if x.t == "Str" then
x.text = re.gsub(x.text,[[" "]]," ") -- replace nbsp with normal space. Also tried \u{202F}, \u{A0}
end
return x
end
return {{Inline = remove_gunk, Block = remove_gunk}}
Thanks for your help! |
Answered by
jgm
Jul 10, 2026
Replies: 2 comments
|
Inside the Str element, you'll just have a unicode nonbreaking space character. Put that in your regex instead of function Str(el)
el.text = string.gsub(el.text, " ", " ")
return el
end |
0 replies
Answer selected by
VladimirAlexiev
|
Thanks! I'm a Lua noob, so I didn't know about the if x.t == "Image" then
x.src = re.gsub(x.src,[["access_token=" [_%a%d-]+]],"") -- strip image access token
x.src = re.gsub(x.src,[["?"? "width=" %d+ "&height=" %d+]],"") -- strip image width/height params
endI see that string.gsub has a similar syntax. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inside the Str element, you'll just have a unicode nonbreaking space character. Put that in your regex instead of
.