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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pygments support #876

Closed
nlhkabu opened this issue Dec 30, 2015 · 7 comments
Closed

Add Pygments support #876

nlhkabu opened this issue Dec 30, 2015 · 7 comments
Assignees
Labels
HTML requires change to HTML files UX/UI design, user experience, user interface

Comments

@nlhkabu
Copy link
Contributor

nlhkabu commented Dec 30, 2015

It would be great if code rendered in long descriptions could be syntax highlighted with a library like pygments.

I can handle the actual selection and application of colors in the CSS, if someone else is happy to integrate the library that applies the classes. Related #800.

@nlhkabu nlhkabu added UX/UI design, user experience, user interface HTML requires change to HTML files labels Dec 30, 2015
@dstufft
Copy link
Member

dstufft commented Dec 30, 2015

Hmm, we should already be doing this too.

@dstufft
Copy link
Member

dstufft commented Dec 30, 2015

Yes, if you take a look at https://warehouse-staging.python.org/project/dstufft.cryptography/ it already has the classes there. It just needs styled.

@nlhkabu
Copy link
Contributor Author

nlhkabu commented Dec 30, 2015

OK. So then, any code that is coming through without Pygments support (e.g. https://warehouse-staging.python.org/project/python-ldap-test/) is because the source file doesn't support it?

Would it be worthwhile documenting how users should write their READMEs so that they get code highlighting on PyPI? ping @ddbeck

@dstufft
Copy link
Member

dstufft commented Dec 30, 2015

Yea, they probably aren't instructing the rst renderer as to what language it is. Generally you want to do something like (taken from pyca/cryptography):

.. code-block:: pycon

    >>> from cryptography.fernet import Fernet
    >>> # Put this somewhere safe!
    >>> key = Fernet.generate_key()
    >>> f = Fernet(key)
    >>> token = f.encrypt(b"A really secret message. Not for prying eyes.")
    >>> token
    '...'
    >>> f.decrypt(token)
    'A really secret message. Not for prying eyes.'

The name (like pycon) can be anything that shows up as a shortname from http://pygments.org/docs/lexers/.

@ryanhiebert
Copy link

For my stuff on PyPI I've found that unrecognized languages also stop it from parsing. For example, with https://pypi.python.org/pypi/tox-travis, I have an example YAML file, and while GitHub recognized the rST, PyPI did not, and so assumed it was plain text. I had to remove the language specifier so PyPI would format it at all.

@ddbeck
Copy link
Contributor

ddbeck commented Jan 4, 2016

@nlhkabu Sorry not getting to this quicker! I already had it in mind to briefly encourage readmes in the new tutorial about making packages, so I suppose the next step would be to provide guidelines on including a PyPI-friendly readme as well. I've opened a new issue for the idea.

On another note, @ryanhiebert's report on unrecognized languages suggests that it would be nice if unrecognized lexers fell back to plain text rather than unformatted text. I'm not sure if that's something that would need to change in pygments or warehouse (or somewhere else) though.

@dstufft
Copy link
Member

dstufft commented Jan 4, 2016

That'd be in https://github.com/pypa/readme probably.

@nlhkabu nlhkabu added this to the Become PyPI milestone Jan 26, 2016
@nlhkabu nlhkabu closed this as completed Feb 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTML requires change to HTML files UX/UI design, user experience, user interface
Projects
None yet
Development

No branches or pull requests

4 participants