luckyframework / website

The Lucky website
https://luckyframework.org
37 stars 66 forks source link

It only converts tags inside the <body> #358

Open jwoertink opened 4 years ago

jwoertink commented 4 years ago

HTML to convert

<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>Theme</title>

  <!-- Custom fonts for this theme -->
  <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">

  <!-- Theme CSS -->
  <link href="css/theme.min.css" rel="stylesheet">

</head>

<body id="page-top">
  <h1>Hi</h1>
</body>
</html>

Lucky response

h1 "Hi"
edwardloveall commented 4 years ago

Good point. I haven't needed this feature but I imagine someone will. Shouldn't be too hard to add once we get around to it.

jwoertink commented 4 years ago

Yeah, I have a theme I want to use, but wanted to just get the layout out of the way, and noticed that didn't work 😅

paulcsmith commented 4 years ago

It's because html2lucky does not approve of the theme. Need to find another one 😂

But seriously I also ran into this when doing a page layout with TailwindUI I wanted to convert

jwoertink commented 4 years ago

Alright, after spending WAY more time than I care to admit on this, it will not be possible to do at this time.

Both of the myhtml and lexbor shards treat the parsing the same as the browser in which it sees HTML snippets as invalid markup so it adds in the missing elements. If we used one of these, the side affect would be that the output would always contain head and body tags no matter what you passed in.

I also took a look at the crystagiri shard which just uses the built-in crystal XML parser. I also tried using the parser natively. The issue with these are that XML parsing doesn't view attributes like @flow-id="thing" as valid, so it skips those. The other issue is that with XML, it doesn't have an idea of set tags. This means that when it parses something like:

<meta content="">
<meta content="">

what the XML parser sees is <Node name="meta" children=[<Node name="meta">]>. The second meta becomes a child of the first and then they mess up everything after because there's no </meta>. You'd have to parse them as self-closing tags for it to work <meta />.

I have an idea for this, but I'll open up the PR to talk more about it.