Code Metaphor

Programming, Writing, Reading, Thoughts…

Pandoku: Ruby에서 Pandoc 쓰기

Pandoc은 Markdown, HTML, LaTeX, ReST, DocBook 등 굉장히 많은 포맷 간의 상호 변환을 해주는 도구인데,

Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and it can write markdown, reStructuredText, HTML, LaTeX, ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki markup, groff man pages, and S5 HTML slide shows.

커맨드라인 툴이기도 하고, Haskell 라이브러리이기도 하다. Pandoc의 특징은 모든 마크업 포맷을 내부 중간 표현 형식으로 한번 만든 다음에, 그것을 다시 출력한다는 점이다. 그래서 HTML 문서를 읽어서 MediaWiki 마크업으로 출력한다던가, Markdown 문서를 읽어서 유닉스 man 페이지를 만든다던가 하는 게 가능하다.

게다가 단순히 Markdown 구현으로 봐서도 사실 다른 구현과 비교하기 힘든 정확도성능을 가지고 있기도 해서, 내가 가장 애용하는 Markdown 구현이기도 하다.

아무튼 최근에 Ruby에서 이걸 써야할 일이 있어서 인터페이스 모듈을 만들어봤다. Ruby가 일본제니까 약간 일본 느낌 나게 이름을 Pandoku라고 지었다.

http://github.com/lunant/pandoku

처음에는 C 인터페이스로 라이브러리를 만들어서 붙이는 것을 생각했지만, Haskell에서 그게 쉽지 않아서 파이프로 통신하게 했다. Gem 배포는 Gemcutter를 이용해서 하고 있다. http://gemcutter.org/gems/pandoku

gem install pandoku

Pandoc 바이너리가 필요한데, 없으면 cabal로 설치하면 된다. Cabal은 Haskell 패키지 매니저다.

cabal install pandoc

Pandoku는 기본적으로 PATH 환경변수에서 pandoc을 찾는다. 만약 PATH에 없다면 별도로 PANDOC_PATH 환경변수를 정의해도 된다.

export PANDOC_PATH="$HOME/.cabal/bin/pandoc"

Ruby에서의 사용은 String#pandoku 메서드를 통해 가능하다. (좀더 복잡한 방식이 있긴 하다.)

require 'pandoku'
result = document.pandoku(:markdown => :html)

This entry was posted on October 12, 2009 at 9:50 AM. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.

Powered by WordPress. Styled by Hong, MinHee. XML Feed, Comments XML Feed.