Skip to content
Open
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
5 changes: 2 additions & 3 deletions html2markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def _markdownify(tag, _listType=None, _blockQuote=False, _listIndex=1):
tag.string = '\n---\n'
tag.unwrap()
elif tag.name == 'pre':
tag.insert_before('\n\n')
tag.insert_after('\n\n')
tag.insert_before('\n\n```\n')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause any <pre> element to be surrounded with a code fence, not just <pre><code>.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For safety and clarity that's not bad, but makes it harder to convert back to html.

Maybe for <pre> we only indent as you already did, but for <code> we backtick explicitly? Then the process to reverse back to html has a method it can follow.

tag.insert_after('\n```\n\n')
if tag.code:
if not _supportedAttrs(tag.code):
return
Expand All @@ -233,7 +233,6 @@ def _markdownify(tag, _listType=None, _blockQuote=False, _listIndex=1):
lines.pop()
for i,line in enumerate(lines):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop doesn't do anything. I can't remember if lines[i] = line.replace(...) is still necessary, but it's currently not being assigned to lines[i].

line = line.replace(u'\xa0', ' ')
lines[i] = ' %s' % line
tag.replace_with(BeautifulSoup('\n'.join(lines), 'html.parser'))
return
elif tag.name == 'code':
Expand Down