Try to avoid page break after colon

This commit is contained in:
RunasSudo 2019-09-24 02:40:11 +10:00
parent 19a05b469d
commit 2b21860dd0
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 26 additions and 12 deletions

View File

@ -141,8 +141,11 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
def render_paragraph(self, token): def render_paragraph(self, token):
self.heading_last = False self.heading_last = False
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>\relax <content>\par}\N', content = self.render_inner(token)
content=self.render_inner(token)
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>\relax <content><pagebreak>\par}\N',
content=content,
pagebreak=r'\nopagebreak' if content.strip().endswith(':') else ''
) )
def render_quote(self, token): def render_quote(self, token):
@ -166,6 +169,8 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
) )
def render_subrules_item(self, token): def render_subrules_item(self, token):
content = self.render_inner(token)
if token.label: if token.label:
if token.full_label(): if token.full_label():
sha = hashlib.sha256() sha = hashlib.sha256()
@ -176,18 +181,20 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
else: else:
hyperlink = '{}' hyperlink = '{}'
return format(r'\N{\par<hyperlink>\leftskip=\dimexpr\quotemargin+<lmarg>+<level>cm\relax\hangindent=1cm\parskip=<parskip>\makebox[<lmarg>][l]{<label>}<content>\par}\N', return format(r'\N{\par<hyperlink>\leftskip=\dimexpr\quotemargin+<lmarg>+<level>cm\relax\hangindent=1cm\parskip=<parskip>\makebox[<lmarg>][l]{<label>}<content><pagebreak>\par}\N',
hyperlink=hyperlink, hyperlink=hyperlink,
parskip=r'\parskip',# if token.level <= 1 else '0cm', parskip=r'\parskip',# if token.level <= 1 else '0cm',
label=token.label, label=token.label,
level=token.level, level=token.level,
content=self.render_inner(token) content=content,
pagebreak=r'\nopagebreak' if content.strip().endswith(':') else ''
) )
else: else:
return format(r'\N{\par\leftskip=\dimexpr<lmarg>+<level>cm+1cm\relax\parskip=<parskip> <content>\par}\N', return format(r'\N{\par\leftskip=\dimexpr<lmarg>+<level>cm+1cm\relax\parskip=<parskip> <content><pagebreak>\par}\N',
parskip=r'\parskip',# if token.level <= 1 else '0cm', parskip=r'\parskip',# if token.level <= 1 else '0cm',
level=token.level, level=token.level,
content=self.render_inner(token) content=content,
pagebreak=r'\nopagebreak' if content.strip().endswith(':') else ''
) )
def render_note(self, token): def render_note(self, token):

View File

@ -152,9 +152,12 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
def render_paragraph(self, token): def render_paragraph(self, token):
self.heading_last = False self.heading_last = False
return format(r'{\li<leftmargin> <content>\par}', content = self.render_inner(token)
return format(r'{\li<leftmargin><pagebreak> <content>\par}',
leftmargin=cm_to_twip(LMARG)+self.quotemargin, leftmargin=cm_to_twip(LMARG)+self.quotemargin,
content=self.render_inner(token) content=content,
pagebreak=r'\keepn' if content.strip().endswith(':') else ''
) )
def render_block_code(self, token): def render_block_code(self, token):
@ -229,18 +232,22 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
return self.render_inner(token) return self.render_inner(token)
def render_subrules_item(self, token): def render_subrules_item(self, token):
content = self.render_inner(token)
if token.label: if token.label:
return format(r'{\fi<fi>\li<li> <label>\tab <content>\par}', return format(r'{\fi<fi>\li<li><pagebreak> <label>\tab <content>\par}',
fi=cm_to_twip(-1), fi=cm_to_twip(-1),
li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin, li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin,
label=token.label, label=token.label,
content=self.render_inner(token) content=content,
pagebreak=r'\keepn' if content.strip().endswith(':') else ''
) )
else: else:
return format(r'{\li<li> <content>\par}', return format(r'{\li<li><pagebreak> <content>\par}',
li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin, li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin,
label=token.label, label=token.label,
content=self.render_inner(token) content=content,
pagebreak=r'\keepn' if content.strip().endswith(':') else ''
) )
def render_note(self, token): def render_note(self, token):