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

XML escaping breaks inserted HTML code #34

Closed
daviwil opened this issue Nov 27, 2021 · 10 comments
Closed

XML escaping breaks inserted HTML code #34

daviwil opened this issue Nov 27, 2021 · 10 comments

Comments

@daviwil
Copy link

daviwil commented Nov 27, 2021

Hi! I use this package for templating the websites I generate using Org Mode. Commit 62d66a7 broke my site generation because this package has now started to escape any HTML that is passed in as a plain-text string in the input list given to esxml-to-xml.

Since I have to pass through HTML that is generated by Org as a body for my page templates, this causes my page bodies to be fully escaped in the generated output. Is there any way we can add an approach to bypass the escaping for cases where it really isn't needed?

Let me know if you need any further details.

Thanks!

@wasamasa
Copy link
Collaborator

Yup, that's expected behavior. To do better, there would need to be some mechanism similar to "HTML strings" in Rails, where you mark up a string as not requiring escaping. It would have a new type now (which allows it to be detected as not needing escaping) while still behaving like a string in all other aspects. When serializing the whole tree, nodes of a raw string type would not be subjected to escaping.

Emacs Lisp doesn't offer extensible types or protocols, so it has to be done slightly differently, like by wrapping such text/nodes with a raw-string tag or using text properties (kind of icky though). In terms of implementation, I could think of using a dynamically bound variable to the current escaping mode. Alternatively the escaping mode could be explicitly passed, but it seems less elegant of a solution.

Extra tests to ensure this behaves as expected are a must. I remember something about the Rails implementation to be tricky to get right, maybe its tests could be lifted.

@daviwil
Copy link
Author

daviwil commented Nov 29, 2021

A dynamic variable could be a cheap short term solution, and detecting a list like '(raw-string "<b>Let me be bold!</b>") would also work perfectly fine in my case.

I can definitely understand the need for escaping strings by default, but it'd be great to have a way to do a targeted override like you're suggesting.

Thanks!

@tali713
Copy link
Owner

tali713 commented Nov 30, 2021

I will take a look sometime over the next week to see if I can produce an ideal solution, if wasamasa doesn't beat me to it. (Hopefully sooner)

@daviwil
Copy link
Author

daviwil commented Dec 1, 2021

Excellent, thanks a lot!

@wasamasa
Copy link
Collaborator

wasamasa commented Apr 6, 2022

Sorry for the delay so far.

@daviwil I've looked into the problem again and it seems extremely simple if I restrict myself to the (raw-string "<br>") case instead of a general way to enable raw string processing for part of a tree. See the linked branch and please let me know if anything is misbehaving here.

@tali713 I've added very basic tests, too. Feel free to add more esxml tests to the file to document all functionality and make refactorings more robust.

@randindom
Copy link

Hi.
First of all, thanks for this great piece of software!
I'm using the raw-string branch. When I use sxml-to-xml(...) and add a (raw-string "HTML_HERE") tag I get the quoted HTML result.
Do you have any hints on how to use the sxml-to-xml() function for this use case, so that I can obtain an unquoted HTML result?

Thank you..!

@wasamasa
Copy link
Collaborator

wasamasa commented May 5, 2022

There is no such thing as raw-string syntax for sxml, so I didn't add the functionality there. Going by https://okmij.org/ftp/Scheme/SXML.html a possible syntax would be (*RAW-STRING* "HTML_HERE"). That could be translated to the equivalent esxml equivalent, then to XML. Would that work for you?

@randindom
Copy link

There is no such thing as raw-string syntax for sxml, so I didn't add the functionality there. Going by https://okmij.org/ftp/Scheme/SXML.html a possible syntax would be (*RAW-STRING* "HTML_HERE"). That could be translated to the equivalent esxml equivalent, then to XML. Would that work for you?

Oh, sure, thanks...

@wasamasa
Copy link
Collaborator

wasamasa commented May 6, 2022

Alright, pushed.

Given that 30 days passed with some positive feedback, I think this is ready for merge.

wasamasa added a commit that referenced this issue May 6, 2022
@randindom
Copy link

JFYI, [in my case] it works! Perfect!

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants