Do not autodetect note alignment

This commit is contained in:
RunasSudo 2019-09-11 10:34:54 +10:00
parent 5fd15585fd
commit dbc94bc119
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
5 changed files with 15 additions and 20 deletions

Binary file not shown.

View File

@ -1 +1 @@
{\rtf1\deff0{\fonttbl{\f0 TeX Gyre Heros{\*\falt FreeSans}{\*\falt Liberation Sans}{\*\falt Arial};}}\paperw11905\paperh16837\margl1133\margr1133\margt1133\margb1133{\header\f0\fs16\tqr\tx9637 Example Legal Document\tab }{\footer\f0\fs16\tqr\tx9637 \tab\chpgn}\sa198\fs1\~\fs24 {\fs20\li0{\b Note:} This is a note.\par}{\sb566\keepn\b\fs26\qc\caps Part 1\u8212?Preliminary\par}{\keepn\b\fi-566\li566 1\tab Short title\par}{\li566 This is the {\i blah blah}.\par}{\keepn\b\fi-566\li566 2\tab Another heading\par}{\fi-566\li1133 (1)\tab ABC\par}{\li1133 Continued\par}{\fi-566\li1700 (a)\tab asdf\par}{\fi-566\li1700 (b)\tab abcdefg\par}{\li1700 hijkl\par}{\li1133 Continued\par}{\fi-566\li1133 (2)\tab DEF\par}{\keepn\b\fi-566\li566 3\tab Table example\par}{\sa0\trowd\trgaph120\trleft566\clbrdrt\brdrs\clbrdrb\brdrs\cellx5101\clbrdrt\brdrs\clbrdrb\brdrs\cellx9636 {\b Column 1\intbl\cell}{\b Column 2\intbl\cell}\row{\b First column\intbl\cell}{\b Second column\intbl\cell}\row {1. First row\intbl\cell}{Foo bar\intbl\cell}\row {2. Second row\intbl\cell}{Baz qux\intbl\cell}\row }}
{\rtf1\deff0{\fonttbl{\f0 TeX Gyre Heros{\*\falt FreeSans}{\*\falt Liberation Sans}{\*\falt Arial};}}\paperw11905\paperh16837\margl1133\margr1133\margt1133\margb1133{\header\f0\fs16\tqr\tx9637 Example Legal Document\tab }{\footer\f0\fs16\tqr\tx9637 \tab\chpgn}\sa198\fs1\~\fs24 {\fs20\li566{\b Note:} This is a note.\par}{\sb566\keepn\b\fs26\qc\caps Part 1\u8212?Preliminary\par}{\keepn\b\fi-566\li566 1\tab Short title\par}{\li566 This is the {\i blah blah}.\par}{\keepn\b\fi-566\li566 2\tab Another heading\par}{\fi-566\li1133 (1)\tab ABC\par}{\li1133 Continued\par}{\fi-566\li1700 (a)\tab asdf\par}{\fi-566\li1700 (b)\tab abcdefg\par}{\li1700 hijkl\par}{\li1133 Continued\par}{\fi-566\li1133 (2)\tab DEF\par}{\keepn\b\fi-566\li566 3\tab Table example\par}{\sa0\trowd\trgaph120\trleft566\clbrdrt\brdrs\clbrdrb\brdrs\cellx5101\clbrdrt\brdrs\clbrdrb\brdrs\cellx9636 {\b Column 1\intbl\cell}{\b Column 2\intbl\cell}\row{\b First column\intbl\cell}{\b Second column\intbl\cell}\row {1. First row\intbl\cell}{Foo bar\intbl\cell}\row {2. Second row\intbl\cell}{Baz qux\intbl\cell}\row }}

View File

@ -97,7 +97,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
def render_paragraph(self, token):
self.heading_last = False
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>\relax\updatealign <content>\par}\N',
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>\relax <content>\par}\N',
content=self.render_inner(token)
)
@ -109,7 +109,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
def render_definition(self, token):
self.heading_last = False
return format(r'\N{\par\leftskip=\dimexpr<lmarg>+1cm\relax\hangindent=1cm\updatealign <content>\par}\N',
return format(r'\N{\par\leftskip=\dimexpr<lmarg>+1cm\relax\hangindent=1cm <content>\par}\N',
content=self.render_inner(token)
)
@ -122,14 +122,14 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
def render_subrules_item(self, token):
if token.label:
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>+<level>cm\relax\hangindent=1cm\updatealign\parskip=<parskip>\makebox[<lmarg>][l]{<label>}<content>\par}\N',
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>+<level>cm\relax\hangindent=1cm\parskip=<parskip>\makebox[<lmarg>][l]{<label>}<content>\par}\N',
parskip=r'\parskip',# if token.level <= 1 else '0cm',
label=token.label,
level=token.level,
content=self.render_inner(token)
)
else:
return format(r'\N{\par\leftskip=\dimexpr<lmarg>+<level>cm+1cm\relax\updatealign\parskip=<parskip> <content>\par}\N',
return format(r'\N{\par\leftskip=\dimexpr<lmarg>+<level>cm+1cm\relax\parskip=<parskip> <content>\par}\N',
parskip=r'\parskip',# if token.level <= 1 else '0cm',
level=token.level,
content=self.render_inner(token)
@ -138,7 +138,8 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
def render_note(self, token):
self.heading_last = False
return format(r'\N{\nopagebreak\par\footnotesize\selectfont\settowidth{\notetaglength}{\bfseries <label>:}\addtolength{\notetaglength}{1em}\leftskip=\lastalign\hangindent=\notetaglength\makebox[\notetaglength][l]{\bfseries <label>:}<content>\par}\N',
return format(r'\N{\nopagebreak\par\footnotesize\selectfont\settowidth{\notetaglength}{\bfseries <label>:}\addtolength{\notetaglength}{1em}\leftskip=\dimexpr1cm+<level>cm\relax\hangindent=\notetaglength\makebox[\notetaglength][l]{\bfseries <label>:}<content>\par}\N',
level=token.level,
label=token.label,
content=self.render_inner(token)
)
@ -205,7 +206,6 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
\usepackage{longtable}\usepackage{tabu}\usepackage{booktabs}
\newlength\quotemargin
\newlength\notetaglength
\newlength\lastalign\newcommand{\updatealign}{\global\lastalign=\dimexpr\leftskip+\hangindent\relax}
% TOC format
\usepackage{titletoc}
\makeatletter

View File

@ -45,7 +45,6 @@ class NumberedHeading(mistletoe.block_token.BlockToken):
return level, label, content
#mistletoe.block_token.remove_token(mistletoe.block_token.Heading)
mistletoe.block_token.add_token(NumberedHeading)
class Subrules(mistletoe.block_token.BlockToken):
@ -73,6 +72,8 @@ class Subrules(mistletoe.block_token.BlockToken):
lines.reset()
if Note.pattern.match(line):
break
if not SubrulesItem.start(line):
break
@ -115,11 +116,10 @@ class SubrulesItem(mistletoe.block_token.BlockToken):
return level, label, children
class Note(mistletoe.block_token.BlockToken):
pattern = re.compile(r'([0-9A-Z ]+):\s+(.+)')
pattern = re.compile(r'(\t*)([0-9A-Z ]+):\s+(.+)')
def __init__(self, match):
self.label, content = match
self.children = mistletoe.span_token.tokenize_inner(content)
self.level, self.label, self.children = match
@classmethod
def start(cls, line):
@ -130,9 +130,9 @@ class Note(mistletoe.block_token.BlockToken):
line = next(lines)
match = cls.pattern.match(line)
label, content = match.group(1, 2)
level_str, label, content = match.group(1, 2, 3)
label = label[0].upper() + label[1:].lower()
return label, content
return len(level_str), label, mistletoe.span_token.tokenize_inner(content)
mistletoe.block_token.add_token(Note)

View File

@ -45,7 +45,6 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
self.render_map['Definition'] = self.render_definition
self.quotemargin = 0
self.lastalign = 0
self.heading_last = False
def render_strong(self, token):
@ -136,7 +135,6 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
return inner
def render_paragraph(self, token):
self.lastalign = LMARG
self.heading_last = False
return format(r'{\li<leftmargin> <content>\par}',
@ -219,7 +217,6 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
def render_subrules_item(self, token):
if token.label:
self.lastalign = LMARG + token.level + 1
return format(r'{\fi<fi>\li<li> <label>\tab <content>\par}',
fi=cm_to_twip(-1),
li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin,
@ -227,7 +224,6 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
content=self.render_inner(token)
)
else:
self.lastalign = LMARG + token.level + 1
return format(r'{\li<li> <content>\par}',
li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin,
label=token.label,
@ -237,14 +233,13 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
def render_note(self, token):
self.heading_last = False
return format(r'{\fs20\li<lastalign>{\b <label>:} <content>\par}',
lastalign=cm_to_twip(self.lastalign),
return format(r'{\fs20\li<leftindent>{\b <label>:} <content>\par}',
leftindent=cm_to_twip(LMARG + token.level),
label=token.label,
content=self.render_inner(token)
)
def render_definition(self, token):
self.lastalign = LMARG + 2
self.heading_last = False
return format(r'{\fi<fi>\li<li> <content>\par}',