Showdown: Possible to suppress the encapsulating <p> tags?

Created on 20 Aug 2018  路  2Comments  路  Source: showdownjs/showdown

I'm attempting to use this library more for just some basic text styling on some strings that will be injected into HTML thereafter. So, I'd like to turn something like this:
Please do **this thing** more than that thing

in to:

Please do <strong>this thing</strong> more than that thing

Without the rest of the markup I'm currently getting:

<p>Please do <strong>this thing</strong> more than that thing

Which is causing issues with my implementation.

I didn't see a sign of it in the docs, but is it possible to only support certain elements of markdown (like bolding/italics/etc), suppress the encapsulating tags, or anything else I could use to address this?

Thanks!

help wanted

Most helpful comment

Hey @Dygerati

Showdown does not support selective conversion (the ability to only parse and convert certain markdown elements).

Depending on your requirements, though, you can create an extension that removes disallowed "tags".

example (fiddle here):

showdown.extension('only-inline-stuff', function () {
  return [{
    type: 'output',
    filter: function (text) {
      // remove paragraphs
      text = text.replace(/<\/?p[^>]*>/g, '');

      // remove code (if you want)
      text = text.replace(/<\/?code[^>]*>/g, '');

      //add other stuff here that you want to remove
      // text = text.replace(, '');
      return text;
    }
  }];
});

All 2 comments

Hey @Dygerati

Showdown does not support selective conversion (the ability to only parse and convert certain markdown elements).

Depending on your requirements, though, you can create an extension that removes disallowed "tags".

example (fiddle here):

showdown.extension('only-inline-stuff', function () {
  return [{
    type: 'output',
    filter: function (text) {
      // remove paragraphs
      text = text.replace(/<\/?p[^>]*>/g, '');

      // remove code (if you want)
      text = text.replace(/<\/?code[^>]*>/g, '');

      //add other stuff here that you want to remove
      // text = text.replace(, '');
      return text;
    }
  }];
});

@Dygerati Closing issue (no activity for 26 days). Feel free to reopen the issue, if you feel you still need help.


Donate Click here to lend your support to: ShowdownJS website and testing platform and make a donation at paypal.com

As you know, ShowdownJS is a free library and it will remain free forever. However, maintaining and improving the library costs time and money.
If you like our work and find our library useful, please donate through Pledgie or directly through paypal!! Your contribution will be greatly appreciated and help us continue to develop this awesome library.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KirkMunro picture KirkMunro  路  6Comments

xduseko picture xduseko  路  3Comments

evanplaice picture evanplaice  路  3Comments

reisraff picture reisraff  路  5Comments

ifeltsweet picture ifeltsweet  路  6Comments