Skip to content

[markdown] A way to prevent wrapping generated HTML with <p> tags when there is no need for them #101

@DmitrySharabin

Description

@DmitrySharabin

The Markdown plugin uses the Showdown library under the hood. And wrapping markdown in paragraph tags is the default behavior that might cause some issues and sometimes highly undesirable (e.g., see https://codepen.io/dmitrysharabin/pen/zYwxEPJ?editors=1100).

It is not a rare problem at all. There are issues concerning it in the Showdown repo as well:

As @tivie mentioned in their comment: Showdown does not support selective conversion (the ability to only parse and convert certain markdown elements), however, one can create an extension that removes disallowed “tags”.

So, we could add this code (with some modifications if needed) to our plugin:

showdown.extension("remove-extra-paragraphs", function () {
  return [{
    type: "output",
    filter: function (markdown) {
      return markdown.replace(/<\/?p[^>]*>/g, "");
    }
  }];
});

However, we need to decide whether we want this extension to be enabled plugin-wise or property-wise. If plugin-wise, how can we distinguish when to apply some extra transformations on the markdown and when don't? If property-wise, should authors add some extra attributes to the property, or maybe they should add a class?

Are there any other cases we should take into account?

@LeaVerou @karger What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions