sergiocorreia / panflute

An Pythonic alternative to John MacFarlane's pandocfilters, with extra helper functions
http://scorreia.com/software/panflute/
BSD 3-Clause "New" or "Revised" License
493 stars 60 forks source link

Is there solution to add custom style for lists with panflute ? #227

Open ant0nT opened 1 year ago

ant0nT commented 1 year ago

I search solution to fix the problem described in https://stackoverflow.com/questions/58024749/how-to-format-lists-in-pandoc-generated-docx-documents. I've tried to write solution by myself with panflute, but honestly hasn't gotten any success. Is it possible to write full script or script with pseudocode to replace styles of lists?

upd: According to https://stackoverflow.com/questions/43730436/pandoc-replace-heading-with-custom-style-for-word-docx

've written this code:

from panflute import *

def action( elem, doc ): if isinstance( elem, BulletList ):

return Div( elem, attributes={'custom-style': 'Header{}'.format(elem.level)} )

    return Div( BulletList(*elem.content), attributes={'custom-style': 'List Bullet {}'.format(elem.level)} )

def main(doc=None): return run_filter( action, doc=doc )

if name == "main": main()

but I get error : AttributeError: 'BulletList' object has no attribute 'level'

Is there solution to find out BulletList element level?

lewer commented 1 year ago

What you are trying to do is not very clear. What do you mean by BulletList level? Headers have a level (Header1, Header2,...) but BulletList don't.

ant0nT commented 1 year ago

If I put tab before asterics in markdown like this:

* item1
* item2
\t* item 2.1

pandoc converting it in docx like this

{black circle} item 1
{black circle} item 2
\t {white circle} item 2.1

and for ordered list:

1. item 1
1. item 2
\t1. item 2.1
\t1. item 2.2

converting it to:

1. item1
2. item 2
\t1. item 2.1
\t2. item 2.2

Preview programs display lists in md like pandoc converting it.

But all lists and tables in docx document have "compact" style, what doesn't let me to customise their representations in docx individually

p.s. I've written python script, which replaces lists to paragraphs with custom styles in md, but don't working properly with sorted lists, because it doesn't start a new list numbering from "1" and continue numbering

p.s. Maybe I should to direct this issue to pandoc developers