2010-07-30 3 views
2

Mac의 명령 행에서 HTML 또는 XML 문자열을 출력하는 방법이 있습니까? 루비에서이 작업을하려고합니다. 어떤 아이디어? 나는 XSLT와 내 파서를 작성하는 것에 대해 생각해 봤지만 두 가지 모두 꽤 복잡하다. 이미 저기있는 것을 찾고 있어요.예쁜 인쇄 HTML을 루비 (또는 쉘)

답변

5

XML 파일

xmllint가 file.xml --format

HTML 파일

xmllint가 --format --html file.html과

쉘에서

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/xmllint.1.html

+1

어떻게 표준 입력에서 읽습니까? –

+0

@ landon9720 (잘못된 형식으로 유감입니다.) 'output = IO.popen ("xmllint --format --html -", "w +") do | pipe | pipe.puts html pipe.close_write pipe.read end' – Stoffe

+0

stdin에서 읽으려면 - 파일 이름으로 사용 : xmllint --format - –

0

또 다른 옵션은 인수없이 pup을 사용하는 것입니다

pup 

XmlStarlet 또한 HTML 파서를 사용하여 지원합니다. foformat의 약어입니다. 도움을 받으려면 xml fo -h을 참조하십시오.

xml fo --html 

tidy의 주요 구현은 HTML5를 지원하지 않지만 tidy-html5는 않습니다. brew install tidy-html5은 OS X에 tidy-html5/usr/local/bin/tidy으로 설치합니다.