Commit d72d55fc authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '227598-make-list-bullet-char-configurable' into 'master'

Static Site Editor: Allow to configure unordered lists bullet chars

See merge request gitlab-org/gitlab!36820
parents a43489c1 ff488958
/* eslint-disable @gitlab/require-i18n-strings */
import { defaults, repeat } from 'lodash'; import { defaults, repeat } from 'lodash';
const DEFAULTS = { const DEFAULTS = {
subListIndentSpaces: 4, subListIndentSpaces: 4,
unorderedListBulletChar: '-',
}; };
const countIndentSpaces = text => { const countIndentSpaces = text => {
...@@ -11,9 +13,12 @@ const countIndentSpaces = text => { ...@@ -11,9 +13,12 @@ const countIndentSpaces = text => {
}; };
const buildHTMLToMarkdownRender = (baseRenderer, formattingPreferences = {}) => { const buildHTMLToMarkdownRender = (baseRenderer, formattingPreferences = {}) => {
const { subListIndentSpaces } = defaults(formattingPreferences, DEFAULTS); const { subListIndentSpaces, unorderedListBulletChar } = defaults(
// eslint-disable-next-line @gitlab/require-i18n-strings formattingPreferences,
DEFAULTS,
);
const sublistNode = 'LI OL, LI UL'; const sublistNode = 'LI OL, LI UL';
const unorderedListItemNode = 'UL LI';
return { return {
TEXT_NODE(node) { TEXT_NODE(node) {
...@@ -47,6 +52,11 @@ const buildHTMLToMarkdownRender = (baseRenderer, formattingPreferences = {}) => ...@@ -47,6 +52,11 @@ const buildHTMLToMarkdownRender = (baseRenderer, formattingPreferences = {}) =>
return reindentedList; return reindentedList;
}, },
[unorderedListItemNode](node, subContent) {
const baseResult = baseRenderer.convert(node, subContent);
return baseResult.replace(/^(\s*)([*|-])/, `$1${unorderedListBulletChar}`);
},
}; };
}; };
......
---
title: Set default bullet char character as - when generating markdown in Static Site Editor
merge_request: 36820
author:
type: other
...@@ -47,4 +47,24 @@ describe('HTMLToMarkdownRenderer', () => { ...@@ -47,4 +47,24 @@ describe('HTMLToMarkdownRenderer', () => {
expect(baseRenderer.convert).toHaveBeenCalledWith(NODE, list); expect(baseRenderer.convert).toHaveBeenCalledWith(NODE, list);
}); });
}); });
describe('UL LI visitor', () => {
it.each`
listItem | unorderedListBulletChar | result | bulletChar
${'* list item'} | ${undefined} | ${'- list item'} | ${'default'}
${' - list item'} | ${'*'} | ${' * list item'} | ${'*'}
${' * list item'} | ${'-'} | ${' - list item'} | ${'-'}
`(
'uses $bulletChar bullet char in unordered list items when $unorderedListBulletChar is set in config',
({ listItem, unorderedListBulletChar, result }) => {
htmlToMarkdownRenderer = buildHTMLToMarkdownRenderer(baseRenderer, {
unorderedListBulletChar,
});
baseRenderer.convert.mockReturnValueOnce(listItem);
expect(htmlToMarkdownRenderer['UL LI'](NODE, listItem)).toBe(result);
expect(baseRenderer.convert).toHaveBeenCalledWith(NODE, listItem);
},
);
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment