Skip to content

Commit

Permalink
tex: fix py mistune
Browse files Browse the repository at this point in the history
  • Loading branch information
inkydragon committed May 19, 2024
1 parent e145020 commit 4e61c07
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions latex/convert2latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ def __init__(self, is_book_or_report=True):
self._ltx_esc_dict = {
'~': r'\textasciitilde{}',

'#': '\#',
'$': '\$',
'%': '\%',
'^': '\^{}',
'&': '\&',
'#': r'\#',
'$': r'\$',
'%': r'\%',
'^': r'\^{}',
'&': r'\&',

'-': '{-}',
'_': '\_',
'_': r'\_',

'{': '\{',
'}': '\}',
'{': r'\{',
'}': r'\}',
'[': '{[}',
']': '{]}',

Expand Down Expand Up @@ -78,11 +78,15 @@ def english_list(self, text, ordered, level, start=None):
def text(self, text):
return self.escape_latex(text)

def link(self, link, text=None, title=None):
def link(self, text=None, url=None, title=None):
"""link(self, text: str, url: str, title: Optional[str] = None) -> str:"""
# 不支持 title
return ' \\href{'+link+'}' + '{'+(text or link)+'} '
return ' \\href{'+url+'}' + '{'+(text or url)+'} '

def image(self, src, alt="", title=None):
def image(self, src, url="", title=None):
"""
image(self, text: str, url: str, title: Optional[str] = None) -> str:
"""
_, fname = os.path.split(src)
fname = fname[0:5]

Expand Down Expand Up @@ -172,20 +176,23 @@ def block_quote(self, text):
return text

# 列表
def list(self, text, ordered, level, start=None):
def list(self, text, ordered, **attrs):
"""list(self, text: str, ordered: bool, **attrs: Any) -> str:"""
if ordered:
return '\\begin{enumerate}\n' + text + '\\end{enumerate}\n'
else:
return '\\begin{itemize}\n' + text + '\\end{itemize}\n'

def list_item(self, text, level):
return '\item ' + text + '\n'
def list_item(self, text):
"""list_item(self, text: str) -> str:"""
return r'\item ' + text + '\n'

# LaTeXRenderer end

# hook func
def remove_english(self, tokens, state):
# hook func: Callable[["Markdown", BlockState], Any]
def remove_english(self, state):
# 删除所有英文节点
tokens = state.tokens
# print(tokens) # for debug
for tok in tokens:
if 'block_quote' == tok['type']:
Expand Down

0 comments on commit 4e61c07

Please sign in to comment.