from panflute import Space, SoftBreak, Str, Math from typing import Union # Import local files from context import Context Whitespace = Union[Space,SoftBreak] class NBSP(Space): pass def bavlna(e: Whitespace, c: Context) -> bool: """Determine if given piece of whitespace should be non-breakable.""" if c.get_metadata("language") == "cs": if isinstance(e.prev, Str) and isinstance(e.next, Str): if e.prev.text.lower() in ['k', 's', 'v', 'z', 'o', 'u', 'a', 'i']: return True if isinstance(e.prev, Str) and isinstance(e.next, Str): prevC = e.prev.text[-1] nextC = e.next.text[0] numbers = ["0123456789"] operators = ["+-/*^%:"] if prevC in numbers and nextC in numbers: return True if prevC in numbers and nextC in operators: return True if prevC in operators and nextC in numbers: return True if isinstance(e.prev, Math) or isinstance(e.next, Math): return True return False