概要

Windows + Cygwin64 + ruby 2.0.0の環境で、JekyllをインストールしMarkdown記法のテキストから静的サイトを生成します。

インストール

  • setup-x86_64.exeから、gcc-coremakerubyrubygemsruby-devellibffi-developensshopensslgitをインストール
  • ~/.gemrcを作成
    install: --no-document
    update: --no-document
    
  • gemでインストール
    gem install jekyll
  • tr: invalid byte sequence in UTF-8 (ArgumentError)とエラーになる場合
    • Cygwin - Ruby-1.9.3p327 - win32/registry - PIBを参考にして、C:/cygwin64/usr/share/ruby/2.0.0/win32/registry.rbを修正
          #
          # Error
          #
          class Error < ::StandardError
            module Kernel32
              extend Fiddle::Importer
              dlload "kernel32.dll"
            end
      #     FormatMessageA = Kernel32.extern "int FormatMessageA(int, void *, int, int, void *, int, void *)", :stdcall
      #     def initialize(code)
      #       @code = code
      #       msg = "\0".force_encoding(Encoding::ASCII_8BIT) * 1024
      #       len = FormatMessageA.call(0x1200, 0, code, 0, msg, 1024, 0)
      #       msg = msg[0, len].force_encoding(Encoding.find(Encoding.locale_charmap))
      #       super msg.tr("\r", '').chomp
      #     end
            FormatMessageW = Kernel32.extern "int FormatMessageW(int, void *, int, int, void *, int, void *)", :stdcall
            def initialize(code)
              @code = code
              msg = "\0\0".force_encoding(Encoding::UTF_16LE) * 1024
              len = FormatMessageW.call(0x1200, 0, code, 0, msg, msg.size, 0)
              msg = msg[0, len].encode(Encoding.find(Encoding.locale_charmap))
              super msg.tr("\r".encode(msg.encoding), '').chomp
            end
            attr_reader :code
          end
      
  • /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: -lcrypt が見つかりませんとエラーになる場合
    • libcrypt-develsetup-x86_64.exeからインストールしてgem install jekyllを再実行
  • -lgmp が見つかりませんとエラーになる場合
    • libgmp-develsetup-x86_64.exeからインストール
      gcc -shared -o stemmer.so porter.o porter_wrap.o -L. -L/usr/lib -L. -fstack-protector -Wl,--export-all-symbols -Wl,--enable-auto-image-base,--enable-auto-import    -lruby220  -lpthread -lgmp -ldl -lcrypt
      /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: -lgmp が見つかりません
      collect2: エラー: ld はステータス 1 で終了しました
      Makefile:254: ターゲット 'stemmer.so' のレシピで失敗しました
      make: *** [stemmer.so] エラー 1
      

実行

  • jekyll new my-awesome-sitemy-awesome-siteディレクトリを作成
    • /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in 'require': cannot load such file -- bigdecimal (LoadError)とエラーになる場合
      • gem install bigdecimalbigdecimalをインストール
  • cd my-awesome-site && bundle exec jekyll buildでビルド
    • LoadError: cannot load such file -- bigdecimalとエラーになる場合
      • ./my-awesome-site/Gemfileファイルにgem 'bigdecimal'を一行追加
    • LoadError: cannot load such file -- jsonとエラーになる場合
      • ./my-awesome-site/Gemfileファイルにgem 'json'を一行追加

Jekyll で google-code-prettify

パーサーをkramdownにして、行頭タブ(4スペース)ブロックの直後に{:class="prettyprint"}、または{:.prettyprint}を追加

 def parse_pre(lines)
   [%Q|#{lines.map {|line| "\t".concat(line) }.join("\n")}|, %Q|{:class="prettyprint"}|]
 end
### サンプルコード
	trayIcon.displayMessage("caption", "text", TrayIcon.MessageType.ERROR);
{:class="prettyprint"}

結果

<h3 id="section">サンプルコード</h3>
<pre class="prettyprint"><code>trayIcon.displayMessage("caption", "text", TrayIcon.MessageType.ERROR);
</code></pre>

default.htmlprettify.js, prettify.cssを追加

<link href="{{ ASSET_PATH }}/css/prettify.css" type="text/css" rel="stylesheet" />
</head>
<body onload="prettyPrint()">
...
<script src="{{ ASSET_PATH }}/js/prettify.js"></script>
</body>

redcarpet

# _config.yml
markdown: redcarpet
redcarpet:
   renderer: Redcarpet::Render::XHTML
   extensions: ["xhtml", "fenced_code_blocks", "strikethrough", "no_intra_emphasis", "lax_spacing"]
  • no_intra_emphasis
    • <pre><code>の中でも、アンダーライン(例: InputMap im = combobox.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);)が、<em>...</em>に変換されるので、no_intra_emphasisで回避

参考リンク

コメント