Skip to content

Commit 1613c30

Browse files
committed
Merge branch 'develop'
2 parents 55c9e84 + 478b1c7 commit 1613c30

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/MANIFEST
99
/venv
1010
build/
11+
.vscode/settings.json

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ newline_style
9696
newline). While the latter convention is non-standard, it is commonly
9797
preferred and supported by a lot of interpreters.
9898

99+
code_language
100+
Defines the language that should be assumed for all ``<pre>`` sections.
101+
Useful, if all code on a page is in the same programming language and
102+
should be annotated with `````python`` or similar.
103+
Defaults to ``''`` (empty string) and can be any string.
104+
99105
Options may be specified as kwargs to the ``markdownify`` function, or as a
100106
nested ``Options`` class in ``MarkdownConverter`` subclasses.
101107

markdownify/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class DefaultOptions:
7676
strong_em_symbol = ASTERISK
7777
sub_symbol = ''
7878
sup_symbol = ''
79+
code_language = ''
7980

8081
class Options(DefaultOptions):
8182
pass
@@ -324,7 +325,7 @@ def convert_p(self, el, text, convert_as_inline):
324325
def convert_pre(self, el, text, convert_as_inline):
325326
if not text:
326327
return ''
327-
return '\n```\n%s\n```\n' % text
328+
return '\n```%s\n%s\n```\n' % (self.options['code_language'], text)
328329

329330
convert_s = convert_del
330331

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
pkgmeta = {
1111
'__title__': 'markdownify',
1212
'__author__': 'Matthew Tretter',
13-
'__version__': '0.9.4',
13+
'__version__': '0.10.0',
1414
}
1515

1616

tests/test_conversions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,8 @@ def test_sub():
210210
def test_sup():
211211
assert md('<sup>foo</sup>') == 'foo'
212212
assert md('<sup>foo</sup>', sup_symbol='^') == '^foo^'
213+
214+
215+
def test_lang():
216+
assert md('<pre>test\n foo\nbar</pre>', code_language='python') == '\n```python\ntest\n foo\nbar\n```\n'
217+
assert md('<pre><code>test\n foo\nbar</code></pre>', code_language='javascript') == '\n```javascript\ntest\n foo\nbar\n```\n'

0 commit comments

Comments
 (0)