Skip to content

Commit

Permalink
Default to Python highlighting for '::' code blocks.
Browse files Browse the repository at this point in the history
Other languages can be set like '.. code-block:: c'.
  • Loading branch information
hugovk committed Dec 11, 2020
1 parent a91ec43 commit ee186f6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions peps/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ def convert_pep_page(pep_number, content):
div = pep_content.new_tag('div')
div['class'] = ['highlight']
cb.wrap(div)
# Highlight existing pure-Python PEPs
if int(pep_number) in PURE_PYTHON_PEPS:
literal_blocks = pep_content.find_all('pre', class_='literal-block')
for lb in literal_blocks:
block = lb.string
if block:
highlighted = highlight(block, PythonLexer(), HtmlFormatter())
lb.replace_with(BeautifulSoup(highlighted).html.body.div)

# Default to Python highlighting for '::' code blocks.
# Other languages can be set like '.. code-block:: c'.
literal_blocks = pep_content.find_all('pre', class_='literal-block')
for lb in literal_blocks:
block = lb.string
if block:
highlighted = highlight(block, PythonLexer(), HtmlFormatter())
lb.replace_with(BeautifulSoup(highlighted, 'lxml').html.body.div)

pep_href_re = re.compile(r'pep-(\d+)\.html')

Expand Down

0 comments on commit ee186f6

Please sign in to comment.