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: Add CSS support for 8-bit ANSI colours #379

Merged
merged 2 commits into from
Jan 3, 2022

Conversation

thiippal
Copy link
Contributor

@thiippal thiippal commented Jan 3, 2022

This pull request adds support for 8-bit ANSI colours, as discussed in #378.

I got the ANSI to RGB mappings from this repository and converted them into a JSON file.

I then wrote the following script to create the style definitions with hex colour codes:

with open('ansi-to-rgb.json') as file:

	rgb = json.load(file)

	for ansi, rgb in rgb.items():
	
		N = int(ansi)
		HEX = f'#{rgb[0]:02x}{rgb[1]:02x}{rgb[2]:02x}'.upper()
		
		print(f'div.highlight .-Color[class*=-C{N}] \u007b\n  color: {HEX} \n\u007d')
		print(f'div.highlight .-Color[class*=-BGC{N}] \u007b\n  background-color: {HEX} \n\u007d')

Test results:

============================================ test session starts ============================================
platform darwin -- Python 3.9.9, pytest-5.4.3, py-1.11.0, pluggy-0.13.1
rootdir: MyST-NB, inifile: tox.ini
plugins: datadir-1.3.1, regressions-2.2.0, anyio-3.4.0, cov-2.10.1
collected 68 items                                                                                          

tests/test_ansi_lexer.py ...........                                                                  [ 16%]
tests/test_execute.py .....................                                                           [ 47%]
tests/test_glue.py .......                                                                            [ 57%]
tests/test_mystnb_features.py ..                                                                      [ 60%]
tests/test_nb_render.py ............                                                                  [ 77%]
tests/test_parser.py ...                                                                              [ 82%]
tests/test_render_outputs.py .........                                                                [ 95%]
tests/test_text_based.py ...                                                                          [100%]

============================================ 68 passed in 54.55s ============================================

@codecov
Copy link

codecov bot commented Jan 3, 2022

Codecov Report

Merging #379 (52d2b80) into master (9ade331) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #379   +/-   ##
=======================================
  Coverage   87.35%   87.35%           
=======================================
  Files          12       12           
  Lines        1368     1368           
=======================================
  Hits         1195     1195           
  Misses        173      173           
Flag Coverage 螖
pytests 87.35% <酶> (酶)

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


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 9ade331...52d2b80. Read the comment docs.

@thiippal thiippal changed the title Add support for 8-bit ANSI colours [ENH] Add support for 8-bit ANSI colours Jan 3, 2022
Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me ta!

@chrisjsewell chrisjsewell changed the title [ENH] Add support for 8-bit ANSI colours 馃憣 IMPROVE: Add CSS support for 8-bit ANSI colours Jan 3, 2022
@chrisjsewell chrisjsewell linked an issue Jan 3, 2022 that may be closed by this pull request
@chrisjsewell chrisjsewell merged commit 619f388 into executablebooks:master Jan 3, 2022
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.

Include CSS classes for 8-bit ANSI colors
2 participants