Skip to content
Closed
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
19 changes: 17 additions & 2 deletions markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def process_tag(self, node, children_only=False):
# Convert the children first
for el in node.children:
if isinstance(el, NavigableString):
text += self.process_text(six.text_type(el))
# Blank chars shall be striped except in <pre>
text += self.process_text(six.text_type(el), keep_whitespaces=(node.name == 'pre'))
else:
text += self.process_tag(el)

Expand All @@ -73,7 +74,9 @@ def process_tag(self, node, children_only=False):

return text

def process_text(self, text):
def process_text(self, text, keep_whitespaces=False):
if keep_whitespaces:
return escape(text or '')
return escape(whitespace_re.sub(' ', text or ''))

def __getattr__(self, attr):
Expand Down Expand Up @@ -127,6 +130,12 @@ def convert_blockquote(self, el, text):
def convert_br(self, el, text):
return ' \n'

def convert_code(self, el, text):
return '`%s`' % text if text else ''

def convert_del(self, el, text):
return '~~%s~~' % text if text else ''

def convert_em(self, el, text):
return '*%s*' % text if text else ''

Expand Down Expand Up @@ -175,6 +184,12 @@ def convert_li(self, el, text):
def convert_p(self, el, text):
return '%s\n\n' % text if text else ''

def convert_pre(self, el, text):
return '```%s\n```\n' % text if text else ''

def convert_s(self, el, text):
return self.convert_del(el, text)

def convert_strong(self, el, text):
return '**%s**' % text if text else ''

Expand Down