Sphinx inline code highlight

前端 未结 6 1599
暖寄归人
暖寄归人 2021-02-07 11:03

I use Sphinx to make a website that contains code samples. I\'m successful using the .. code-block directive to get syntax highlighting. But I can\'t get inline syn

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 11:52

    Found a better (sphinx-only) solution: in sphinx/builders/html.py find a line

    from docutils.core import Publisher
    

    and change it to:

    from docutils.core import Publisher
    def process_programmatic_settings(self, settings_spec,
                                      settings_overrides,
                                      config_section):
        if self.settings is None:
            defaults = (settings_overrides or {}).copy()
            # Propagate exceptions by default when used programmatically:
            defaults.setdefault('traceback', True)
            defaults.setdefault('syntax_highlight', 'short') # ADDED THIS LINE
            self.get_settings(settings_spec=settings_spec,
                              config_section=config_section,
                              **defaults)
    Publisher.process_programmatic_settings = process_programmatic_settings
    

    This solution is better then previous ones: since it doesn't double the amount of css rules, and doesn't modify docutils.

    Still, ideal solution would only change conf.py. So there's a plenty space for improvement.

提交回复
热议问题