Skip to content

HTML Attributes without quote is broken #1141

Closed

Description

@rhysd

Marked version: 0.3.17

Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown

Expectation

Marked can handle HTML attributes without quote like <a href=https://example.com></a> in markdown doc. It should be converted into <p><a href="https://example.com"></a></p>, the same as <a href="https://example.com"></a>.

Result

Converted into broken HTML <p>&lt;a href=<a href="https://example.com&gt;">https://example.com&gt;</a></a></p>

What was attempted

  1. npm install marked
  2. Put following code to foo.js
  3. Run node foo.js
const marked = require('marked');
console.log(marked('<a href=https://example.com></a>'));

Call stack & console log

<p>&lt;a href=<a href="https://example.com&gt;">https://example.com&gt;</a></a></p>

though I expected

<p><a href="https://example.com"></a></p>

Activity

  1. added 3 commits that reference this issue on Mar 14, 2018
    eae48f4
    df91b03
    ca38265
  2. joshbruce commented on Mar 23, 2018

    @joshbruce
    Member

    Not sure I agree with this desired behavior actually; see HTML spec: https://www.w3.org/TR/html52/dom.html#elements

    There is no example in which the HTML attributes exist without quotation. Therefore, this may be one of those moments of should we do this. Do we really want to begin creating the habit of not encasing attribute values in quotes? What value is there to the developer?

    <[element name] [attribute]="[value(s)]">
    
    <[element name] [attribute]="[value(s)]">[content]</[element name]>
    
    <!-- not, strictly speaking, valid HTML -->
    <[element name] [attribute]=[value(s)]>
    
    <[element name] [attribute]=[value(s)]>[content]</[element name]>

    Allowing for non quoted attributes also could make it harder on Marked because we have to cover both use cases - quoted and non-quoted. What happens with the following case:

    <a class=something something-else one-more-class>Hello, World!</a>

    How do we determine what to encapsulate in quotes?

  3. joshbruce commented on Mar 23, 2018

    @joshbruce
    Member

    Ps. Also not sure this is referenced in the CommonMark and GFM specs. If it is, please point us to the proper example.

  4. UziTech commented on Mar 23, 2018

    @UziTech
    Member

    From CommonMark spec:

    An attribute value consists of an unquoted attribute value, a single-quoted attribute value, or a double-quoted attribute value.

    https://spec.commonmark.org/0.28/#attribute-value

    An unquoted attribute value would only be up to whitespace so your example would be encapsulated as follows:

    <a class="something" something-else one-more-class>Hello, World!</a>
  5. joshbruce commented on Mar 23, 2018

    @joshbruce
    Member

    @UziTech: Thanks for the spec reference. I don't see any examples that actually use unquoted attributes. Having said that, I ran tests against a couple of the examples from the spec and none of them pass.

  6. added
    L1 - broken
    and removed on Mar 23, 2018
  7. UziTech commented on Mar 23, 2018

    @UziTech
    Member

    Some of them might be fixed by #1135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L1 - brokenhelp wantedparser: CommonMark

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions