@@ -11,6 +11,7 @@ const _boldRegex = /[_*]{2}(.*?)[_*]{2}/g;
11
11
*
12
12
* @param {string } str String to be checked for html tags
13
13
* @returns {string } String with html tags stripped out
14
+ * @private
14
15
*/
15
16
const _removeHtmlTags = str => str . replace ( _htmlTagRegex , '' ) ;
16
17
@@ -19,31 +20,38 @@ const _removeHtmlTags = str => str.replace(_htmlTagRegex, '');
19
20
*
20
21
* @param {string } str String to be checked for double spaces
21
22
* @returns {string } String with html double spaces fixed
23
+ * @private
22
24
*/
23
25
const _fixDoubleSpaces = str => str . replace ( _doubleSpaceRegex , ' ' ) ;
24
26
25
27
/**
26
28
* Converts some markdown syntaxes into html
27
- * It's not a full markdown-to-html converter
28
- * It currently supports two syntaxes: Bold and Italic
29
- * Bold: Double asterisk (**) or double underscore (__).
30
- * Bold examples: **Lorem ipsum** __dolor__
31
- * Italic: Single asterisk (*) or single underscore (_)
32
- * Italic examples: _Lorem ipsum_ *dolor*
29
+ * <p>It's not a full markdown-to-html converter</p>
30
+ * <p>It currently supports two syntaxes: <strong>Bold</strong> and <em>Italic</em></p>
31
+ * <ul>
32
+ * <li>Bold: Double asterisk (**) or double underscore (__).</li>
33
+ * <li>Bold examples: **Lorem ipsum** __dolor__</li>
34
+ * <li>Italic: Single asterisk (*) or single underscore (_)</li>
35
+ * <li>Italic examples: _Lorem ipsum_ *dolor*</li>
36
+ * </ul>
37
+ *
33
38
*
34
39
* @param {string } str String to convert to html
35
- * @param {object } options Object with options for the conversion
36
- * @param {boolean } options.italic Defines if should convert italic
37
- * @param {boolean } options.bold Defines if should convert bold
38
- * @param {boolean } options.useCarbonClasses If true uses carbon typography classes
40
+ * @param {object } [ options={}] Object with options for the conversion
41
+ * @param {boolean } [ options.italic=false] Defines if should convert italic
42
+ * @param {boolean } [ options.bold=false] Defines if should convert bold
43
+ * @param {boolean } [ options.useCarbonClasses=true] Defines if should use carbon typography classes
39
44
* @returns {string } String converted to html
40
45
* @example
41
46
* import { markdownToHtml } from '@carbon/ibmdotcom-utilities';
42
47
*
43
48
* markdownToHtml('Lorem _ipsum_ __dolor__ *sit* **amet**.')
44
49
* // 'Lorem <em>ipsum</em> <strong>dolor</strong> <em>sit</em> <strong>amet</strong>.'
45
50
*/
46
- function markdownToHtml ( str , { italic, bold, useCarbonClasses } = { } ) {
51
+ function markdownToHtml (
52
+ str ,
53
+ { italic = false , bold = false , useCarbonClasses = true } = { }
54
+ ) {
47
55
const isAllStyles = ! italic && ! bold ;
48
56
let converted = _removeHtmlTags ( str ) ;
49
57
0 commit comments