pyvec / naucse.python.cz

Website with learning materials / Stránka s učebními materiály
https://naucse.python.cz
Other
322 stars 118 forks source link

Colorized shell output in Markdown #61

Closed encukou closed 5 years ago

encukou commented 7 years ago

The PyLadies materials for Git use HTML for colorized shell output. Is there a better way? How to do this in Markdown?

hroncok commented 7 years ago

Keep the color escape codes and write a plugin for the Markdown parser that converts them to HTML style/class?

benabraham commented 7 years ago

I use https://highlightjs.org/ on client. Many syntaxes, many color themes.

hroncok commented 7 years ago

Here we use Pygments.

encukou commented 7 years ago

Pygments also has many syntaxes and color schemes for syntax highliting. This is not about syntax highlighting, though.

Als, no JS please. All this could end up printed in a book.

benabraham commented 7 years ago

I get it now. Sorry for OT. @hroncok's idea is probably the best. It will be mostly copy&paste when created. A question is if it will be easy enough to edit such source.

Sanqui commented 7 years ago

I believe ansi2html can be used for this.

hroncok commented 7 years ago

https://github.com/pyvec/naucse.python.cz/blob/e2c0ea93799e64e760dc51f5de948b1cbb3a5145/naucse/markdown_util.py#L63

Seems easy!

from ansi2html import Ansi2HTMLConverter
ansi_convertor = Ansi2HTMLConverter(inline=True)

...

        if lang == 'ansi':
            converted = ansi_convertor.convert(code, full=False)  # already escapes HTML (do we need to use some Markup() equivalent in mistune?)
            return '<div class="codehilite"><pre><code>{}</code></pre></div>'.format(converted)        
encukou commented 7 years ago

Reopening this – it still should be possible to do it in a more elegant way.

hroncok commented 7 years ago

GitHub umí tohle:

```patch
diff --git a/setup.py b/setup.py
index 3a69792..6b453ab 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ setup(
     keywords='holiday,dates',
     license='Public Domain',
     url='https://gist.github.com/oskar456/e91ef3ff77476b0dbc4ac19875d0555e',
-    py_modules=['isholiday'],
+    packages=['isholiday'],
     classifiers=[
         'Intended Audience :: Developers',
         'License :: Public Domain',

Nevyřešilo by to všechny případy, ale pro diffy/commity by to vypadalo dobře i na githubu i na webu, kdybychom měli pro pygments takový lexer.

encukou commented 7 years ago

Mám za to že v Pygments se jen jinak jmenuje – diff

hroncok commented 7 years ago

Když jsme to použil, vypadalo to jako plaintext. Možná něco dělám špatně.

encukou commented 5 years ago

Still not ideal, but I don't think it makes sense to track this here – there'll always be something more inportant.