Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1613c302bc | ||
|
|
478b1c7e13 | ||
|
|
ffcf6cbcb2 | ||
|
|
0ab0452414 | ||
|
|
b62b067cbd | ||
|
|
cb2646cd93 | ||
|
|
9692b5e714 | ||
|
|
ac68c53a7d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@
|
|||||||
/MANIFEST
|
/MANIFEST
|
||||||
/venv
|
/venv
|
||||||
build/
|
build/
|
||||||
|
.vscode/settings.json
|
||||||
|
|||||||
@@ -96,6 +96,12 @@ newline_style
|
|||||||
newline). While the latter convention is non-standard, it is commonly
|
newline). While the latter convention is non-standard, it is commonly
|
||||||
preferred and supported by a lot of interpreters.
|
preferred and supported by a lot of interpreters.
|
||||||
|
|
||||||
|
code_language
|
||||||
|
Defines the language that should be assumed for all ``<pre>`` sections.
|
||||||
|
Useful, if all code on a page is in the same programming language and
|
||||||
|
should be annotated with `````python`` or similar.
|
||||||
|
Defaults to ``''`` (empty string) and can be any string.
|
||||||
|
|
||||||
Options may be specified as kwargs to the ``markdownify`` function, or as a
|
Options may be specified as kwargs to the ``markdownify`` function, or as a
|
||||||
nested ``Options`` class in ``MarkdownConverter`` subclasses.
|
nested ``Options`` class in ``MarkdownConverter`` subclasses.
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ class MarkdownConverter(object):
|
|||||||
strong_em_symbol = ASTERISK
|
strong_em_symbol = ASTERISK
|
||||||
sub_symbol = ''
|
sub_symbol = ''
|
||||||
sup_symbol = ''
|
sup_symbol = ''
|
||||||
|
code_language = ''
|
||||||
|
|
||||||
class Options(DefaultOptions):
|
class Options(DefaultOptions):
|
||||||
pass
|
pass
|
||||||
@@ -324,7 +325,7 @@ class MarkdownConverter(object):
|
|||||||
def convert_pre(self, el, text, convert_as_inline):
|
def convert_pre(self, el, text, convert_as_inline):
|
||||||
if not text:
|
if not text:
|
||||||
return ''
|
return ''
|
||||||
return '\n```\n%s\n```\n' % text
|
return '\n```%s\n%s\n```\n' % (self.options['code_language'], text)
|
||||||
|
|
||||||
convert_s = convert_del
|
convert_s = convert_del
|
||||||
|
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
|||||||
pkgmeta = {
|
pkgmeta = {
|
||||||
'__title__': 'markdownify',
|
'__title__': 'markdownify',
|
||||||
'__author__': 'Matthew Tretter',
|
'__author__': 'Matthew Tretter',
|
||||||
'__version__': '0.9.4',
|
'__version__': '0.10.0',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -210,3 +210,8 @@ def test_sub():
|
|||||||
def test_sup():
|
def test_sup():
|
||||||
assert md('<sup>foo</sup>') == 'foo'
|
assert md('<sup>foo</sup>') == 'foo'
|
||||||
assert md('<sup>foo</sup>', sup_symbol='^') == '^foo^'
|
assert md('<sup>foo</sup>', sup_symbol='^') == '^foo^'
|
||||||
|
|
||||||
|
|
||||||
|
def test_lang():
|
||||||
|
assert md('<pre>test\n foo\nbar</pre>', code_language='python') == '\n```python\ntest\n foo\nbar\n```\n'
|
||||||
|
assert md('<pre><code>test\n foo\nbar</code></pre>', code_language='javascript') == '\n```javascript\ntest\n foo\nbar\n```\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user