or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli.mdcore-conversion.mdevent-system.mdextension-system.mdflavor-management.mdglobal-configuration.mdindex.mdinstance-configuration.md

core-conversion.mddocs/

0

# Core Conversion

1

2

Core conversion functionality for transforming between Markdown and HTML formats using the showdown.Converter class.

3

4

## Capabilities

5

6

### Converter Constructor

7

8

Creates a new Converter instance with optional configuration.

9

10

```javascript { .api }

11

/**

12

* Creates a new Showdown Converter instance

13

* @param converterOptions - Optional configuration object

14

* @returns New Converter instance

15

*/

16

new showdown.Converter(converterOptions?: ConverterOptions): Converter

17

```

18

19

**Usage Examples:**

20

21

```javascript

22

// Default converter

23

const converter = new showdown.Converter();

24

25

// Converter with options

26

const converter = new showdown.Converter({

27

tables: true,

28

strikethrough: true,

29

ghCodeBlocks: true,

30

tasklists: true

31

});

32

33

// Converter with extensions

34

const converter = new showdown.Converter({

35

extensions: ['my-extension']

36

});

37

```

38

39

### makeHtml

40

41

Converts Markdown text to HTML.

42

43

```javascript { .api }

44

/**

45

* Converts a markdown string into HTML

46

* @param text - Markdown text to convert

47

* @returns HTML string

48

*/

49

converter.makeHtml(text: string): string

50

```

51

52

**Usage Examples:**

53

54

```javascript

55

const converter = new showdown.Converter();

56

57

// Basic conversion

58

const html = converter.makeHtml('# Hello World');

59

console.log(html); // <h1 id="helloworld">Hello World</h1>

60

61

// Complex markdown

62

const markdown = `

63

# Title

64

65

This is **bold** and *italic* text.

66

67

- List item 1

68

- List item 2

69

70

\`\`\`javascript

71

console.log('Hello');

72

\`\`\`

73

`;

74

75

const html = converter.makeHtml(markdown);

76

```

77

78

### makeMarkdown

79

80

Converts HTML back to Markdown format.

81

82

```javascript { .api }

83

/**

84

* Converts HTML into Markdown

85

* @param src - HTML string to convert

86

* @param HTMLParser - Optional HTML parser to use

87

* @returns Markdown string

88

*/

89

converter.makeMarkdown(src: string, HTMLParser?: any): string

90

```

91

92

**Usage Examples:**

93

94

```javascript

95

const converter = new showdown.Converter();

96

97

// Basic HTML to Markdown

98

const markdown = converter.makeMarkdown('<h1>Hello World</h1>');

99

console.log(markdown); // # Hello World

100

101

// Complex HTML

102

const html = `

103

<h1>Title</h1>

104

<p>This is <strong>bold</strong> and <em>italic</em> text.</p>

105

<ul>

106

<li>List item 1</li>

107

<li>List item 2</li>

108

</ul>

109

`;

110

111

const markdown = converter.makeMarkdown(html);

112

```

113

114

### makeMd

115

116

Alias for `makeMarkdown` method.

117

118

```javascript { .api }

119

/**

120

* Alias for makeMarkdown - converts HTML into Markdown

121

* @param src - HTML string to convert

122

* @param HTMLParser - Optional HTML parser to use

123

* @returns Markdown string

124

*/

125

converter.makeMd(src: string, HTMLParser?: any): string

126

```

127

128

**Usage Examples:**

129

130

```javascript

131

const converter = new showdown.Converter();

132

133

// Same functionality as makeMarkdown

134

const markdown = converter.makeMd('<p><strong>Bold text</strong></p>');

135

console.log(markdown); // **Bold text**

136

```

137

138

## Error Handling

139

140

The conversion methods handle various edge cases:

141

142

```javascript

143

const converter = new showdown.Converter();

144

145

// Empty or falsy input returns the input as-is

146

console.log(converter.makeHtml('')); // ''

147

console.log(converter.makeHtml(null)); // null

148

console.log(converter.makeHtml(undefined)); // undefined

149

150

// Invalid HTML for makeMarkdown may produce unexpected results

151

// Always validate input when converting user-provided HTML

152

```

153

154

## Performance Considerations

155

156

- Converter instances can be reused for multiple conversions

157

- Creating multiple converters with the same options is inefficient

158

- Large documents may benefit from chunking or streaming approaches

159

- Extensions can significantly impact conversion performance