showdown icon indicating copy to clipboard operation
showdown copied to clipboard

Cannot set any option using setOption()

Open sunzhaoyuan opened this issue 6 years ago • 9 comments

I initialize showdown object on the frontend side by doing something like

var converter = new showdown.Converter({'tables': true});
// some code ...
html = converter.makeHtml(markdownText);

If I print all options, I can see the tables is set to true.

{omitExtraWLInCodeBlocks: false, prefixHeaderId: false, tables: true}

However, it cannot interpret my table in md format, instead it only put it around a <p></p> For example

<p>| Tables       |      Are          |  Cool     |
|----------    |:-------------:    |------:    |
| col 1 is     |  left-aligned     | $1600    |
| col 2 is     |    centered       |   $12    |
| col 3 is     | right-aligned     |    $1    |</p>

I've also tried to use converter.setOption('tables', true); or showdown.setOption('tables', true);, but neither of them worked.

I wonder if I set something wrong or I can only set options on the server (backend) side?

sunzhaoyuan avatar Jan 30 '19 04:01 sunzhaoyuan

I found out that setOption() can be only used on the server side. However I used browserify to solve this problem. (Sorry, I don't know if I am allowed to put a link here, if not please tell me and I'll remove it)

Browserify allows you to "require" an object just like node.js. So on the top of my file, I simply putted

    var showdown = require('showdown');

and then use browserify to compile the js file. It solved my issue.

sunzhaoyuan avatar Jan 30 '19 06:01 sunzhaoyuan

if this is really happening, it seems like it's really a bug

obedm503 avatar Jan 30 '19 18:01 obedm503

ok since I am not a pro web developer, I will reopen this issue and leave the discussions/decisions to pros. But if anyone who encounters the same problem, please consider this solution as it solved mine pretty well.

sunzhaoyuan avatar Jan 30 '19 19:01 sunzhaoyuan

I will look into it, but I've performed a quick test and couldn't reproduce the issue.

tivie avatar Feb 08 '19 17:02 tivie

https://codepen.io/cshanejennings/pen/dLPJqg I don't see the inverse working here (attempting to convert html to markdown), but no idea if I'm doing something wrong, just started working with your library.

I should add I'm referencing the lib from the CDN here: https://cdn.jsdelivr.net/npm/[email protected]/dist/showdown.min.js

cshanejennings avatar Apr 01 '19 18:04 cshanejennings

Just for a quick update, I'm currently looking at this issue.

tivie avatar Apr 18 '19 00:04 tivie

Any updates on the issue?

I can't get tables working, too, in a web browser. I tried the following lines of code:

  • var converter = new showdown.Converter({tables: true});
  • var converter = new showdown.Converter({tables: "true"});
  • converter.setOption("tables", true);
  • converter.setOption("tables", "true");

None of them works: I just get <p>|my|table|</p>

EDIT:

Looks like there's an issue with table parser. This table works fine (and hence tables option):

| Header1 | Header2 |
|---|---|
| Value1 | Value2 |

kornerr avatar May 14 '19 10:05 kornerr

I also am unable to set the option 'SimplifiedAutoLink' to true using

    converter.setOption({SimplifiedAutoLink: true}),

michaelpalumbo avatar Sep 05 '19 19:09 michaelpalumbo

I was researching on a way how to pass params to extensions. The setOption({}) does not work form me either. However here is one more way to approach it.

kuncevic avatar Aug 26 '21 11:08 kuncevic