public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Scripting help, or how to set bullet list style for .docx formatting
@ 2017-06-13 20:42 Daniel Shunfenthal
  0 siblings, 0 replies; only message in thread
From: Daniel Shunfenthal @ 2017-06-13 20:42 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2488 bytes --]

I'm having trouble with writing a pandoc python filter.

When I convert from markdown to docx I'm using a custom reference to set 
styles. 
I can change most of the styles I want, except the bullet style, it isn't 
supported in the reference file. Default bullets only seem to only use "•" 
and "-" and repeats. I wanted to add a couple more bullets since my 
markdown file has a few levels.

If I read the docs correctly, the best way to do that would be to create a 
custom style and a filter to convert it. (but let me know if there is an 
easier way)
I made the custom style in the reference doc called "List Bullet" and if I 
surround my lists with a Div with the class name, it works for the first 
level at least.

I'm trying to make a python filter, but I am only just learning programming 
and I only know a very little python. I think this shouldn't be too hard to 
do, but I'm stuck. I've looked at a couple of the python examples, but I 
don't quite understand some things.

This is what I have so far. It works only on the first bullet of each list, 
and I sort of understand why but I do not know how to have it apply to the 
whole list and sub-lists. I also think I need to call each successive 
increment "List Bullet 2", "3" and so on.

FYI, got most of the code from the python filter examples on their github.
from pandocfilters import toJSONFilter, BulletList, Div, stringify, 
attributes

def deflists(key, value, format, meta):
    
    if key == 'BulletList':
        # Pretty sure this needs to loop through each value, but not sure 
how.
        return Div(["", [], [['custom-style', 'List Bullet']]], value[0])
        
# Is this on the right track? I think I need to recurse through the list?
def toDiv(bullets):
    return Div(["", [], [['custom-style', 'List Bullet']]], bullets)

if __name__ == "__main__":
    toJSONFilter(deflists)

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/b1327704-3fd9-48da-b709-04e9e7267312%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 8912 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-13 20:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-13 20:42 Scripting help, or how to set bullet list style for .docx formatting Daniel Shunfenthal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).