Some more clever bavlna stuff.
This commit is contained in:
parent
c85fc8ce55
commit
46dff9c42c
2 changed files with 21 additions and 4 deletions
2
test.md
2
test.md
|
@ -35,6 +35,8 @@ A non-breakable space bro
|
||||||
|
|
||||||
A lot of spaces
|
A lot of spaces
|
||||||
|
|
||||||
|
A text with some $math$.
|
||||||
|
|
||||||
This should be seen by all.
|
This should be seen by all.
|
||||||
|
|
||||||
[!opendatatask]{}
|
[!opendatatask]{}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from panflute import Space,SoftBreak,Str
|
from panflute import Space, SoftBreak, Str, Math
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
# Import local files
|
# Import local files
|
||||||
|
@ -12,11 +12,26 @@ class NBSP(Space):
|
||||||
def bavlna(e: Whitespace, c: Context) -> bool:
|
def bavlna(e: Whitespace, c: Context) -> bool:
|
||||||
"""Determine if given piece of whitespace should be non-breakable."""
|
"""Determine if given piece of whitespace should be non-breakable."""
|
||||||
|
|
||||||
|
|
||||||
if c.get_metadata("language") == "cs":
|
if c.get_metadata("language") == "cs":
|
||||||
|
if isinstance(e.prev, Str) and isinstance(e.next, Str):
|
||||||
# TODO: Add more clever stuff
|
if e.prev.text.lower() in ['k', 's', 'v', 'z', 'o', 'u', 'a', 'i']:
|
||||||
if isinstance(e.prev, Str) and isinstance(e.next, Str) and 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
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue