2
我使用Jekyll與Pygments將Markdown轉換爲靜態html頁面。內容準備爲GitHub pages。要顯示的代碼示例(在該示例外殼命令)我添加以下部分,將文件:如何擴展pygments.lexers.shell的關鍵字列表
{% highlight sh %}
$ ls -1a
.
..
README
{% endhighlight %}
參數sh
是指殼其構成詞法分析器。您也可以選擇其他詞法分析器,例如console
以突出顯示文本。
我注意到一些基本命令如ls
沒有被shell詞法分析器突出顯示。這也可以在source code of the lexer中看到。以下摘錄顯示shell詞法分析器的關鍵字定義(可在BashLexer類中找到)。
...
'basic': [
(r'\b(if|fi|else|while|do|done|for|then|return|function|case|'
r'select|continue|until|esac|elif)\s*\b',
Keyword),
(r'\b(alias|bg|bind|break|builtin|caller|cd|command|compgen|'
r'complete|declare|dirs|disown|echo|enable|eval|exec|exit|'
r'export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|'
r'local|logout|popd|printf|pushd|pwd|read|readonly|set|shift|'
r'shopt|source|suspend|test|time|times|trap|true|type|typeset|'
r'ulimit|umask|unalias|unset|wait)\s*\b(?!\.)',
Name.Builtin),
(r'#.*\n', Comment),
(r'\\[\w\W]', String.Escape),
(r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
(r'[\[\]{}()=]', Operator),
(r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
(r'&&|\|\|', Operator),
],
...
有什麼方法可以擴展關鍵字列表,或者您可以推薦另一個詞法分析器嗎?
你可以看看也很受歡迎的[彩虹語法熒光筆](https://github.com/ccampbell/rainbow)。它的外殼模式演示[這裏](http://htmlpreview.github.com/?https://raw.github.com/ccampbell/rainbow/master/demos/shell.html)。它突出了我嘗試過的'ls -1a',應該很容易整合。 –