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

Enhance rule MD033 to be more specific #494

Open
mvilrokx opened this issue Mar 19, 2024 · 0 comments
Open

Enhance rule MD033 to be more specific #494

mvilrokx opened this issue Mar 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@mvilrokx
Copy link

Describe the Enhancement:

I want to be able to narrow the scope of allowable HTML tags beyond just the tag name.

Impacted Rules:

MD033

Describe the Need:

I want to use rule MD033/no-inline-html, but there are genuine reasons to use some HTML Tags over plain markdown in certain cases. E.g. I only want to allow the usage of the <img> tag if that tag has a style, width or height attribute. Or, to put it another way: I do not want to allow the usage of the <img> tag if it only has attributes src and/or alt.

The reason behind this is that an <img> tag that has just a src or alt attribute can be perfectly described in plain Markdown:

<img src="./picture.png" alt="a picture" />

becomes

![a picture](./picture.png)

If it has any other attribute, it cannot be converted to a Markdown tag without affecting the way it gets rendered:

<img src="./picture.png" alt="a picture" height="100px" width="100px" />
<img src="./picture.png" alt="a picture" style="display: block; margin-left: auto; margin-right: auto; float: none; />

And therefor I would consider this acceptable usage of the <img> tag.

The problem is that the rule only allows exceptions at the "tag" level, e.g. "allowed_elements": ["img"]. I want to be able to narrow the scope by adding exceptions to this.

Current Alternative

Set "allowed_elements": ["img"], but this will allow all <img> tags whereas I only want to allow some.

Can We Help You Implement This?:

Yes, but I'd first like to get some input if this is deemed useful.

If it is, we need to discuss how this would be configured. Some examples:

Original:

{
  "MD033": {
    "allowed_elements": [
      "img"
    ]
  }
}

Enhancement:

{
  "MD033": {
    "allowed_elements": [{
        "img": {
          "except_if_it_contains_only_these_attributes": ["src", "alt"]
        }
    }]
  }
}

(sorry about the name, suggestions are welcome :-))

This would allow the <img> tag, except if it contains only src or only alt or only both

Alternative Enhancement:

{
  "MD033": {
    "allowed_elements": [{
        "img": {
          "allowed_attributes": ["style", "width", "height"]
        }
    }]
  }
}

This would allow the <img> tag, but only if it contains any of "style", "width" or "height" (or any combination).

To be honest I am not sure how useful the later suggestion is since there are many other attributes that could be used on <img> tags that are not convertible to plain markdown, e.g. title, and I would want to exclude those to but then the list in allowed_attributes would have to contain all attributes except src and alt.

@mvilrokx mvilrokx added the enhancement New feature or request label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant