Skip to content

Commit 68077a2

Browse files
feat(markdown-converter): add tag to allow html
1 parent 1e5cf47 commit 68077a2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/utilities/src/utilities/markdownToHtml/__tests__/markdownToHtml.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ describe('Markdown converter utility', () => {
2525
expect(output).toBe(expected);
2626
});
2727

28-
it('return the converted string without carbon classes', () => {
29-
const output = markdownToHtml(str, { useCarbonClasses: false });
30-
const expected = 'This is <em>italic</em> and <strong>bold</strong>.';
28+
it('return the converted string without carbon classes and allowing html', () => {
29+
const output = markdownToHtml(str, {
30+
allowHtml: true,
31+
useCarbonClasses: false,
32+
});
33+
const expected =
34+
'This <p>is</p> <input value="something" /> <em>italic</em> and <strong>bold</strong>.';
3135
expect(output).toBe(expected);
3236
});
3337
});

packages/utilities/src/utilities/markdownToHtml/markdownToHtml.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const _fixDoubleSpaces = str => str.replace(_doubleSpaceRegex, ' ');
4040
* @param {object} [options={}] Object with options for the conversion
4141
* @param {boolean} [options.italic=false] Defines if should convert italic
4242
* @param {boolean} [options.bold=false] Defines if should convert bold
43+
* @param {boolean} [options.allowHtml=false] Defines if should allow or remove html tags
4344
* @param {boolean} [options.useCarbonClasses=true] Defines if should use carbon typography classes
4445
* @returns {string} String converted to html
4546
* @example
@@ -50,10 +51,15 @@ const _fixDoubleSpaces = str => str.replace(_doubleSpaceRegex, ' ');
5051
*/
5152
function markdownToHtml(
5253
str,
53-
{ italic = false, bold = false, useCarbonClasses = true } = {}
54+
{
55+
italic = false,
56+
bold = false,
57+
allowHtml = false,
58+
useCarbonClasses = true,
59+
} = {}
5460
) {
5561
const isAllStyles = !italic && !bold;
56-
let converted = _removeHtmlTags(str);
62+
let converted = allowHtml ? str : _removeHtmlTags(str);
5763

5864
if (italic || isAllStyles) {
5965
converted = converted.replace(_italicRegex, (match, p1) => {

0 commit comments

Comments
 (0)