node-html-to-text icon indicating copy to clipboard operation
node-html-to-text copied to clipboard

I can't use unorderedListItemPrefix for orderedList

Open willyou opened this issue 1 year ago • 2 comments

Hello there, I want to remove the ordered list prefix item: Turn this

1. abc
2. abcd
3. abcde

into

abc
abcd
abcde

I tried to use

  1. the formatter to achieve what I wanted but had no luck.
  2. selectors: [ { selector: 'ol', options: { itemPrefix: ' ' } } ]

selector ul will work, but ol won't work. This worked for me.

selectors: [ { selector: 'ol', options: { itemPrefix: '  ' } } ]

So I am wondering is it supported already? Or, is there any workaround I can follow to achieve my goal?

willyou avatar Oct 21 '23 07:10 willyou

As per Readme, itemPrefix is only taken into account by unorderedList default formatter.

orderedList formatter has no own options and only looks into index type attribute of HTML element. I'll consider adding some options to orderedList formatter in the future.

To get what you want, you can assign a different formatter to ol selector.

  • adding format: 'unorderedList' to ol selector should work and allow the use of itemPrefix (not intended use but simple enough);
  • or you can define a custom formatter, albeit in this case it would require copying a significant chunk of code responsible for list formatting that is not exposed.

KillyMXI avatar Oct 21 '23 12:10 KillyMXI

Thank you for the quick reply; it worked! Thank you!

willyou avatar Oct 23 '23 02:10 willyou