Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃憣 IMPROVE: Code block highlighting #478

Merged
merged 5 commits into from Dec 29, 2021
Merged

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.

None yet

1 participant