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

Custom elements not supported #239

Closed
thomaswilburn opened this issue Dec 8, 2014 · 11 comments
Closed

Custom elements not supported #239

thomaswilburn opened this issue Dec 8, 2014 · 11 comments
Labels

Comments

@thomaswilburn
Copy link

We use CommonMark as our document parser at the Seattle Times on some special projects, and it has problems recognizing our custom elements when we try to insert them into the document as HTML. For example, this is not recognized:

<responsive-frame src="example.com"></responsive-frame>

A workaround is that we can wrap it in a known HTML element, such as a div, and that will be recognized:

<div>
  <responsive-frame src="example.com"></responsive-frame>
</div>

But this is ugly, and it goes against the point of our custom elements, which is to be more usable for non-technical producers. Can we get the HTML parser to recognize these valid elements as HTML?

@jgm
Copy link
Member

jgm commented Dec 8, 2014

Currently the spec hard-codes a list of HTML block elements (and this isn't one, obviously). But, in response to some other issues, I'm thinking of changing the spec to hard-code the elements that can NOT start HTML blocks, instead. That would solve your problem.

@thomaswilburn
Copy link
Author

That sounds like a good solution, thanks.

@colinodell
Copy link
Contributor

+1 I like the idea of blacklisting elements instead

@jgm
Copy link
Member

jgm commented Dec 13, 2014

@jgm
Copy link
Member

jgm commented Dec 13, 2014

So, here's the plan. Both items need to be implemented in the spec, in the C parser, and in the JS parser.

  1. Change from whitelisting elements that can start HTML blocks to blacklisting elements that can't start HTML blocks.
  2. Change the scanner for HTML tags to allow interior hyphens.

@puzrin
Copy link
Contributor

puzrin commented Dec 13, 2014

How are you going to define, if certain custom tag can or can not start html blocks?

@jgm
Copy link
Member

jgm commented Dec 14, 2014

@puzrin, my idea had been that any HTML tag that begins a block, except for a select few designated ones that are used for span-level content, would start an HTML block. But that's a bit crude, as in principle one might define a span-level custom tag and decide to start a paragraph with it.

Of course, one could go to a system where custom tags can be registered as block or inline tags through options to the program or library. I'd rather avoid that, though -- and even with the tags that HTML provides, we face many cases of ambiguity. For example, is <del> at the beginning of a line meant to enclose the entire paragraph (a block) or should it be interpreted as an inline tag inside the paragraph?

I'm very much tempted by the following rule, which is easy to remember and use: to start an HTML block, put a single HTML tag on a line by itself. (The block then continues until...etc.) Thus,

<del>
Content inside block-level tags.
</del>

<del>A paragraph with inline-level tags.</del>

With this rule, we wouldn't need to build in any distinction between block-level and span-level HTML tags.

The main worry here would be about backwards compatibility, since existing Markdown processors don't have this restriction.

An alternative system would use a mix of heuristics, following the current CommonMark spec for known HTML elements, but using the rule above for unknown ones. Aesthetically, this is ugly, but it might achieve more backwards compatibility.

@thomaswilburn
Copy link
Author

I could live with that for custom elements, although I also think it'd be okay to just treat custom elements as block level by default, personally.

@jgm jgm added the spec label Dec 23, 2014
@jgm
Copy link
Member

jgm commented Dec 29, 2014

@jgm jgm closed this as completed in cf2956f Jul 11, 2015
jgm added a commit to commonmark/cmark that referenced this issue Jul 11, 2015
jgm added a commit to commonmark/commonmark.js that referenced this issue Jul 11, 2015
This allows for custom tags, which in HTML5 MUST contain
a hyphen.  See commonmark/commonmark-spec#239.
@jgm
Copy link
Member

jgm commented Jul 11, 2015

@thomaswilburn - Note the following.

<responsive-frame src="example.com">
</responsive-frame>

will be treated as a raw HTML block, and reproduced verbatim.

<responsive-frame src="example.com"></responsive-frame>

will be treated as a paragraph with inline HTML tags, and reproduced with <p>...</p> surrounding it.

See the new spec for HTML blocks (still in master, not published) for further details on how this works.

@thomaswilburn
Copy link
Author

Awesome, thanks John.

talum pushed a commit to github/cmark-gfm that referenced this issue Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants