mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-04 01:25:38 -05:00
WYSIWYG fix list nesting (#13251)
* Improvements to nested lists * OL tests and PR feedback
This commit is contained in:
@@ -105,6 +105,32 @@ export class HTMLMarkdownConverter {
|
||||
return `[${node.innerText}](${node.href})`;
|
||||
}
|
||||
});
|
||||
this.turndownService.addRule('listItem', {
|
||||
filter: 'li',
|
||||
replacement: function (content, node, options) {
|
||||
content = content
|
||||
.replace(/^\n+/, '') // remove leading newlines
|
||||
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
|
||||
.replace(/\n/gm, '\n '); // indent
|
||||
let prefix = options.bulletListMarker + ' ';
|
||||
let parent = node.parentNode;
|
||||
let nestedCount = 0;
|
||||
if (parent.nodeName === 'OL') {
|
||||
let start = parent.getAttribute('start');
|
||||
let index = Array.prototype.indexOf.call(parent.children, node);
|
||||
prefix = (start ? Number(start) + index : index + 1) + '. ';
|
||||
} else if (parent.nodeName === 'UL') {
|
||||
while (parent?.nodeName === 'UL') {
|
||||
nestedCount++;
|
||||
parent = parent?.parentNode;
|
||||
}
|
||||
prefix = (' '.repeat(nestedCount - 1)) + options.bulletListMarker + ' ';
|
||||
}
|
||||
return (
|
||||
prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user