@@ -124,9 +124,9 @@ def convert(self, html):
124
124
return self .convert_soup (soup )
125
125
126
126
def convert_soup (self , soup ):
127
- return self .process_tag (soup , convert_as_inline = False , children_only = True )
127
+ return self .process_tag (soup , convert_as_inline = False )
128
128
129
- def process_tag (self , node , convert_as_inline , children_only = False ):
129
+ def process_tag (self , node , convert_as_inline ):
130
130
text = ''
131
131
132
132
# markdown headings or cells can't include
@@ -135,7 +135,7 @@ def process_tag(self, node, convert_as_inline, children_only=False):
135
135
isCell = node .name in ['td' , 'th' ]
136
136
convert_children_as_inline = convert_as_inline
137
137
138
- if not children_only and ( isHeading or isCell ) :
138
+ if isHeading or isCell :
139
139
convert_children_as_inline = True
140
140
141
141
# Remove whitespace-only textnodes just before, after or
@@ -171,14 +171,18 @@ def process_tag(self, node, convert_as_inline, children_only=False):
171
171
newlines = '\n ' * max (newlines_left , newlines_right )
172
172
text = text_strip + newlines + next_text_strip
173
173
174
- if not children_only :
175
- fn_name = ' convert_%s' % node . name . translate ( '' . maketrans ( ':-' , '__' ) )
176
- convert_fn = getattr (self , fn_name , None )
177
- if convert_fn and self .should_convert_tag (node .name ):
178
- text = convert_fn (node , text , convert_as_inline )
174
+ # apply this tag's final conversion function
175
+ convert_fn_name = " convert_%s" % re . sub ( r"[\[\]:-]" , "_" , node . name )
176
+ convert_fn = getattr (self , convert_fn_name , None )
177
+ if convert_fn and self .should_convert_tag (node .name ):
178
+ text = convert_fn (node , text , convert_as_inline )
179
179
180
180
return text
181
181
182
+ def convert__document_ (self , el , text , convert_as_inline ):
183
+ # for BeautifulSoup objects (where node.name == "[document]"), return content results as-is
184
+ return text
185
+
182
186
def process_text (self , el ):
183
187
text = six .text_type (el ) or ''
184
188
0 commit comments