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

Option to not XML-escape text #97

Open
meygerjos opened this issue May 4, 2017 · 8 comments
Open

Option to not XML-escape text #97

meygerjos opened this issue May 4, 2017 · 8 comments

Comments

@meygerjos
Copy link

It would be nice if there was an option to not XML-escape text, so that special characters could be used, as in alignedText 0 0 "Jack&amp;Jill had 5&minus;4 pancakes". Currently this renders as <text ...>Jack&amp;amp;Jill had 5&amp;minus;4 pancakes</text>.

I tracked down what happens to the string that is put into alignedText during rendering. Graphics.Rendering.SVG.renderText sends the string (in a Text object) to Graphics.SVG.Core.toElement, part of the svg-builder package, which runs it through Blaze.ByteString.Builder.Html.Utf8.fromHtmlEscapedString, which is the culprit.

I'm not sure what could be done to get around this. For now my workaround is to run the svg output through sed -i "s/\&amp;/\&/g".

@byorgey
Copy link
Member

byorgey commented May 4, 2017

Thanks for the report, and for the good sleuthing work. I agree there ought to be a better solution here. @jeffreyrosenbluth , any thoughts? I could easily imagine adding a configuration option for the SVG backend to turn off XML-escaping. But it might be nicer to control it on the level of individual strings. That is trickier though since I guess we would have to add functions like unescapedText to diagrams-lib, even though this only makes sense for particular backends like SVG.

@jeffreyrosenbluth
Copy link
Member

What would be the downside of not escaping the the text as our default?

@meygerjos
Copy link
Author

Backwards incompatibility, and different results for different backends.

@byorgey
Copy link
Member

byorgey commented May 5, 2017

ClaudiusMaximus commented in IRC: "Why not use unicode character instead of &charactername; in the strings?"

@byorgey
Copy link
Member

byorgey commented May 5, 2017

I guess that would work for everything except &.

@meygerjos
Copy link
Author

I tried that with a minus sign and I get error: lexical error in string/character literal (UTF-8 decoding error) when I try to compile.

@jeffreyrosenbluth
Copy link
Member

@meygerjos That's surprising. I looked at the code in Blaze.ByteString.Builder.Html.Utf8.fromHtmlEscapedString and it seems that it should work. Can you show us an offending code snippet?

@meygerjos
Copy link
Author

OK, it works if I save the file in utf-8. I was previously saving the file in japanese-shift-jis-2004 because that was what emacs recommended.

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

3 participants