2014년 5월 14일 수요일

Pandoc을 사용해서 HTML로 렌더링된 Markdown 문서를 역으로 변환하기

요약

  • 사용할 프로그램: Pandoc
  • Ubuntu에서 Pandoc설치:
    $ sudo apt-get install pandoc
  • 사용법:
    $ pandoc -f입력포맷 -t출력포맷 입력파일 -o 출력파일
  • 예시:
    $ pandoc -fhtml -tmarkdown_github test.html -o test.md

이야기

이번에 블로그 글을 Atom 에디터의 Markdown 처리 기능을 이용해서 보기 좋은 HTML 문서로 재작성해보았는데, 원본 Markdown에서 HTML로 변환한 것을 블로그 글로 올리고 나서 원본이 없으면 나중에 다시 편집할 때 어떻게 할까 하는 생각을 하다가 Pandoc이 생각났다.

Pandoc

Pandoc은 마크업 문서간 변환 툴이다. 홈페이지에 나와있는 지원포맷 목록은 다음과 같으며 유용해보이는 포맷들은 글꼴 강조를 하였다.
  • HTML:
    XHTMLHTML5, and HTML slide shows using Slidy, reveal.js, Slideous, S5, or DZSlides.
  • Word processor:
    Microsoft Word docxOpenOffice/LibreOffice ODT,OpenDocument XML
  • Ebooks:
    EPUB version 2 or 3, FictionBook2
  • Documentation:
    DocBook, GNU TexInfo, Groff man pages, Haddock markup
  • Page layout:
    InDesign ICML
  • Outline:
    OPML
  • TeX:
    LaTeX, ConTeXt, LaTeX Beamer slides PDF via LaTeX
  • Lightweight markup:
    Markdown, reStructuredText, AsciiDoc, MediaWiki markup, Emacs Org-Mode, Textile
  • Custom:
    custom writers can be written in lua.

렌더링된 HTML로부터 Markdown 만들기

방법은 간단하다. 변환하려는 내용을 복사해서 HTML 파일로 저장하고 Pandoc을 사용해서 변환하면 된다. Ubuntu에서 pandoc을 설치하려면$ sudo apt-get install pandoc을 실행한다.
Pandoc의 명령어의 간략한 사용법은 이렇다.
$ pandoc -f입력포맷 -t출력포맷 입력파일 -o 출력파일
나는 HTML으로부터 Markdown(Github Flavored)을 만들고 싶기때문에 다음과 같이 실행하였다.
$ pandoc -fhtml -tmarkdown_github test.html -o test.md
실행해보니 변환이 대체로 잘 되는데, 렌더링된 HTML에 적용되어 있던 몇몇 스타일 정보들이 그대로 텍스트로 옮겨오는 문제가 있다. 주로multi-line code block들에서 이러한 문제가 발생한다. 이런 부분은 같은 스타일이 적용된 것을 텍스트 에디터에서 찾아바꾸기를 통해 바꾸어주면 된다. 해 보면 그리 오래 걸리지는 않는다.
이렇게 하면 원본에 거의 근접한 markdown 문서를 만들 수 있다.

댓글 1개:

  1. These typically contain an RFID chip that permits a printer to establish the filament type and properties but restricts the fabric to the manufacturer's appropriate printers. Make certain that a 3D printer's build space is large enough for the sort of objects that you intend to print with it. The build space is the size, in three dimensions, of the most important object that may a given printer can produce (at least in theory—it may be be} somewhat less if the build platform is not exactly level, for example). Typical 3D printers have build areas between 6 and 9 inches sq., but they'll range from quantity of} inches to more than two toes on a side, and a few are high precision machining actually sq.. In our critiques, we record printers' build areas in inches in peak, width, and depth . Among the things we search for in an entry-level 3D printer are a low price, ease of setup and use, largely problem-free operation, and strong print quality.

    답글삭제