How to use the Converter function from showdown

Find comprehensive JavaScript showdown.Converter code examples handpicked from public code repositorys.

showdown.Converter is a tool that converts Markdown-formatted text into HTML code.

2
3
4
5
6
7
8
9
10
11
12
const path = require('path')
const rimraf = require('rimraf')
const handlebars = require('handlebars')
const showdown = require('showdown')
const moment = require('moment')
const converter = new showdown.Converter({ tables: true })


const publicPath = path.join(__dirname, '..', 'public')
const templates = {}

fork icon218
star icon403
watch icon70

34
35
36
37
38
39
40
41
42
43
      replace: '<a href="$1_c.html$2">'
    }
  ]
})

const converter = new showdown.Converter({
  tables: true,
  ghCodeBlocks: true,
  ghCompatibleHeaderId: true,
  encodeEmails: true,
fork icon73
star icon117
watch icon14

How does showdown.Converter work?

showdown.Converter is a JavaScript library that allows developers to convert Markdown-formatted text into HTML code. The library works by first parsing the Markdown text into an Abstract Syntax Tree (AST), which represents the structure of the text in a way that can be easily processed by the library. Once the AST is generated, the library applies a series of transformations to convert the text into HTML. These transformations include converting Markdown syntax such as headings, emphasis, and lists into their corresponding HTML tags, as well as applying custom extensions and filters that can modify the output as needed. To use showdown.Converter in a JavaScript program, developers first create an instance of the Converter class by calling the showdown.Converter constructor. They can then call the makeHtml method on the instance with a string of Markdown-formatted text as an argument. This will return a string of HTML code that represents the converted text. Overall, showdown.Converter provides an easy-to-use solution for converting Markdown text into HTML, making it a popular choice for web developers who want to allow users to input and display formatted text in their applications.

63
64
65
66
67
68
69
70
71

  if (enableHighlight) {
    options.extensions.push(showdownHighlight)
  }

  const converter = new showdown.Converter(options);

  return converter.makeHtml(markdown);
}
fork icon40
star icon633
watch icon11

25
26
27
28
29
30
31
32
33
34
  },
};

beforeEach(() => {
  showdown.Converter.mockClear();
  showdown.Converter().makeHtml.mockClear();
  req.body.descriptionHtml = undefined;
  req.body.youtubeVideoId = undefined;
  req.body.stackoverflowQuestionId = undefined;
});
fork icon58
star icon319
watch icon15

+ 101 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
const showdown = require("showdown");
const converter = new showdown.Converter();

const markdownText =
  "# Hello, world!\n\nThis is some **bold** and *italic* text.\n\n- List item 1\n- List item 2\n- List item 3";

const html = converter.makeHtml(markdownText);

console.log(html);

In this example, we first import the showdown library and create a new instance of the showdown.Converter class, which we assign to the variable converter. We then define a string of Markdown-formatted text and assign it to the variable markdownText. This text includes a heading, some bold and italic text, and a bulleted list. Next, we call the makeHtml method on the converter instance, passing markdownText as an argument. This method converts the Markdown text into HTML code and returns a string, which we assign to the variable html. Finally, we log the resulting html string to the console, which will output the following HTML code: html Copy code

141
142
143
144
145
146
147
148
149
150
151


// create Work Item via https://docs.microsoft.com/en-us/rest/api/azure/devops/
async function create(vm) {
  if (vm.env.logLevel >= 200) console.log(`Starting 'create' method...`);
  
  var converter = new showdown.Converter({tables: 'true'});
  var html = converter.makeHtml(vm.body);
  
  converter = null;

fork icon51
star icon55
watch icon3

+ 3 other calls in file

1
2
3
4
5
6
7
8
9
10
11
12
const { keys, trim, isEmpty, isNil, toLower, pick } = require('lodash');
const showdown = require('showdown');
const mime = require('mime');
const itemsImport = require('./helpers/simpleListImport');


const converter = new showdown.Converter();


// EN: This function is based on: @leebrary/helpers/prepareAsset
// EN: Esta función está basada en: @leebrary/helpers/prepareAsset
function getFileUrl(fileID) {
fork icon23
star icon67
watch icon4

54
55
56
57
58
59
60
61
62
63
  break;
case 'ghPage':
  const titleOfHtml = 'Developer Conferences in Taiwan';
  const descriptionOfHtml = '統整研討會資訊';
  const coverImgOfHtml = 'https://blog.ivanwei.co/images/2018/05/16/DCIT.png';
  const converter = new showdown.Converter({tables: true, extensions: ['targetlink']});

  function fixJson2Md (content) {
    return content.replace(/\n\ /g, ' ').replace(/(\n\d{1,2}|\)\n\n)/g, (substr) => {
      const month = substr.match(/\d{1,2}/);
fork icon8
star icon66
watch icon12

55
56
57
58
59
60
61
62
63
64
                )
        );
}

$onInit() {
        this.converter = new showdown.Converter({
                tables: true,
                strikethrough: true,
                omitExtraWLInCodeBlocks: true,
                parseImgDimensions: true,
fork icon8
star icon61
watch icon6

24
25
26
27
28
29
30
31
32

if (unsupportedContentTypes.length) {
  throw new Error(`Unknown content type: ${unsupportedContentTypes[0]}`);
}

this.converter = new showdown.Converter();

const referenceAttributes = this.options.references.map((ref) => {
  if (typeof ref === 'object') return ref.name;
fork icon8
star icon33
watch icon7

10
11
12
13
14
15
16
17
18
<script src="/path/to/xss/dist/xss.min.js"></script>
<script src="/path/to/showdown-xss-filter.js"></script>
```

```javascript
var converter = new showdown.Converter({ extensions: ['xssfilter'] })
var text = "<script>alert('xss!')</script>";
console.log(converter.makeHtml(text));
```
fork icon6
star icon31
watch icon16

+ 3 other calls in file

98
99
100
101
102
103
104
105
106

### Node

```js
var showdown  = require('showdown'),
    converter = new showdown.Converter(),
    text      = '#hello, markdown!',
    html      = converter.makeHtml(text);
```
fork icon9
star icon22
watch icon3

+ 7 other calls in file

9
10
11
12
13
14
15
16
17
18

var sdmath = require("../public/js/showdown/mathjax");
var showdown  = require('showdown'),
    sdtable = require('showdown-table'),
    sdprett = require('showdown-prettify'),
    converter = new showdown.Converter(
    {
        tables: true,
        ghCodeBlocks: true,
        tasklists: true,
fork icon1
star icon6
watch icon4

2
3
4
5
6
7
8
9
10
11
12
		typeof define === 'function' && define.amd ? define(['exports'], factory) :
			(factory((global.RCSIdomaticLogic = global.RCSIdomaticLogic || {})));
}(this, (function (exports) { 'use strict';


	const showdownPackage = typeof require === 'undefined' ? window.showdown : require('showdown');
	const showdownConverter = new showdownPackage.Converter();
	showdownConverter.setOption('simpleLineBreaks', true);
	showdownConverter.setOption('simplifiedAutoLink', true);
	showdownConverter.setOption('noHeaderId', true);
	showdownConverter.setOption('strikethrough', true);
fork icon1
star icon0
watch icon2

+ 51 other calls in file

208
209
210
211
212
213
214
215
216
217

// Correct the class:
$node.removeClass("EditableElement");
$node.addClass("EditableContent");

this.#converter = new showdown.Converter({
                noHeaderId: true,
                strikethrough: true,
                omitExtraWLInCodeBlocks: true,
                simplifiedAutoLink: false,
fork icon3
star icon0
watch icon15

-3
fork icon0
star icon0
watch icon1

+ 33 other calls in file

13
14
15
16
17
18
19
20
21
22
    body = fs.readFileSync(file, "utf8")
}

// Convert Markdown to HTML
if (convertMarkdown) {
    const converter = new showdown.Converter()
    body = converter.makeHtml(body)
}

return body
fork icon0
star icon0
watch icon1

+ 6 other calls in file

18
19
20
21
22
23
24
25
26
27
28
const moment = require("moment");
const textDiff = require("text-diff");
const diff = new textDiff();


const showdown = require("showdown");
const md = new showdown.Converter({
	tables: true,
	simplifiedAutoLink: true,
	strikethrough: true,
	tasklists: true,
fork icon0
star icon0
watch icon1

92
93
94
95
96
97
98
99
100
101


module.exports = {
    capitalize,
    formatMoney,
    numberToString,
    showdown: new showdown.Converter(),
    transformToPercentage,
    getFlagEmoji,
};
fork icon0
star icon0
watch icon1

+ 28 other calls in file

7
8
9
10
11
12
13
14
15
16
17
18
var snippets = require('./snippets');
var init_state = require('./init_state.json');




// All mu globals
var g_converter = new showdown.Converter();
var g_elements_orig = init_state.elements;
var g_custome_sidebar_open = false
var g_custome_sidebar_header = "Nothing to see here"
var g_custome_sidebar_content = "yet..."
fork icon0
star icon0
watch icon1

+ 6 other calls in file