Ask Your Question
2

Is askbot having code highlighting?

asked 2019-07-03 03:50:59 -0500

testuser's avatar

for various languages is askbot supporting code/ keyword lightlights?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-07-10 16:49:18 -0500

martin-bts's avatar

updated 2019-07-19 05:28:26 -0500

In theory, Askbot uses python-markdown2 so it can do everything described in the markdown2 wiki. However, the current code, i.e. askbot.utils.markdown.get_parser does not enable syntax highlighting.

For a least invasive extension one could subclass markdown2.Markdown, extend the constructor and assign the new subclass to ASKBOT_MARKDOWN_CLASS in settings.py. I didn't test the following, but I am confident solutions look something like this:

  • in somefile.py (in Askbot's PYTHONPATH)

    import markdown2
    
    class MyMarkdown(markdown2.Markdown):
        def __init__(self, *args, **kwargs):
             extras = kwargs.get('extras', list())
             extras.extend(['fenced-code-blocks'])
             kwargs['extras'] = extras
             super(MyMarkdown, self).__init__(*args, **kwargs)
    
  • in settings.py

    ASKBOT_MARKDOWN_CLASS = 'somefile.MyMarkdown'
    
edit flag offensive delete link more

Comments

And as we can see in this particular case, this site applies highlighting to Python code if it can detect it. So I guess the `fenced-code-blocks` is only required if want the ability to explicitly select a certain language.

martin-bts's avatar martin-bts  ( 2019-07-10 16:52:05 -0500 )edit
1

From the fine manual: "You must have the pygments Python module installed for this to work."

martin-bts's avatar martin-bts  ( 2019-07-17 10:41:33 -0500 )edit

You need to have the pygments module installed for it to work

webdios's avatar webdios  ( 2020-02-15 02:32:28 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-07-03 03:50:14 -0500

Seen: 7,889 times

Last updated: Jul 19 '19