1
1
"""AST nodes to designate notebook components."""
2
2
from docutils import nodes
3
3
4
- from .utils import sphinxEncode
5
4
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
+ )
6
12
7
- def getIndex (body , text ):
13
+
14
+ def get_index (body , text ):
8
15
index = 0
9
16
indices = [i for i , x in enumerate (body ) if x == text ]
10
17
for i in indices :
@@ -35,7 +42,7 @@ def __init__(self, rawsource="", *children, **attributes):
35
42
36
43
def visit_H2Node (self , node ):
37
44
self .h2Text = node .astext ()
38
- self .h2Text = sphinxEncode (self .h2Text )
45
+ self .h2Text = sphinx_encode (self .h2Text )
39
46
40
47
strong = nodes .strong ("" )
41
48
strong .children = node .children
@@ -51,7 +58,7 @@ def visit_H2Node(self, node):
51
58
52
59
53
60
def depart_H2Node (self , node ):
54
- index = getIndex (self .body , self .h2Text )
61
+ index = get_index (self .body , self .h2Text )
55
62
if index :
56
63
self .body [index ] = "\\ Large " + self .h2Text
57
64
# else throw an error
@@ -62,7 +69,7 @@ def visit_H3Node(self, node):
62
69
63
70
64
71
def depart_H3Node (self , node ):
65
- index = getIndex (self .body , self .h2Text )
72
+ index = get_index (self .body , self .h2Text )
66
73
if index :
67
74
self .body [index ] = "\\ large " + self .h2Text
68
75
# else throw an error
0 commit comments