Merge branch 'AndrewCRichards-andrewcrichards/add_code_samp_kbd_tags' into develop
This commit is contained in:
@@ -205,6 +205,18 @@ class MarkdownConverter(object):
|
||||
return ''
|
||||
return '%s%s%s%s%s' % (prefix, em_tag, text, em_tag, suffix)
|
||||
|
||||
def convert_code(self, el, text, convert_as_inline):
|
||||
prefix, suffix, text = chomp(text)
|
||||
if not text:
|
||||
return ''
|
||||
return '%s`%s`%s' % (prefix, text, suffix)
|
||||
|
||||
def convert_samp(self, el, text, convert_as_inline):
|
||||
return self.convert_code(el, text, convert_as_inline)
|
||||
|
||||
def convert_kbd(self, el, text, convert_as_inline):
|
||||
return self.convert_code(el, text, convert_as_inline)
|
||||
|
||||
def convert_hn(self, n, el, text, convert_as_inline):
|
||||
if convert_as_inline:
|
||||
return text
|
||||
|
||||
@@ -14,3 +14,10 @@ def test_ignore_comments():
|
||||
def test_ignore_comments_with_other_tags():
|
||||
text = md("<!-- This is a comment --><a href='http://example.com/'>example link</a>")
|
||||
assert text == "[example link](http://example.com/)"
|
||||
|
||||
|
||||
def test_code_with_tricky_content():
|
||||
assert md('<code>></code>') == "`>`"
|
||||
assert md('<code>/home/</code><b>username</b>') == "`/home/`**username**"
|
||||
assert md('First line <code>blah blah<br />blah blah</code> second line') \
|
||||
== "First line `blah blah \nblah blah` second line"
|
||||
|
||||
@@ -240,6 +240,27 @@ def test_em_spaces():
|
||||
assert md('foo <em></em> bar') == 'foo bar'
|
||||
|
||||
|
||||
def code_samp_kbd_tests(tag):
|
||||
# Basically re-use test_em() and test_em_spaces(),
|
||||
assert md(f'<{tag}>Hello</{tag}>') == '`Hello`'
|
||||
assert md(f'foo <{tag}>Hello</{tag}> bar') == 'foo `Hello` bar'
|
||||
assert md(f'foo<{tag}> Hello</{tag}> bar') == 'foo `Hello` bar'
|
||||
assert md(f'foo <{tag}>Hello </{tag}>bar') == 'foo `Hello` bar'
|
||||
assert md(f'foo <{tag}></{tag}> bar') in ['foo bar', 'foo bar'] # Either is OK
|
||||
|
||||
|
||||
def test_code():
|
||||
code_samp_kbd_tests('code')
|
||||
|
||||
|
||||
def test_samp():
|
||||
code_samp_kbd_tests('samp')
|
||||
|
||||
|
||||
def test_kbd():
|
||||
code_samp_kbd_tests('kbd')
|
||||
|
||||
|
||||
def test_h1():
|
||||
assert md('<h1>Hello</h1>') == 'Hello\n=====\n\n'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user