When in doubt of which type of code block alias to use in your RST file, pygments provides all available lexers 📜 for a neat documentation project
https://pygments.org/docs/lexers/
#pygments #RST #sphinx
Available lexers — Pygments

I'm wrapping up the last two pages of documentation for my thing and while documenting a handful of example commands in interactive mode, I thought

"Man wouldn't it be nice if this had syntax highlighting, at least for keywords and arguments? I wouldn't need to use 'console' for sphinx code blocks, and it would not be this drab gray..."

Fast forward 45 minutes later, I'm in the middle of a gnarly custom Pygments regex lexer and I think:

"Oh but what if I just read the commands module source tree and parsed the AST to extract command names from functions that have the typer decorator? I would never need to maintain that list again and they'd always be keywords!"

The real "What the fuck am I doing with my life?" moment was marginally offset by how it actually worked on first try, against all expectations.

Sphinx is insidious. Once you start extending it there's no end in sight.

#Python #Sphinx #Pygments #programming

Python-kodeblokk

Eksempel på kodeblokk med Python:

def main(): print("Hello, world!")Code language: Python (python)

Med Microformats-prefiks h-, p- o.l. så kunne kanskje formateringa vha. CSS-klasser ha sluppet gjennom.

… the #Pygments lexer for #CommonLisp treats ‘defun’ and ‘list*’ (among other symbols) as basically the same thing. They're both ‘builtins’.

As the kids say, my disappointment is immeasurable.

Ggghh, emacs --batch + font-lock-fontify-buffer + output the face changes maybe?

If you use the pygments syntax highlighter (for example in your documentation), and you have examples that produce output (for example from the shell or Python REPL), here is a tip that I just discovered: look for the "console session" version of your language on this page: https://pygments.org/languages/
It keeps the language's syntactic coloring while dealing correctly with the prompt and output. Also when you copy the code, it will avoid copying the prompt.

#Python #pygments #foss

Languages — Pygments

Service toot: Just in case you need a reason to update your #TeXLive:

#minted finally release the 3.0.0 which provides an own binary which makes the python/ #pygments setup obsolete. This also drops the requirement of shell-escape (or different hacks) to use the syntax highlighting.

Ensure to not only update the package itself, as you also need to update the settings which allow it to run in restricted mode.

#TeXLaTeX

#pygments 、Racket のコードもちゃんとシンタックスハイライティングしてくれるのかなり嬉しいな。
Racket に最初から入っている手続きに色が付いているので Racket の手続きやマクロのリストを持っているっぽい。
すばらしい。

Is Brent Roose on the Fediverse anywhere? I love this idea, and I’d love to help contribute.

I started down the path of trying to port #Pygments to #PHP a while back. I maintained a PHP wrapper for it (https://github.com/ramsey/pygments), and even set up a GitHub organization for “Phygments.” 😉 https://github.com/phygments

I want to help make this happen. Maybe I’ll have to email Brent if he’s not on the Fediverse.

@freekmurze @pronskiy Do either of you know if he’s here? https://mastodon.social/@php_discussions/112118298296419881

GitHub - ramsey/pygments: 💅 A PHP wrapper for Pygments, the Python syntax highlighter, forked from the Pygments.php project

💅 A PHP wrapper for Pygments, the Python syntax highlighter, forked from the Pygments.php project - ramsey/pygments

GitHub

I used two default styles of "pygments" with high contrast ratio 🎨
https://pygments.org/styles/

#a11y #pygments #contrast #styles #code

Styles — Pygments

At last, submitted a proposal for a #Python source code annotator for #wily, by @tonybaloney.

It allows inline visualization of code metrics in source code, inspired by @coveragepy

Uses #radon to calculate #Cyclomatic #Complexity and #Halstead metrics, then adds color coded metric values to a #Pygments highlighted source listing and allows changing the metrics for visualization.

The code works, there are screenshots and an example in the linked issue.

#codequality

https://github.com/tonybaloney/wily/issues/217

Generate annotated source listings with inline visualization of code metrics · Issue #217 · tonybaloney/wily

Wily should be able to generate color coded source listings with inline visualization of code metrics from detailed metric results. The inspiration for this comes from #88 (which has an early previ...

GitHub