File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,10 @@ code_language
102
102
should be annotated with `````python `` or similar.
103
103
Defaults to ``'' `` (empty string) and can be any string.
104
104
105
+ escape_underscores
106
+ If set to ``False ``, do not escape ``_ `` to ``\_ `` in text.
107
+ Defaults to ``True ``.
108
+
105
109
Options may be specified as kwargs to the ``markdownify `` function, or as a
106
110
nested ``Options `` class in ``MarkdownConverter `` subclasses.
107
111
Original file line number Diff line number Diff line change 25
25
UNDERSCORE = '_'
26
26
27
27
28
- def escape (text ):
28
+ def escape (text , escape_underscores ):
29
29
if not text :
30
30
return ''
31
- return text .replace ('_' , r'\_' )
31
+ if escape_underscores :
32
+ return text .replace ('_' , r'\_' )
33
+ return text
32
34
33
35
34
36
def chomp (text ):
@@ -68,15 +70,16 @@ class MarkdownConverter(object):
68
70
class DefaultOptions :
69
71
autolinks = True
70
72
bullets = '*+-' # An iterable of bullet types.
73
+ code_language = ''
71
74
convert = None
72
75
default_title = False
76
+ escape_underscores = True
73
77
heading_style = UNDERLINED
74
78
newline_style = SPACES
75
79
strip = None
76
80
strong_em_symbol = ASTERISK
77
81
sub_symbol = ''
78
82
sup_symbol = ''
79
- code_language = ''
80
83
81
84
class Options (DefaultOptions ):
82
85
pass
@@ -155,7 +158,7 @@ def process_text(self, el):
155
158
text = whitespace_re .sub (' ' , text )
156
159
157
160
if el .parent .name != 'code' :
158
- text = escape (text )
161
+ text = escape (text , self . options [ 'escape_underscores' ] )
159
162
160
163
# remove trailing whitespaces if any of the following condition is true:
161
164
# - current text node is the last node in li
Original file line number Diff line number Diff line change 3
3
4
4
def test_underscore ():
5
5
assert md ('_hey_dude_' ) == r'\_hey\_dude\_'
6
+ assert md ('_hey_dude_' , escape_underscores = False ) == r'_hey_dude_'
6
7
7
8
8
9
def test_xml_entities ():
You can’t perform that action at this time.
0 commit comments