h1 and h2 tag conversion
This commit is contained in:
@@ -36,6 +36,16 @@ class MarkdownConverter(object):
|
||||
node.clear()
|
||||
node.text = text
|
||||
|
||||
def underline(self, text, pad_char):
|
||||
text = (text or '').rstrip()
|
||||
return '%s\n%s\n\n' % (text, pad_char * len(text)) if text else ''
|
||||
|
||||
def convert_h1(self, el):
|
||||
return self.underline(el.text, '=')
|
||||
|
||||
def convert_h2(self, el):
|
||||
return self.underline(el.text, '-')
|
||||
|
||||
|
||||
def markdownify(html, strip=None, keep=None):
|
||||
converter = MarkdownConverter(strip, keep)
|
||||
|
||||
9
tests.py
9
tests.py
@@ -9,3 +9,12 @@ class BasicTests(unittest.TestCase):
|
||||
|
||||
def test_soup(self):
|
||||
self.assertEqual(md('<div><span>Hello</div></span>'), 'Hello')
|
||||
|
||||
|
||||
class ConversionTests(unittest.TestCase):
|
||||
|
||||
def test_h1(self):
|
||||
self.assertEqual(md('<h1>Hello</h1>'), 'Hello\n=====\n\n')
|
||||
|
||||
def test_h2(self):
|
||||
self.assertEqual(md('<h2>Hello</h2>'), 'Hello\n-----\n\n')
|
||||
|
||||
Reference in New Issue
Block a user