Add syntax highlighting to gh-pages

前端 未结 5 1745
遥遥无期
遥遥无期 2020-12-14 01:07

Is there an easy way to add syntax highlighting to my various plugin\'s gh-pages using github\'s Pygments?

I know that every page runs through the Jekyll engine and

5条回答
  •  一整个雨季
    2020-12-14 01:59

    As pointed out by @David Douglas, "GitHub Pages now only supports Rouge, a pure-Ruby syntax highlighter"

    You have to put this in you _config.yml. This is from the _config.yml of Barry Clark's Jekyll Now

    # Jekyll 3 now only supports Kramdown for Markdown
    kramdown:
        # Use GitHub flavored markdown, including triple backtick fenced code blocks
        input: GFM
        # Jekyll 3 and GitHub Pages now only support rouge for syntax highlighting
        syntax_highlighter: rouge
        syntax_highlighter_opts:
            # Use existing pygments syntax highlighting css
            css_class: 'highlight'
    

    Then for the code highlighting part...

    The list of langauge aliases for Rouge are listed here: https://github.com/jneen/rouge/wiki/List-of-supported-languages-and-lexers

    It uses all-lowercase latters.

    For example, for JavaScript:

    ``` javascript
    function test() {
        console.log("test");
    }
    ```
    

提交回复
热议问题