【问题标题】:Pretty Print HTML in Ruby (or Shell)Ruby(或Shell)中的漂亮打印HTML
【发布时间】:2011-03-23 11:42:04
【问题描述】:

有什么方法可以在 mac 上从命令行漂亮地打印 HTML 或 XML 字符串?尝试在 Ruby 中执行此操作。有任何想法吗?我曾考虑过 XSLT,以及编写我自己的解析器,但这两者都涉及很多。正在寻找已经存在的东西。

【问题讨论】:

    标签: html ruby xml unix pretty-print


    【解决方案1】:

    类似Tidy

    【讨论】:

      【解决方案2】:

      XML 文件

      xmllint --format file.xml

      HTML 文件

      xmllint --format --html file.html

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

      【讨论】:

      • @landon9720(抱歉格式错误)output = IO.popen("xmllint --format --html -", "w+") do |pipe| pipe.puts html pipe.close_write pipe.read end
      • 从标准输入读取,使用 - 作为文件名:xmllint --format -
      【解决方案3】:

      在 shell 中,另一种选择是使用不带参数的 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

      【讨论】:

        猜你喜欢
        • 2012-05-08
        • 1970-01-01
        • 1970-01-01
        • 2011-01-07
        • 2012-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-29
        相关资源
        最近更新 更多