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

Does not recognise custom html elements #283

Closed
timoxley opened this issue Nov 12, 2013 · 6 comments
Closed

Does not recognise custom html elements #283

timoxley opened this issue Nov 12, 2013 · 6 comments
Labels
has PR The issue has a Pull Request associated NFS - new feature (spec related)

Comments

@timoxley
Copy link

tldr;

Custom html elements are coming, and marked does not currently recognise them as valid html. Custom elements may have different escaping requirements for their content based on whether the elements contains more elements (like div) or plain text (like script). Perhaps it would be possible to pass which html tags to escape/not escape as configuration properties.

Backstory

I've been experimenting with custom elements and I wanted to inject some into my markdown presentation.

## Shadow DOM is a sub-tree inside a DOM node
#### Like a mini-iframe that replaces an Element.

<h3>Light DOM</h3>

```html
<h3>Light DOM</h3>
`` `
<play-script>
var heading = currentSlide.querySelector('h3')
var root = heading.createShadowRoot()
root.innerHTML = '<a href="#">Shadow DOM</a>'
</play-script>

Source

play-script is essentially a script tag that renders its content, highlighted with highlight.js, and executes only when you click on it.

Problem: currently marked does not recognise tags with hyphens in them as valid html. To get around this quickly, I loosened the html detection regex to also match tags with a single hypen:

Source

-  + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|@)\\b';
+  + '|span|br|wbr|ins|del|img)\\b)[\\w-]+(?!:/|@)\\b';

This successfully recognised my custom tag play-script as html, but it raised a new issue:

My custom tag's content was text as opposed to more xml tags, so marked would html-escape all of my script contents. This was no good since I wanted that text to remain as executable script (perhaps I should have looked at unescaping).

So as a hack to make it work, I reluctantly added my specific tag, (and the template tag) as special-cased to avoid escaping, along with style, pre and script:

-        pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
+        pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style' || cap[1] === 'play-script' || cap[1] === 'template',

Source

Special-casing my custom element is clearly not at all a solution, but perhaps the tags that are matched here could be passed in as configuration properties.

@martypdx
Copy link

+1

3 similar comments
@mikomatic
Copy link

+1

@bsr203
Copy link

bsr203 commented Dec 10, 2014

+1

@lkiarest
Copy link

+1

@joshbruce
Copy link
Member

See #956

FF was a hold out on implementing this until the spec stabilized. Working on cleaning house, thank you for the PR.

https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements

@joshbruce
Copy link
Member

#985

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has PR The issue has a Pull Request associated NFS - new feature (spec related)
Projects
None yet
Development

No branches or pull requests

6 participants