First time here? Check out the FAQ!
2

Is askbot having code highlighting?
 

for various languages is askbot supporting code/ keyword lightlights?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
testuser's avatar
21
testuser
asked 5 years ago

Comments

see more comments

1 Answer

2

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'
    

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
martin-bts's avatar
78
martin-bts
answered 5 years ago, updated 5 years ago
link

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 (5 years ago)
1

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

martin-bts's avatar martin-bts (5 years ago)

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

webdios's avatar webdios (5 years ago)
see more comments