How to blog code at wordpress.com [closed]

给你一囗甜甜゛ 提交于 2019-11-29 18:51:18
Alex Duggleby

See here: http://en.support.wordpress.com/code/posting-source-code/

Wrap your code in these tags: [sourcecode language='css'] .. [/sourcecode]

(or shorter [code lang='css'] .. [/code] )

Note that Visual Editor doesn't interpret the tags, you need to click Preview to see how it works.

Available language codes:

  • actionscript3
  • bash
  • clojure
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • html
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • r
  • ruby
  • scala
  • sql
  • vb
  • xml

Hope that helps.

You can also use hilite.me. It doesn't require installation of plugins or JS/CSS files. It's also open-source and has an API.

Disclaimer: I'm the developer.

Crayon Syntax Highlighter is an excellent free plugin. I went with that one, but there are many others I came across that may serve the purpose:

There's a <code> html element you can use. Otherwise you could try the Textile or Markdown syntaxes (I'm not sure if WordPress.com uses them). Try it out and use the preview function in WordPress to see when you get it right.

cellepo

With my Wordpress.org installation, I couldn't get the Accepted Answer here to work (not sure if that's only expected to work with Wordpress.com?)...

I ended up using the SyntaxHighlighter plugin instead.

With that plugin, at first, your code will appear escaped in 'Preview Changes' view: It will appear correctly then after publishing. I think thereafter publishing it will then appear correctly in 'Preview Changes' (not 100% about that).

If you are hosting your own wordpress blog opposed to on WP.com you can get this functionality by installing this plugin, since it is the same plugin that the WP.com code relies on.

http://wordpress.org/extend/plugins/google-syntax-highlighter/

You can also use the new web app I wrote called BlogTrog CodeWindow -- it's powered by Actipro CodeHighlighter.

http://www.blogtrog.com

It's free, should work in all modern browsers, and doesn't require you to install anything anywhere. Just paste your code and embed the results.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!