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

Use Pygments to format <pre> blocks #138

Open
briancohan opened this issue Aug 30, 2021 · 2 comments
Open

Use Pygments to format <pre> blocks #138

briancohan opened this issue Aug 30, 2021 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@briancohan
Copy link
Contributor

briancohan commented Aug 30, 2021

Right now, in wtpython.formatters we have PythonCodeConverter which assumes all <pre> blocks are python code. This is certainly a good assumption given our code, but it's likely we'll encounter non-python code in a stackoverflow post.

Pygments appears to be able to guess a language from a code block.

https://pygments.org/docs/quickstart/#guessing-lexers
https://pygments.org/docs/api/#pygments.lexers.guess_lexer

Suggest replacing PythonCodeConverter with a PygmentsCodeConverter that will try to detect a language. If there's an issue, then python should be a fallback.

@briancohan briancohan added the enhancement New feature or request label Aug 30, 2021
@briancohan briancohan added this to the UI/UX milestone Aug 30, 2021
@eniraa
Copy link
Contributor

eniraa commented Aug 30, 2021

This shouldn't have to be guessed for every code block. The <pre> blocks should have classes like lang-java or lang-py which specify the language.

@briancohan
Copy link
Contributor Author

briancohan commented Aug 30, 2021

This shouldn't have to be guessed for every code block. The <pre> blocks should have classes like lang-java or lang-py which specify the language.

I haven't looked at the markdown myself or the product of MarkdownConverter but you are correct, we don't have to guess if the language is specified in the markdown already. But when the language is not specified by the author of the question/answer, then we could use Pygments to guess it. I doubt we'll see much ruby or c++ or anything like that, but html/css/js could be in the question or answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants