Last active
November 6, 2018 05:35
-
-
Save K4zuki/0ab8a76f8130b93c6288cae725e3d3ea to your computer and use it in GitHub Desktop.
change attributes of code block inside `pandoc-crossref` listing div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
python3.5 works as-is | |
json lib does not work as expected with python2.7 | |
seems utf-8 string related | |
pandoc -t docx -o <docx filename> <input filename> | |
--filter=pandoc-crossref --filter=./listing_test.py | |
""" | |
import os | |
import panflute as pf | |
class BlockQuoteDiv(object): | |
def action(self, elem, doc): | |
if (doc.format == "docx"): | |
if isinstance(elem, pf.Div) and elem.identifier.startswith("lst:"): | |
cb = elem.content.pop(-1) | |
pf.debug(cb) | |
div = pf.Div(cb, attributes=cb.attributes) | |
elem.content.append(div) | |
return elem | |
def main(doc=None): | |
bqd = BlockQuoteDiv() | |
return pf.run_filter(bqd.action, doc=doc) | |
if __name__ == "__main__": | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"blocks": [ | |
{ | |
"t": "Div", | |
"c": [ | |
[ | |
"lst:block-listingtable", | |
[ | |
"listing", | |
"plain", | |
"numberLines" | |
], | |
[] | |
], | |
[ | |
{ | |
"t": "Para", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "—" | |
}, | |
{ | |
"t": "Strong", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "List" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "1:" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "setup.cfg" | |
} | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": "—" | |
} | |
] | |
}, | |
{ | |
"t": "CodeBlock", | |
"c": [ | |
[ | |
"", | |
[ | |
"plain", | |
"numberLines" | |
], | |
[ | |
[ | |
"numbers", | |
"left" | |
] | |
] | |
], | |
"[metadata]\ndescription-file = README.md\n" | |
] | |
} | |
] | |
] | |
}, | |
{ | |
"t": "Div", | |
"c": [ | |
[ | |
"", | |
[], | |
[ | |
[ | |
"custom-style", | |
"Block Quote" | |
] | |
] | |
], | |
[ | |
{ | |
"t": "Para", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "Block" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "Quote" | |
} | |
] | |
} | |
] | |
] | |
} | |
], | |
"pandoc-api-version": [ | |
1, | |
17, | |
4, | |
2 | |
], | |
"meta": { | |
"subfigureChildTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
} | |
] | |
}, | |
"include": { | |
"t": "MetaList", | |
"c": [ | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "markdown" | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "images" | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "data" | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "Out" | |
} | |
] | |
} | |
] | |
}, | |
"eqnLabels": { | |
"t": "MetaString", | |
"c": "arabic" | |
}, | |
"tableEqns": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"lolTitle": { | |
"t": "MetaBlocks", | |
"c": [ | |
{ | |
"t": "Header", | |
"c": [ | |
1, | |
[ | |
"", | |
[], | |
[] | |
], | |
[ | |
{ | |
"t": "Str", | |
"c": "List" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "of" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "Listings" | |
} | |
] | |
] | |
} | |
] | |
}, | |
"sectionsDepth": { | |
"t": "MetaString", | |
"c": "0" | |
}, | |
"CJKoptions": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "BoldFont=SourceHanSans-Bold," | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "ItalicFont=SourceHanSans-Medium," | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "BoldItalicFont=SourceHanSans-Bold" | |
} | |
] | |
}, | |
"tblPrefix": { | |
"t": "MetaList", | |
"c": [ | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "tbl." | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "tbls." | |
} | |
] | |
} | |
] | |
}, | |
"chapters": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"figureTitle": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "Figure" | |
} | |
] | |
}, | |
"secHeaderTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"secHeaderDelim" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"t" | |
] | |
} | |
] | |
}, | |
"figureTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"figureTitle" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"titleDelim" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"t" | |
] | |
} | |
] | |
}, | |
"ccsDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "," | |
}, | |
{ | |
"t": "Space" | |
} | |
] | |
}, | |
"eqnPrefixTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"p" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": " " | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
} | |
] | |
}, | |
"CJKmainfont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "SourceHanSans-Normal" | |
} | |
] | |
}, | |
"CJKmonofont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "RictyDiminished-Regular" | |
} | |
] | |
}, | |
"secPrefix": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "Chapter" | |
} | |
] | |
}, | |
"linkcolor": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "black" | |
} | |
] | |
}, | |
"lofTitle": { | |
"t": "MetaBlocks", | |
"c": [ | |
{ | |
"t": "Header", | |
"c": [ | |
1, | |
[ | |
"", | |
[], | |
[] | |
], | |
[ | |
{ | |
"t": "Str", | |
"c": "List" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "of" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "Figures" | |
} | |
] | |
] | |
} | |
] | |
}, | |
"linkReferences": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"figPrefix": { | |
"t": "MetaList", | |
"c": [ | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "fig." | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "figs." | |
} | |
] | |
} | |
] | |
}, | |
"nameInLink": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"pairDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "," | |
}, | |
{ | |
"t": "Space" | |
} | |
] | |
}, | |
"lstPrefixTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"p" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": " " | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
} | |
] | |
}, | |
"secHeaderDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Space" | |
} | |
] | |
}, | |
"lastDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "," | |
}, | |
{ | |
"t": "Space" | |
} | |
] | |
}, | |
"papersize": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "b5paper" | |
} | |
] | |
}, | |
"mathfont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "SourceHanSans-Light" | |
} | |
] | |
}, | |
"fontsize": { | |
"t": "MetaString", | |
"c": "11" | |
}, | |
"lgeometry": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "top=20truemm,bottom=20truemm,left=20truemm,right=20truemm" | |
} | |
] | |
}, | |
"urlcolor": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "black" | |
} | |
] | |
}, | |
"tableTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"tableTitle" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"titleDelim" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"t" | |
] | |
} | |
] | |
}, | |
"tableTitle": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "Table" | |
} | |
] | |
}, | |
"rangeDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "-" | |
} | |
] | |
}, | |
"titleDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": ":" | |
} | |
] | |
}, | |
"numberSections": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"subfigureRefIndexTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"suf" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "(" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"s" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": ")" | |
} | |
] | |
}, | |
"chapter": { | |
"t": "MetaBool", | |
"c": true | |
}, | |
"documentclass": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "book" | |
} | |
] | |
}, | |
"codeBlockCaptions": { | |
"t": "MetaBool", | |
"c": true | |
}, | |
"sansfont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "SourceHanSans-Regular" | |
} | |
] | |
}, | |
"subfigGrid": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"chaptersDepth": { | |
"t": "MetaString", | |
"c": "1" | |
}, | |
"mainlang": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "Japanese" | |
} | |
] | |
}, | |
"tblLabels": { | |
"t": "MetaString", | |
"c": "arabic" | |
}, | |
"lotTitle": { | |
"t": "MetaBlocks", | |
"c": [ | |
{ | |
"t": "Header", | |
"c": [ | |
1, | |
[ | |
"", | |
[], | |
[] | |
], | |
[ | |
{ | |
"t": "Str", | |
"c": "List" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "of" | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "Tables" | |
} | |
] | |
] | |
} | |
] | |
}, | |
"refIndexTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"suf" | |
] | |
} | |
] | |
}, | |
"geometry": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "top=30truemm,bottom=30truemm,left=20truemm,right=20truemm" | |
} | |
] | |
}, | |
"cref": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"tblPrefixTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"p" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": " " | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
} | |
] | |
}, | |
"listingTitle": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "List" | |
} | |
] | |
}, | |
"eqnPrefix": { | |
"t": "MetaList", | |
"c": [ | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "eq." | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "eqns." | |
} | |
] | |
} | |
] | |
}, | |
"listingTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "—" | |
}, | |
{ | |
"t": "Strong", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"listingTitle" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"titleDelim" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"t" | |
] | |
} | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": "—" | |
} | |
] | |
}, | |
"secPrefixTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"p" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": " " | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
} | |
] | |
}, | |
"tables": { | |
"t": "MetaBool", | |
"c": true | |
}, | |
"figLabels": { | |
"t": "MetaString", | |
"c": "arabic" | |
}, | |
"mainfont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "SourceHanSans-Regular" | |
} | |
] | |
}, | |
"autoEqnLabels": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"figPrefixTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"p" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": " " | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
} | |
] | |
}, | |
"refDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "," | |
}, | |
{ | |
"t": "Space" | |
} | |
] | |
}, | |
"secLabels": { | |
"t": "MetaString", | |
"c": "arabic" | |
}, | |
"monofont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "RictyDiminished-Regular" | |
} | |
] | |
}, | |
"lstPrefix": { | |
"t": "MetaList", | |
"c": [ | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "lst." | |
} | |
] | |
}, | |
{ | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "lsts." | |
} | |
] | |
} | |
] | |
}, | |
"ccsLabelSep": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Str", | |
"c": "—" | |
}, | |
{ | |
"t": "Space" | |
} | |
] | |
}, | |
"chapDelim": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "." | |
} | |
] | |
}, | |
"autoSectionLabels": { | |
"t": "MetaBool", | |
"c": false | |
}, | |
"ccsTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"ccsLabelSep" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"t" | |
] | |
} | |
] | |
}, | |
"citecolor": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "black" | |
} | |
] | |
}, | |
"CJKsansfont": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Str", | |
"c": "SourceHanSans-Normal" | |
} | |
] | |
}, | |
"subfigureTemplate": { | |
"t": "MetaInlines", | |
"c": [ | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"figureTitle" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"i" | |
] | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"titleDelim" | |
] | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"t" | |
] | |
}, | |
{ | |
"t": "Str", | |
"c": "." | |
}, | |
{ | |
"t": "Space" | |
}, | |
{ | |
"t": "Math", | |
"c": [ | |
{ | |
"t": "DisplayMath" | |
}, | |
"ccs" | |
] | |
} | |
] | |
}, | |
"crossrefYaml": { | |
"t": "MetaString", | |
"c": "pandoc-crossref.yaml" | |
}, | |
"lstLabels": { | |
"t": "MetaString", | |
"c": "arabic" | |
}, | |
"subfigLabels": { | |
"t": "MetaString", | |
"c": "alpha a" | |
}, | |
"listings": { | |
"t": "MetaBool", | |
"c": true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment