ul and li conversion
This commit is contained in:
@@ -83,6 +83,14 @@ class MarkdownConverter(object):
|
||||
def convert_i(self, el):
|
||||
return self.convert_em(el)
|
||||
|
||||
def convert_li(self, el):
|
||||
parent = el.getparent()
|
||||
if parent is not None and parent.tag == 'ol':
|
||||
bullet = '%s.' % (parent.index(el) + 1)
|
||||
else:
|
||||
bullet = '*'
|
||||
return '%s %s\n' % (bullet, el.text or '')
|
||||
|
||||
def convert_strong(self, el):
|
||||
return '**%s**' % el.text if el.text else ''
|
||||
|
||||
|
||||
6
tests.py
6
tests.py
@@ -35,5 +35,11 @@ class ConversionTests(unittest.TestCase):
|
||||
def test_i(self):
|
||||
self.assertEqual(md('<i>Hello</i>'), '*Hello*')
|
||||
|
||||
def test_ol(self):
|
||||
self.assertEqual(md('<ol><li>a</li><li>b</li></ol>'), '1. a\n2. b\n')
|
||||
|
||||
def test_strong(self):
|
||||
self.assertEqual(md('<strong>Hello</strong>'), '**Hello**')
|
||||
|
||||
def test_ul(self):
|
||||
self.assertEqual(md('<ul><li>a</li><li>b</li></ul>'), '* a\n* b\n')
|
||||
|
||||
Reference in New Issue
Block a user