Skip to content

Commit 4b9c541

Browse files
committed
Move sphinxEncode to nodes.sphinx_encode
1 parent dc9a0b4 commit 4b9c541

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

jupyterbook_latex/nodes.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
"""AST nodes to designate notebook components."""
22
from docutils import nodes
33

4-
from .utils import sphinxEncode
54

5+
def sphinx_encode(string: str) -> str:
6+
"""Replace tilde, hyphen and single quotes with their LaTeX commands."""
7+
return (
8+
string.replace("~", "\\textasciitilde{}")
9+
.replace("-", "\\sphinxhyphen{}")
10+
.replace("'", "\\textquotesingle{}")
11+
)
612

7-
def getIndex(body, text):
13+
14+
def get_index(body, text):
815
index = 0
916
indices = [i for i, x in enumerate(body) if x == text]
1017
for i in indices:
@@ -35,7 +42,7 @@ def __init__(self, rawsource="", *children, **attributes):
3542

3643
def visit_H2Node(self, node):
3744
self.h2Text = node.astext()
38-
self.h2Text = sphinxEncode(self.h2Text)
45+
self.h2Text = sphinx_encode(self.h2Text)
3946

4047
strong = nodes.strong("")
4148
strong.children = node.children
@@ -51,7 +58,7 @@ def visit_H2Node(self, node):
5158

5259

5360
def depart_H2Node(self, node):
54-
index = getIndex(self.body, self.h2Text)
61+
index = get_index(self.body, self.h2Text)
5562
if index:
5663
self.body[index] = "\\Large " + self.h2Text
5764
# else throw an error
@@ -62,7 +69,7 @@ def visit_H3Node(self, node):
6269

6370

6471
def depart_H3Node(self, node):
65-
index = getIndex(self.body, self.h2Text)
72+
index = get_index(self.body, self.h2Text)
6673
if index:
6774
self.body[index] = "\\large " + self.h2Text
6875
# else throw an error

jupyterbook_latex/utils.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)