Page 1 of 1
HTML entities
Posted: Sat Apr 29, 2017 10:54 am
by exheusden
Many years ago, I wrote a HyperText function to convert accented and other special characters to HTML entities.
I was recently looking at the now LiveCode stack that contains this function, in order to modify the old textual entities into numeric ones. The function is:
Code: Select all
function textToEntities textToCheck
put "&,ä,á,à,â,ã,å,æ,ë,è,é,ê,í,ï,î,ñ,ö,ó,ò,ô,õ,ü,ú,ù,ç,Å,Æ,Ö,Ü,…,—,£,¡,ß" into textTable
put "&,ä,á,à,â,ã,å,æ,ë,è,é,ê,í,ï,î,ñ,ö,ó,ò,ô,õ,ü,ú,ù,ç,Å,Æ,Ö,Ü,…,—,£,¡,ß" into entityTable
put 0 into itemCount
repeat for each item textTableItem in textTable
get textTableItem
add 1 to itemCount
replace it with item itemCount of entityTable in textToCheck
end repeat
return textToCheck
end textToEntities
Is there a more "automatic" way (perhaps a built-in function) to do this in LiveCode?
Re: HTML entities
Posted: Sat Apr 29, 2017 11:58 am
by Klaus
Hola Exheusden,
if you can live with html entity NAMES instead of numbers, you can use something like this, from a quick test:
Code: Select all
on mouseUp
put "&,ä,á,à,â,ã,å,æ,ë,è,é,ê,í,ï,î,ñ,ö,ó,ò,ô,õ,ü,ú,ù,ç,Å,Æ,Ö,Ü,…,—,£,¡,ß" into TT
set the text of the templatefield to TT
put the HTMLtext of the templatefield into fld 1
reset the templatefield
end mouseUp
You get the picture.
Best
Klaus
Re: HTML entities
Posted: Sat Apr 29, 2017 11:59 am
by exheusden
Thank you again, Klaus. That looks a lot tidier!
However, this returns the old character HTML entities, such as &,ä,á,à,â,ã,å,æ,ë,è, etc.
I want the entity numbers, such as &,ä,á,à,â,ã,å,æ,ë,è, etc
Re: HTML entities
Posted: Sat Apr 29, 2017 12:34 pm
by Klaus
exheusden wrote:However, this returns the old character HTML entities, such as &,ä,á,à,â,ã,å,æ,ë,è, etc.
I want the entity numbers, such as &,ä,á,à,â,ã,å,æ,ë,è, etc
Yep, that's why I wrote:
if you can live with html entity NAMES instead of numbers...

Re: HTML entities
Posted: Sat Apr 29, 2017 12:38 pm
by exheusden
Indeed, and I can't, so should I take it that there is no more efficient way to achieve what I want than my code? It works surprisingly well, but seems a bit dated (just like my car…).
Re: HTML entities
Posted: Sat Apr 29, 2017 12:54 pm
by Klaus
Well, I don't even own a car!

Re: HTML entities
Posted: Sat Apr 29, 2017 2:58 pm
by [-hh]
For LC 7/8/9 an (Unicode-)
extended table may be interesting?
For example the currency symbol for Euro is in the lookup table below:
So this works in LC 7/8/9:
Code: Select all
set htmltext of fld "OUT1" to "€"
For generating your conversion list you could use
codepointToNum and
numToCodepoint
for example, with the Euro symbol,
codepointToNum("€") and
numToCodepoint(8364)
Here is my lookup table sorted by the (decimal) numbers:
Code: Select all
""
&&
''
<<
>>
 
¡¡
¢¢
££
¤¤
¥¥
¦¦
§§
¨¨
©©
ªª
««
¬¬
­­
®®
¯¯
°°
±±
²²
³³
´´
µµ
¶¶
··
¸¸
¹¹
ºº
»»
¼¼
½½
¾¾
¿¿
ÀÀ
ÂÂ
ÃÃ
ÄÄ
ÅÅ
ÆÆ
ÇÇ
ÈÈ
ÉÉ
ÊÊ
ËË
ÌÌ
ÍÍ
ÎÎ
ÏÏ
ÐÐ
ÑÑ
ÒÒ
ÓÓ
ÔÔ
ÕÕ
ÖÖ
××
ØØ
ÙÙ
ÚÚ
ÛÛ
ÜÜ
ÝÝ
ÞÞ
ßß
àà
ââ
ãã
ää
åå
ææ
çç
èè
éé
êê
ëë
ìì
íí
îî
ïï
ðð
ññ
òò
óó
ôô
õõ
öö
÷÷
øø
ùù
úú
ûû
üü
ýý
þþ
ÿÿ
ŒŒ
œœ
ŠŠ
šš
ŸŸ
ƒƒ
ˆˆ
˜˜
ΑΑ
ΒΒ
ΓΓ
ΔΔ
ΕΕ
ΖΖ
ΗΗ
ΘΘ
ΙΙ
ΚΚ
ΛΛ
ΜΜ
ΝΝ
ΞΞ
ΟΟ
ΠΠ
ΡΡ
ΣΣ
ΤΤ
ΥΥ
ΦΦ
ΧΧ
ΨΨ
ΩΩ
αα
ββ
γγ
δδ
εε
ζζ
ηη
θθ
ιι
κκ
λλ
μμ
νν
ξξ
οο
ππ
ρρ
ςς
σσ
ττ
υυ
φφ
χχ
ψψ
ωω
ϑϑ
ϒϒ
ϖϖ
  
  
  
‌‌
‍‍
‎‎
‏‏
––
——
‘‘
’’
‚‚
““
””
„„
††
‡‡
••
……
‰‰
′′
″″
‹‹
››
‾‾
⁄⁄
€€
ℑℑ
℘℘
ℜℜ
™™
ℵℵ
←←
↑↑
→→
↓↓
↔↔
↵↵
⇐⇐
⇑⇑
⇒⇒
⇓⇓
⇔⇔
∀∀
∂∂
∃∃
∅∅
∇∇
∈∈
∉∉
∋∋
∏∏
∑∑
−−
∗∗
√√
∝∝
∞∞
∠∠
∧∧
∨∨
∩∩
∪∪
∫∫
∴∴
∼∼
≅≅
≈≈
≠≠
≡≡
≤≤
≥≥
⊂⊂
⊃⊃
⊄⊄
⊆⊆
⊇⊇
⊕⊕
⊗⊗
⊥⊥
⋅⋅
⌈⌈
⌉⌉
⌊⌊
⌋⌋
〈⟨
〉⟩
◊◊
♠♠
♣♣
♥♥
♦♦
And here is the same table (just for easy access by the impatient readers) sorted by the HTML-entity names:
Code: Select all
ÂÂ
ââ
´´
ÆÆ
ææ
ÀÀ
àà
ℵℵ
ΑΑ
αα
&&
∧∧
∠∠
''
ÅÅ
åå
≈≈
ÃÃ
ãã
ÄÄ
ää
„„
ΒΒ
ββ
¦¦
••
∩∩
ÇÇ
çç
¸¸
¢¢
ΧΧ
χχ
ˆˆ
♣♣
≅≅
©©
↵↵
∪∪
¤¤
‡‡
††
⇓⇓
↓↓
°°
ΔΔ
δδ
♦♦
÷÷
ÉÉ
éé
ÊÊ
êê
ÈÈ
èè
∅∅
  
  
ΕΕ
εε
≡≡
ΗΗ
ηη
ÐÐ
ðð
ËË
ëë
€€
∃∃
ƒƒ
∀∀
½½
¼¼
¾¾
⁄⁄
ΓΓ
γγ
≥≥
>>
⇔⇔
↔↔
♥♥
……
ÍÍ
íí
ÎÎ
îî
¡¡
ÌÌ
ìì
ℑℑ
∞∞
∫∫
ΙΙ
ιι
¿¿
∈∈
ÏÏ
ïï
ΚΚ
κκ
ΛΛ
λλ
⟨〈
««
⇐⇐
←←
⌈⌈
““
≤≤
⌊⌊
∗∗
◊◊
‎‎
‹‹
‘‘
<<
¯¯
——
µµ
··
−−
ΜΜ
μμ
∇∇
 
––
≠≠
∋∋
¬¬
∉∉
⊄⊄
ÑÑ
ññ
ΝΝ
νν
ÓÓ
óó
ÔÔ
ôô
ŒŒ
œœ
ÒÒ
òò
‾‾
ΩΩ
ωω
ΟΟ
οο
⊕⊕
∨∨
ªª
ºº
ØØ
øø
ÕÕ
õõ
⊗⊗
ÖÖ
öö
¶¶
∂∂
‰‰
⊥⊥
ΦΦ
φφ
ΠΠ
ππ
ϖϖ
±±
££
″″
′′
∏∏
∝∝
ΨΨ
ψψ
""
√√
⟩〉
»»
⇒⇒
→→
⌉⌉
””
ℜℜ
®®
⌋⌋
ΡΡ
ρρ
‏‏
››
’’
‚‚
ŠŠ
šš
⋅⋅
§§
­­
ΣΣ
σσ
ςς
∼∼
♠♠
⊂⊂
⊆⊆
∑∑
⊃⊃
¹¹
²²
³³
⊇⊇
ßß
ΤΤ
ττ
∴∴
ΘΘ
θθ
ϑϑ
  
ÞÞ
þþ
˜˜
××
™™
ÚÚ
úú
⇑⇑
↑↑
ÛÛ
ûû
ÙÙ
ùù
¨¨
ϒϒ
ΥΥ
υυ
ÜÜ
üü
℘℘
ΞΞ
ξξ
ÝÝ
ýý
¥¥
ŸŸ
ÿÿ
ΖΖ
ζζ
‍‍
‌‌