-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Option for list item indentation #484
Comments
Hi @zirkelc, actually this was requested a few times. As this neither adds unjustified complexity, nor introduces use case specific behaviour, I think we can add it. Actually we have implemented it on our project too - as a side effect of different handling of ordered lists that have more than single-digit items. The constant function listIndent(content, indentLength) {
const indent = strings.repeat(' ', indentLength);
return content
.replace(/^\n+/, '') // remove leading newlines
.replace(/\n+$/, '\n') // replace trailing newlines with just a single one
.replace(/\n/gm, `\n${indent}`); // indent
}
rules.set('listItem', {
filter: 'li',
replacement(content, node, options) {
const parent = node.parentNode;
let marker = options.bulletListMarker;
if (parent.nodeName === 'OL') {
const start = parent.getAttribute('start');
const index = Array.prototype.indexOf.call(parent.children, node);
marker = `${start ? Number(start) + index : index + 1}.`;
}
const space = repeat(' ', 1 + Math.max(0, 3 - marker.length));
const prefix = `${marker}${space}`;
const liContent = listIndent(content, prefix.length);
const trailNl = node.nextSibling && !/\n$/.test(liContent) ? '\n' : '';
return `${prefix}${liContent}${trailNl}`;
},
}); For ordered lists, it works like this: <it should="respect multi-digit ordered list items">
<turndown>
<ol start="9">
<li>a</li>
<li>b</li>
</ol>
</turndown>
<produces>
9. a
10. b
</produces>
</it> You can try if it does the job for you (e.g. using this as a custom rule) and I'd then implement it. |
Hi @martincizek that looks good! I think both |
@martincizek do you consider adding this feature? If you're busy, I can draft a PR for this. |
The current implementation uses 3 spaces for
<li>
indentation. In order to change it, we have to add a custom rule.Would it be possible to add an option to configure this setting, for example as
bulletListIndentation
?turndown/src/commonmark-rules.js
Lines 61 to 72 in cc73387
If accepted I'd be willing to submit a PR
The text was updated successfully, but these errors were encountered: