Welcome! And thanks for taking your time to contribute to this project 🤩
- Contributing to accessible pygments themes
Please share your thoughts on fixes and features in the issue tracker. When doing so, add a clear description, and provide as much information as possible about your environment.
You will need to have the following installed locally:
git
- Python >= 3.9
- hatch
-
Fork this repository to your GitHub account, then clone it to your local machine:
git clone https://github.com/<your-username>/accessible-pygments.git
Remember that this fork is a copy of the repository and any changes in it don't affect the original one.
-
From here you can create your local environments with hatch:
hatch env create
-
You can verify that the environment was created successfully by running:
$ hatch env show ┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Type ┃ Dependencies ┃ Scripts ┃ ┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩ │ default │ virtual │ │ │ ├─────────┼─────────┼──────────────┼───────────────────┤ │ dev │ virtual │ │ css │ │ │ │ │ render_html │ | | | | update_theme_docs | ├─────────┼─────────┼──────────────┼───────────────────┤ │ test │ virtual │ hypothesis │ tests │ │ │ │ pytest │ │ └─────────┴─────────┴──────────────┴───────────────────┘
You can run the tests directly with hatch:
hatch run test:tests
You can generate individual HTML files for each of the themes included in accessible_pygments
by running:
hatch run dev:render_html
This will add the HTML files under docs/
for each supported theme.
We recommend using your favorite browser to see the rich HTML output.
We use several linters and formatters to ensure the code is consistent and clean. You can run this with:
hatch run dev:lint
Our package is divided by themes, where each folder has the style of each theme, a description in Markdown and the source CSS file.
├── a11y_pygments
│ ├── a11y_dark
│ │ ├── style.py
│ │ ├── style.css
│ │ ├── README.md
│ ├── a11y_light
│ │ ├── style.py
│ │ ├── style.css
│ │ ├── README.md
To add a new theme, please create a folder with your new theme name, like white-cats
and add the three files
described before (so that it matches the rest of the themes).
You can use as a base one of our existing themes, this file needs to define a new class named Theme
with the new colors and rules you want.
NOTE 📝 Please try to encapsulate all the raw colors in the
Colors
enum
and call them in the rules section. This will help us with maintenance 🙏.
While working on your theme, it might be helpful to generate example HTML files with the following command:
hatch run dev:render_html
The HTML files are generated from sample source code files located under tests/scripts
.
If successful, you should be able to see the results of your new theme applied to those code files under docs/_build/<your-theme>
.
If you prefer to inspect the CSS separately from the HTML, use the following command:
hatch run dev:create_css
This will add the CSS file under docs/_build/css/<your-theme>.css
.
Once you are happy with the colors and the rules in the style file, please update the README for your new theme! You can generate a README with the following command:
hatch run dev:update_theme_docs your_theme_module_name
This script will:
- generate a table of contrast ratios of the colors you've chosen and their compliance with WCAG,
- pull the docstring from the
Theme
class and put it in the README as the description for your theme (if you are porting a theme or color palette developed elsewhere please acknowledge your source(s) in the docstring of theTheme
class), - take a screenshot of your theme applied to a code sample, save it at
a11y_pygments/<your_theme>/images/<your_theme>.png
, and embed it in the theme README.
Also, don't forget to add the name of your theme to our list of supported themes in the main README.
We have a demo page where you will be able to change the style of different languages at the same time. To add your new theme:
- Open the
[docs/index.html](docs/index.html)
file. - Add your new theme name to the
themes
section:
With this change, you will be able to open docs/index.html
in your favorite browser and find your new theme in our demo!
Once you have added and verified your theme you should be ready to open a Pull Request 👏🏻