2

Does anyone have a good way to escape html tags in erlang (as for CGI.escapeHtml in Ruby)?

Thanks

Lyes Zaiko
  • 130
  • 1
  • 8
  • please expound on your question. Show an example of what you want. what your inputs should be and outputs. Not all of us have programmed in Ruby ! :) – Muzaaya Joshua Nov 18 '11 at 10:37
  • I'd guess this would be basically the same question: http://stackoverflow.com/questions/3339014/how-do-i-xml-encode-a-string-in-erlang – RoToRa Nov 18 '11 at 12:04
  • @RoToRa So you suggest that I can proceed as for [http://stackoverflow.com/questions/3339014/how-do-i-xml-encode-a-string-in-erlang](http://stackoverflow.com/questions/3339014/how-do-i-xml-encode-a-string-in-erlang), it may be a good idea since XML uses the same tags as HTML. I guess then that there is no existing erlang module that do this. Thanks – Lyes Zaiko Nov 18 '11 at 13:15
  • 1
    @MuzaayaJoshua: CGI.escapeHtml(), escapes html spécial chars in a text such as if this last id displayed in an html page, the html tags within it are not interpreted by the browser. I'm looking for an erlang-equivalent of it. – Lyes Zaiko Nov 18 '11 at 13:17
  • http://stackoverflow.com/q/6266695/324312 – jdeseno Nov 23 '11 at 15:43

1 Answers1

1

Well, i would tell you to roll your own method using string and list processing But, i would also say that if you have yaws web server source, there is a method i have used and copied into my own libraries. yaws_api:url_encode(HtmlString).

See it here in action.

1> Html = "5 > 4 = true".
"5 > 4 = true"
2> yaws_api:url_encode(Html).
"5%20%3E%204%20%3D%20true"
3> 
I hope this is some how what u needed. If this is what you needed, you could just browse yaws web server source code and then copy out this function and use it in your own projects, notice that within the module yaws_api.erl, you will have to make sure that you copy out all the dependencies for this function as klacke did a lot of pattern matching, function clauses, recursion e.t.c. Just copy the whole function and the small support functions from that source file and paste it some where in your projects. The other way would be to do it by your own by manipulating strings and Lists. Those are my suggestions :)
Muzaaya Joshua
  • 7,736
  • 3
  • 47
  • 86