Implement block quotes
This commit is contained in:
parent
0eeb0cc0aa
commit
5fd15585fd
@ -89,7 +89,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
if token.level == 3:
|
||||
# Section
|
||||
heading_last, self.heading_last = self.heading_last, False
|
||||
return format(r'{\par\bfseries\makebox[<lmarg>][l]{<label>}<content>\phantomsection\addcontentsline{toc}{subsubsection}{\protect\numberline{<label>} <content>}\nopagebreak\par}',
|
||||
return format(r'{\par\leftskip=\quotemargin\bfseries\makebox[<lmarg>][l]{<label>}<content>\phantomsection\addcontentsline{toc}{subsubsection}{\protect\numberline{<label>} <content>}\nopagebreak\par}',
|
||||
label=token.label,
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
@ -97,7 +97,12 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
def render_paragraph(self, token):
|
||||
self.heading_last = False
|
||||
|
||||
return format(r'\N{\par\leftskip=<lmarg>\updatealign <content>\par}\N',
|
||||
return format(r'\N{\par\leftskip=\dimexpr\quotemargin+<lmarg>\relax\updatealign <content>\par}\N',
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
||||
def render_quote(self, token):
|
||||
return format(r'{\quotemargin=<lmarg>\renewcommand{\addcontentsline}[3]{}<content>}',
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
||||
@ -117,7 +122,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
|
||||
def render_subrules_item(self, token):
|
||||
if token.label:
|
||||
return format(r'\N{\par\leftskip=\dimexpr<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\updatealign\parskip=<parskip>\makebox[<lmarg>][l]{<label>}<content>\par}\N',
|
||||
parskip=r'\parskip',# if token.level <= 1 else '0cm',
|
||||
label=token.label,
|
||||
level=token.level,
|
||||
@ -176,7 +181,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
inner = self.render_inner(token)
|
||||
|
||||
if colnum == 0:
|
||||
return format(r'\makebox[1.8em][l]{<rownum>.}<content>',
|
||||
return format(r'\makebox[2.2em][l]{<rownum>.}<content>',
|
||||
rownum=inner.split(' ')[0],
|
||||
content=' '.join(inner.split(' ')[1:])
|
||||
)
|
||||
@ -198,6 +203,7 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
|
||||
\setlength{\emergencystretch}{3em}
|
||||
\usepackage{microtype}
|
||||
\usepackage{longtable}\usepackage{tabu}\usepackage{booktabs}
|
||||
\newlength\quotemargin
|
||||
\newlength\notetaglength
|
||||
\newlength\lastalign\newcommand{\updatealign}{\global\lastalign=\dimexpr\leftskip+\hangindent\relax}
|
||||
% TOC format
|
||||
|
@ -151,3 +151,7 @@ class Definition(mistletoe.block_token.BlockToken):
|
||||
return next(lines).rstrip('\n')
|
||||
|
||||
mistletoe.block_token.add_token(Definition)
|
||||
|
||||
def convert_leading_tabs(string):
|
||||
return string
|
||||
mistletoe.block_token.Quote.convert_leading_tabs = convert_leading_tabs
|
||||
|
@ -44,6 +44,7 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
|
||||
self.render_map['Note'] = self.render_note
|
||||
self.render_map['Definition'] = self.render_definition
|
||||
|
||||
self.quotemargin = 0
|
||||
self.lastalign = 0
|
||||
self.heading_last = False
|
||||
|
||||
@ -95,7 +96,7 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
|
||||
# Section
|
||||
heading_last, self.heading_last = self.heading_last, False
|
||||
return format(r'{\keepn\b\li<hangindent> <content>\par}',
|
||||
hangindent=cm_to_twip(LMARG),
|
||||
hangindent=cm_to_twip(LMARG)+self.quotemargin,
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
||||
@ -121,29 +122,31 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
|
||||
if token.level == 3:
|
||||
# Section
|
||||
heading_last, self.heading_last = self.heading_last, False
|
||||
return format(r'{\keepn\b\fi-<hangindent>\li<hangindent> <label>\tab <content>\par}',
|
||||
return format(r'{\keepn\b\fi-<hangindent>\li<leftmargin> <label>\tab <content>\par}',
|
||||
hangindent=cm_to_twip(LMARG),
|
||||
leftmargin=cm_to_twip(LMARG)+self.quotemargin,
|
||||
label=token.label,
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
||||
def render_quote(self, token):
|
||||
raise Exception('NYI')
|
||||
self.quotemargin = cm_to_twip(LMARG)
|
||||
inner = self.render_inner(token)
|
||||
self.quotemargin = 0
|
||||
return inner
|
||||
|
||||
def render_paragraph(self, token):
|
||||
self.lastalign = LMARG
|
||||
self.heading_last = False
|
||||
|
||||
return format(r'{\li<lmarg> <content>\par}',
|
||||
return format(r'{\li<leftmargin> <content>\par}',
|
||||
leftmargin=cm_to_twip(LMARG)+self.quotemargin,
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
||||
def render_block_code(self, token):
|
||||
raise Exception('NYI')
|
||||
|
||||
def render_block_code(self, token):
|
||||
raise Exception('NYI')
|
||||
|
||||
def render_list(self, token):
|
||||
raise Exception('NYI')
|
||||
|
||||
@ -219,14 +222,14 @@ class RTFRenderer(mistletoe.base_renderer.BaseRenderer):
|
||||
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),
|
||||
li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin,
|
||||
label=token.label,
|
||||
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),
|
||||
li=cm_to_twip(LMARG + token.level + 1)+self.quotemargin,
|
||||
label=token.label,
|
||||
content=self.render_inner(token)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user