How do I add syntax highlighting to a WordPress blog hosted on WordPress.com?

前端 未结 9 666
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 07:57

I\'d like to have a good syntax highlighter for my WordPress blog. What options do I have available? I often see one which has well-colored syntax highlighting and options to c

相关标签:
9条回答
  • 2021-01-31 08:16

    I have developed a lightweight syntax highlighter plugin for WordPress called "Mivhak". The plugin has a backend code editor to easily insert code, with live error checking and syntax highlighting. It is also highliy customizable.

    The plugin is hosted on wordpress.org

    0 讨论(0)
  • 2021-01-31 08:17

    http://wordpress.org/extend/plugins/devformatter/

    WP Plugin for various syntax highlighting!

    0 讨论(0)
  • 2021-01-31 08:21

    SyntaxHighlighter is a pretty good tool. It uses JavaScript with CSS classes to mark HTML elements that should be highlighted. It also allows code to be copied to the clipboard and printed.

    0 讨论(0)
  • 2021-01-31 08:24

    On wordpress.com, you can't install plugins, so you have to use Wordpress' built-in widget.

    Do it like:

    [code language='python']
    
    [/code]
    

    Note that those tags go inside your visual editor, not the HTML editor.

    You can find more information here.

    0 讨论(0)
  • 2021-01-31 08:27

    Here is an offline option (I know you are asking about online tool but just in case ...)

    I use offline tools to process the blog entry with source code examples into html format and then just post the html.

    It's really just:

    • offset source code by at least 4 spaces and specify language on the first line like :::html
    • run your file through:

    python script:

    import markdown
    html = markdown.markdown(text,['codehilite'])
    

    I setup markdown with pygments probably you could just use pygments for source code. You run the file thought the script and then copy paste the html to your blog.

    You can dump css style, to highlight syntax, from pygments and then either link to it or include it in your page. I'm not sure if wordpress supports that.

    Here is how to setup markdown with pygments to do syntax highlighting (for Blogger - the only specifics for Blogger is that it updates the Blogger css with the css to highlight code).

    0 讨论(0)
  • 2021-01-31 08:30

    The best way for syntax highlighting is using prismjs, which is completely free with awesome features.

    1. It has support for almost all programming languages, shell scripts and much more.

    2. It is very light weight and it will not bog down your sites speed like other syntax highlighting plugins.

    For configuring prismjs you need to do little code tweaks in your function.php file. Follow the turoails in this blog http://skillslane.com/setup-syntax-highlighter-for-wordpress/

    0 讨论(0)
提交回复
热议问题