みんなどうやってブログにソースコード埋めてるのかと調べてみた
スクリプトを埋め込んでpreタグを使うといい感じになる
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=sons-of-obsidian" />
スキンはsons-of-obsidian以外にもいろいろあります
ただのpreタグをはてなブログで表示すると
<pre> log("hello world"); </pre>
それがこうなる
<pre class="prettyprint lang-java linenums=true"> log("hello world"); </pre>
いろいろな言語に対応しているみたい
<pre class="prettyprint lang-html linenums=true"> The lang-* class specifies the language file extensions. File extensions supported by default include: "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", "xhtml", "xml", "xsl". </pre>
ちなみにはてなブログで全ての記事に適用するには、
設定→詳細設定タブ→下のほうに「headに要素を追加」
があるのでここにScriptタグを貼ればOKです。