I like being able to script Pandoc via filters in Python, but one of the major drawbacks of the approach as it currently stands is that Python has no pattern matching to speak of. As a result, code that needs to run queries of the structure of Pandoc documents quickly turns into a nightmare, especially if that code needs to check nested structures. Consider the following partial function in Haskell, which matches against a BlockQuote containing a Para where the first word is "Chapter" in small caps: filter :: Block -> Block filter (BlockQuote [Para (SmallCaps [Str "Chapter"]):_]) = ... Without pattern matching, the equivalent code in Python is painful to write, opaque, and quite brittle. Unfortunately, without support for pattern matching, there is no possibility of a direct analogue in Python. Instead, I propose a fluent interface as a way to provide a query language of sorts for Python. So for example, the same query might look like: m = Matcher(block). BlockQuote(length = 1)[0]. Para(length = -1)[0]. SmallCaps(length = 1)[0]. Str(content = 'Chapter') if m.matches(): ... The code is not quite as dense because I've split it out for legibility, but can be condensed better to fit on a single line if desired. It is at any rate a massive improvement over hand-written queries over the JSON structure of the document. A proof of concept library is available today, and has been demonstrated with the query above as well as other queries I have needed in my own projects. Current coverage of the Pandoc API is at around 50%. The code is made available under an MIT license: https://bitbucket.org/elliottslaughter/pandocpatterns I would greatly appreciate any thoughts or feedback on the concept, design, or implementation. Please feel free to take the code out for a test drive and kick the tires. If there is interest, I would be willing to invest the effort to improve the library and make it more robust and useful. Thank you for your time. -- Elliott Slaughter "Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay -- 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/CAJ9X%3Dkb9W0_Jd4ufPcRiZSSZ%2B5Bpftg4hZ82zCuBLb-moadnSQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.