Recent

Author Topic: Function to replace characters with HTML character references ( < > )?  (Read 3007 times)

alpine

  • Hero Member
  • *****
  • Posts: 1412
I'm looking into the fpc packages for such a function but I can't find one.
There should be one somewhere (fcl-web), with such a developed infrastructure...
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Josh

  • Hero Member
  • *****
  • Posts: 1460
unit
httpprotocol

has a httpdecode and httpdecode function

any use ?
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

alpine

  • Hero Member
  • *****
  • Posts: 1412
unit
httpprotocol

has a httpdecode and httpdecode function

any use ?
Thanks for reply!
Found these but they are for URL encoding (+%xxx+).
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

dsiders

  • Hero Member
  • *****
  • Posts: 1649
I'm looking into the fpc packages for such a function but I can't find one.
There should be one somewhere (fcl-web), with such a developed infrastructure...

EscapeHTML() and  UnescapeHTML() routines are located in htmlelements.pp in the fcl-xml package.

Kays

  • Hero Member
  • *****
  • Posts: 632
  • Whasup!?
    • KaiBurghardt.de
EscapeHTML can only handle ampersand, less than, greater than, inch sign, and dumb apostrophe, yet there are 1926 character entities. I don’t think Alpine would’ve asked his question if all he needed was escaping the special meaning characters ampersand and less than sign. He could’ve accomplished that on his own.
Yours Sincerely
Kai Burghardt

dsiders

  • Hero Member
  • *****
  • Posts: 1649
EscapeHTML can only handle ampersand, less than, greater than, inch sign, and dumb apostrophe, yet there are 1926 character entities. I don’t think Alpine would’ve asked his question if all he needed was escaping the special meaning characters ampersand and less than sign. He could’ve accomplished that on his own.

It's hard to answer a question that was not asked...

delphius

  • Jr. Member
  • **
  • Posts: 83
Take a look at https://www.benibela.de/documentation/bbutils/bbutils.html#strDecodeHTMLEntities
Its missing fpc functions :)
But we need to solve the opposite problem.
Benny's methods are quite complex and close to black magic, but here I laid out a principle that can be easily reversed
https://github.com/delphius/htmlparser
https://github.com/delphius/htmlparser/blob/d73faa9a5785514726a946b8af09dbee256d0efa/HTML2TextRenderer.pas#L267

There are 2231 entities :))))
https://github.com/delphius/htmlparser/blob/main/entities.inc

P.S. It's the only place I know that is close to what you are looking for
https://gitlab.com/freepascal.org/lazarus/lazarus/-/blob/main/components/lazutils/html2textrender.pas#L293
But there's only 3! entities in the function
« Last Edit: May 01, 2024, 01:14:27 am by delphius »
fpmtls - ssl/tls 1.3 implementation in pure pascal
fpmailsend - sending a simple email message
pascal-webui - use web browser as gui and fpc as backend

alpine

  • Hero Member
  • *****
  • Posts: 1412
@Kays
Wow, I didn't knew they are so many. I've expected something in the hundreds.

@dsiders
Thank you for pointing me to fcl-xml.

Meanwhile, I really wrote a one-liner stub which happens to be just like the one in the htmlelements.pp. Just hoped for something more comprehensive.   


 
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Roland57

  • Hero Member
  • *****
  • Posts: 613
    • msegui.net
My projects are on Codeberg.

 

TinyPortal © 2005-2018