Skip to content

Conversation

@chrisjsewell
Copy link
Member

In markdown a code block (a.k.a fence) is of the form:

```language
source text
```

MyST-Parser mimics the code-block directive to render these blocks:

In sphinx, the lexer name is only recorded as the language attribute,
and the text is lexed later by pygments within the visit_literal_block
method of the output format SphinxTranslator.
This is the current logic.

However, in docutils, this directive directly parses the text with the pygments lexer, if syntax highlighting is enabled (the default). This was not handled.

Both cases are now handled, and additionally the following configuration are added:

  • myst_highlight_code_blocks (docutils only): If True (default) use pygments to create lexical tokens for the given language, otherwise skip lexical analysis
  • myst_number_code_blocks: A list of languages to add line numbers to

@codecov
Copy link

codecov bot commented Dec 29, 2021

Codecov Report

Merging #478 (3620554) into master (6c44075) will decrease coverage by 0.16%.
The diff coverage is 85.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #478      +/-   ##
==========================================
- Coverage   90.19%   90.02%   -0.17%     
==========================================
  Files          16       16              
  Lines        2030     2056      +26     
==========================================
+ Hits         1831     1851      +20     
- Misses        199      205       +6     
Flag Coverage Δ
pytests 90.02% <85.36%> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
myst_parser/docutils_renderer.py 92.13% <80.64%> (-0.53%) ⬇️
myst_parser/__init__.py 88.57% <100.00%> (+0.33%) ⬆️
myst_parser/main.py 88.80% <100.00%> (-0.28%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c44075...3620554. Read the comment docs.

@chrisjsewell chrisjsewell merged commit 2b3a931 into master Dec 29, 2021
@chrisjsewell chrisjsewell deleted the docutils-code-block branch December 29, 2021 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants