Khan / Khan/pygments-server

Allowing to pass options to url resp. pygments

Open
#1 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4
Forks
2
PR merge metrics
No merged PRs in 30d

Description

A long time we were searching for a solution to solve the performance problems with the Mediawiki SyntaxHightlight extension which calls python for each code block separately. Before we got completely frustrated we came across this project which solved our issue. Thank you very much for it.
To let the pymets-server run together with SyntaxHighlight we modified the main.py a bit because we needed to pass certain options (e. g. cssclass) to the pygments formatter.

To avoid such hacks which could also occur in other use cases, we suggest to add an "options" url parameter (maybe "style" should be removed then) to the pygmentize server method which then passes them into the function call of _get_formatter_by_name(alias, **options). When calling pygmetize with Python such option are passed like -O cssclass=mw-highlight,encoding=utf-8. Maybe the url could then be like this: http://server:port?lang=sql&options=cssclass%3Dmw-highlight%2Cencoding%3Dutf-8. Of course, another flexible format is also possible. Finally, the options parameter is then taken, decoded and decomposed before it is passed to the method get_formatter_by_name.

We would be very grateful if somebody comments or even works on this feature.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read main.py and locate the pygmentize server method, then trace how URL parameters reach get_formatter_by_name. Review the existing style parameter handling and determine a compatible representation for formatter options. Done means URL-supplied options are decoded and passed to the formatter without requiring a local modification.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.