| Total Complexity | 9 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python3 |
||
| 2 | |||
| 3 | |||
| 4 | """ |
||
| 5 | Pandoc filter for converting spaces to non-breakable spaces in LaTeX |
||
| 6 | for french ponctuation |
||
| 7 | """ |
||
| 8 | |||
| 9 | from panflute import Space, Str, RawInline, run_filter # type: ignore |
||
| 10 | |||
| 11 | |||
| 12 | def spaces(elem, doc): |
||
| 13 | """ |
||
| 14 | Add LaTeX spaces when needed. |
||
| 15 | """ |
||
| 16 | # Is it in the right format and is it a Space? |
||
| 17 | if doc.format in ["latex", "beamer"] and isinstance(elem, Space): |
||
| 18 | if isinstance(elem.prev, Str) and elem.prev.text in ["«", "“", "‹"]: |
||
| 19 | return RawInline("\\thinspace{}", "tex") |
||
| 20 | if isinstance(elem.next, Str): |
||
| 21 | if elem.next.text == ":": |
||
| 22 | return RawInline("~", "tex") |
||
| 23 | if elem.next.text in [";", "?", "!", "»", "”", "›"]: |
||
| 24 | return RawInline("\\thinspace{}", "tex") |
||
| 25 | return None |
||
| 26 | |||
| 27 | |||
| 28 | def main(doc=None): |
||
| 29 | """ |
||
| 30 | main function. |
||
| 31 | """ |
||
| 32 | return run_filter(spaces, doc=doc) |
||
| 33 | |||
| 34 | |||
| 35 | if __name__ == "__main__": |
||
| 36 | main() |
||
| 37 |