Skip to content

code simplification to remove the children_only parameter #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def convert(self, html):
return self.convert_soup(soup)

def convert_soup(self, soup):
return self.process_tag(soup, convert_as_inline=False, children_only=True)
return self.process_tag(soup, convert_as_inline=False)

def process_tag(self, node, convert_as_inline, children_only=False):
def process_tag(self, node, convert_as_inline):
text = ''

# markdown headings or cells can't include
Expand All @@ -135,7 +135,7 @@ def process_tag(self, node, convert_as_inline, children_only=False):
isCell = node.name in ['td', 'th']
convert_children_as_inline = convert_as_inline

if not children_only and (isHeading or isCell):
if isHeading or isCell:
convert_children_as_inline = True

# Remove whitespace-only textnodes just before, after or
Expand Down Expand Up @@ -171,14 +171,18 @@ def process_tag(self, node, convert_as_inline, children_only=False):
newlines = '\n' * max(newlines_left, newlines_right)
text = text_strip + newlines + next_text_strip

if not children_only:
fn_name = 'convert_%s' % node.name.translate(''.maketrans(':-', '__'))
convert_fn = getattr(self, fn_name, None)
if convert_fn and self.should_convert_tag(node.name):
text = convert_fn(node, text, convert_as_inline)
# apply this tag's final conversion function
convert_fn_name = "convert_%s" % re.sub(r"[\[\]:-]", "_", node.name)
convert_fn = getattr(self, convert_fn_name, None)
if convert_fn and self.should_convert_tag(node.name):
text = convert_fn(node, text, convert_as_inline)

return text

def convert__document_(self, el, text, convert_as_inline):
# for BeautifulSoup objects (where node.name == "[document]"), return content results as-is
return text

def process_text(self, el):
text = six.text_type(el) or ''

Expand Down
Loading