From 3133e931af8b747db0a2b385446b1f8eb8550a6d Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Mon, 5 Nov 2012 21:36:59 +1300 Subject: [PATCH] Bold and italics within code blocks aren't recognized Pass them through as raw HTML instead. --- html2text.py | 17 +++++++++++++++-- test/code_blocks.html | 9 +++++++++ test/code_blocks.md | 6 ++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/code_blocks.html create mode 100644 test/code_blocks.md diff --git a/html2text.py b/html2text.py index b13615b5..e9bf9010 100755 --- a/html2text.py +++ b/html2text.py @@ -440,8 +440,21 @@ def handle_tag(self, tag, attrs, start): self.blockquote -= 1 self.p() - if tag in ['em', 'i', 'u'] and not self.ignore_emphasis: self.o(self.emphasis_mark) - if tag in ['strong', 'b'] and not self.ignore_emphasis: self.o(self.strong_mark) + if tag in ['em', 'i', 'u'] and not self.ignore_emphasis: + if not self.pre: + self.o(self.emphasis_mark) + elif start: + self.o("<"+tag+">") + else: + self.o("") + if tag in ['strong', 'b'] and not self.ignore_emphasis: + if not self.pre: + self.o(self.strong_mark) + elif start: + self.o("<"+tag+">") + else: + self.o("") + if tag in ['del', 'strike', 's']: if start: self.o("<"+tag+">") diff --git a/test/code_blocks.html b/test/code_blocks.html new file mode 100644 index 00000000..eac54efa --- /dev/null +++ b/test/code_blocks.html @@ -0,0 +1,9 @@ + + +
+This is a bold statement.
+
+This is a foreign word.
+
+ + diff --git a/test/code_blocks.md b/test/code_blocks.md new file mode 100644 index 00000000..4bc252a6 --- /dev/null +++ b/test/code_blocks.md @@ -0,0 +1,6 @@ + + This is a bold statement. + + This is a foreign word. + +