question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom element in `<head>`

See original GitHub issue

I came upon this today, I am developing a Static Website Generator and I want to allow for layout templates like:

<html>
  <head>
    <site-include type="partial" name="scripts"></site-include>
  </head>
</html>

So here you see the tag site-include denotes where a partial page should be included (in this case the scripts partial page in the head).
In my C# code I then QuerySelector the site-include and ReplaceWith the partial.
But or course the problem is that when I use the HTMLParser the above template gets turne into:

<html>
  <head>
  </head>
  <body>
   <site-include type="partial" name="scripts"></site-include>
  </body>
</html>

Is there any option I can set to the HTMLParser to allow custom elements inside the <head>?
I believe your parser is working as is correct for browsers, but it is not what I need for my purposes.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
LukeTOBriencommented, May 13, 2022

3rd time lucky 😉

1reaction
LukeTOBriencommented, Jan 21, 2022

why you use an HTML5 conform parser if what you input is not HTML5

I guess I didn’t realise it would do this, I have used AngleSharp in the past and had the idea of using it with this project.
An option to make the parser non HTML5 conformant would be the solution… But I could look at using XML like you say, the System.Xml.Linq namespace has similar manipulation methods, so I will give this a try.

(I don’t want to change your SSG - just want to see if there is any other option besides changing a lib that is used underneath)

At this stage I am just doing unit tests and experimenting to see what direction to go in.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are HTML5 custom elements allowed in <HEAD>
My question is, can HTML5 custom-elements be used in HEAD? ... is moving the custom element out of the head section, into the...
Read more >
Google's John Mueller Warns Against Custom Elements In ...
Custom elements in document heads can disrupt Google's rendering, potentially harming SEO; JSON-LD offers a flexible alternative.
Read more >
Custom code in head and body tags
Custom code entered in the Head code section appears before the closing </head> tag in your site's HTML markup and applies to your...
Read more >
Using custom elements - Web APIs | MDN
Autonomous custom elements are standalone — they don't inherit from standard HTML elements. You use these on a page by literally writing them ......
Read more >
Components: <Head>
Add custom elements to the `head` of your page with the built-in Head ... We expose a built-in component for appending elements to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found