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

Pasting and converting HTML to Hiccup loses contents of <style> and <script> tags #2171

Closed
jffry opened this issue May 9, 2019 · 3 comments
Labels
bug Marks issues describing bugs released Marks issues which have had the fixes released in a stable build
Milestone

Comments

@jffry
Copy link

jffry commented May 9, 2019

Follow-on to #2154: Pasting HTML and converting it to Hiccup doesn't correctly convert <script> or <style> tags that contain inline contents.

Paste this HTML into a Clojure file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <title>Sparkfund Email</title>
  <style type="text/css">.example { color: red; }</style>
  <script type="text/javascript">alert('hello?');</script>
</head>
<body>
  <p>The content of the style and script tags is dropped.</p>
  <style type="text/css">.example { color: red; }</style>
  <script type="text/javascript">alert('hello?');</script>
  <pre>
    What about the humble pre tag?
    which can have text on multiple lines?
  </pre>
  <textarea>And textareas?</textarea>
  <foo>Or custom tags?</foo>
</body>
</html>

Accept the option to convert to Hiccup:

image

The resulting Hiccup is incorrect because it has lost the contents of the <script> and <style> tags:

[:html {:lang "en"}
 [:head
  [:meta {:charset "UTF-8"}]
  [:title "Sparkfund Email"]
  [:style {:type "text/css"}]
  [:script {:type "text/javascript"}]]
 [:body
  [:p "The content of the style and script tags is dropped."]
  [:style {:type "text/css"}]
  [:script {:type "text/javascript"}]
  [:pre "What about the humble pre tag?
    which can have text on multiple lines?"]
  [:textarea "And textareas?"]
  [:foo "Or custom tags?"]]]

This also happens in the case of isolated fragments, e.g.

<script>
alert("test");
</script>

converts to just [:script].

This is in Cursive v1.8.2-eap2-2018.3 and IDEA Ultimate 2018.3.6.

@jffry
Copy link
Author

jffry commented May 9, 2019

I'm also unsure whether or not it's a problem that the leading whitespace on the first line of the <pre> tag got trimmed

@cursive-ide cursive-ide added this to the 1.8.2 milestone May 9, 2019
@cursive-ide
Copy link
Owner

Thanks for the report - I suspect this is because those fragments are embedded languages. I'll check what I need to do to fix this. I wonder about the pre tag too, I'll think about that.

@cursive-ide
Copy link
Owner

This is fixed for the next build, including a fix so that pre maintains its whitespace:

[:html {:lang "en"}
 [:head
  [:meta {:charset "UTF-8"}]
  [:title "Sparkfund Email"]
  [:style {:type "text/css"} ".example { color: red; }"]
  [:script {:type "text/javascript"} "alert('hello?');"]]
 [:body
  [:p "The content of the style and script tags is dropped."]
  [:style {:type "text/css"} ".example { color: red; }"]
  [:script {:type "text/javascript"} "alert('hello?');"]
  [:pre "
    What about the humble pre tag?
    which can have text on multiple lines?
  "]
  [:textarea "And textareas?"]
  [:foo "Or custom tags?"]]]

@cursive-ide cursive-ide modified the milestones: 1.8.2, 1.8.2-eap4 May 24, 2019
@cursive-ide cursive-ide added the bug Marks issues describing bugs label Sep 22, 2020
@cursive-ide cursive-ide added the released Marks issues which have had the fixes released in a stable build label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Marks issues describing bugs released Marks issues which have had the fixes released in a stable build
Projects
None yet
Development

No branches or pull requests

2 participants