MacOS X 上的 HTML5 格式? (最好使用 TextMate)

发布于 2024-10-14 02:19:36 字数 58 浏览 10 评论 0原文

是否有适用于 MacOS X 且支持 HTML5 文档格式的编辑器或捆绑包?整理画布等新标签上的错误。

Are there any editors or bundles available for MacOS X that support formatting of HTML5 documents? Tidy errors out on newer tags like canvas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

独夜无伴 2024-10-21 02:19:36

这个问题讨论如何让 Tidy 与 HTML5 配合使用;调整 TextMate 包的命令行以使用这些参数应该可以。

This question talks about how to make Tidy work with HTML5; tweaking the TextMate bundle's command line to use these params should work.

逆流 2024-10-21 02:19:36

我设法使用此问题中找到的信息将 HTML5 Tidy 添加到 TextMate。 Tidy 似乎不接受自定义字符串作为 DocType,因此我使用 TextMate 宏来插入有效的字符串。可能有一种更优雅的方法来做到这一点,但它可以完成工作!

首先,我们需要为 Tidy 创建一个与 HTML5 兼容的 TextMate 命令。从“捆绑包”菜单访问“捆绑包编辑器”,然后创建一个包含以下内容的新命令:

#!/usr/bin/env ruby -wKU

require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'

result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \
          -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
          --indent yes \
          ${TM_XHTML:+-asxhtml --output-xhtml yes} \
          ${TM_SELECTED_TEXT:+--show-body-only yes} \
          --enclose-text yes \
          --doctype omit \
          --new-blocklevel-tags article,header,footer \
          --new-inline-tags video,audio,canvas,ruby,rt,rp \
          --break-before-br yes --vertical-space yes \
          --wrap-php no \
          --tidy-mark no`
status = $?.exitstatus

at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log

if status == 2 # Errors

  msg = "Errors: " + File.read('/tmp/tm_tidy_errors')
  TextMate.exit_show_tool_tip msg

elsif status == 1 # Warnings - use output but also display notification with warnings

  log = File.read('/tmp/tm_tidy_errors').to_a.select do |line|
    ! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing <!DOCTYPE> declaration') or line.include?("Warning: inserting missing 'title' element")))
  end.join rescue nil

  unless log.empty?
    options = {
      :title   => "Tidy Warnings",
      :summary => "Warnings for tidying your document (press escape to close):",
      :log     => log
    }
    TextMate::UI.simple_notification(options)
  end

end

if ENV['TM_SOFT_TABS'] == "YES"
  print result
else
  in_pre = false
  result.each_line do |line|
    unless in_pre
      tab_size = ENV["TM_TAB_SIZE"].to_i
      space, text = /( *)(.*)/m.match(line)[1..2]
      line = "\t" * (space.length / tab_size).floor + " "  * (space.length % tab_size) + text
    end

    print line

    in_pre = true  if line.include?("<pre>")
    in_pre = false if line.include?("</pre>")
  end
end

将此命令命名为“HTML5 Tidy”。将范围选择设置为“text.html”。我们稍后将设置键盘快捷键。请注意,“doctype”开关已设置为“omit”,这会完全删除 DocType 声明。

然后,您需要通过以下操作从“捆绑包”菜单中录制宏:

  • 选择刚刚创建的“HTML5 Tidy”命令
  • 按 CMD+向上键移至文档开头
  • 键入
  • 插入新行

选择“保存上次录制”菜单项来存储宏。将其命名为适当的名称,例如“HTML5 Tidy + DocType”,并将其范围设置为“text.html”。然后,您可以使用“等效键”输入为已完成的宏分配键盘快捷键。

这应该允许您在 HTML5 文档上使用 Tidy,不会出现任何问题。

I managed to add a HTML5 Tidy to TextMate by using the information found in this question. Tidy does not seem to accept a custom string as a DocType, so I used a TextMate macro to insert a valid one. There probably is a more elegant way of doing this, but it gets the job done!

To start off, we need to create a TextMate command for Tidy that plays nice with HTML5. Access the "Bundle Editor" from the Bundles menu, and create a new command containing the following:

#!/usr/bin/env ruby -wKU

require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'

result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \
          -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
          --indent yes \
          ${TM_XHTML:+-asxhtml --output-xhtml yes} \
          ${TM_SELECTED_TEXT:+--show-body-only yes} \
          --enclose-text yes \
          --doctype omit \
          --new-blocklevel-tags article,header,footer \
          --new-inline-tags video,audio,canvas,ruby,rt,rp \
          --break-before-br yes --vertical-space yes \
          --wrap-php no \
          --tidy-mark no`
status = $?.exitstatus

at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log

if status == 2 # Errors

  msg = "Errors: " + File.read('/tmp/tm_tidy_errors')
  TextMate.exit_show_tool_tip msg

elsif status == 1 # Warnings - use output but also display notification with warnings

  log = File.read('/tmp/tm_tidy_errors').to_a.select do |line|
    ! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing <!DOCTYPE> declaration') or line.include?("Warning: inserting missing 'title' element")))
  end.join rescue nil

  unless log.empty?
    options = {
      :title   => "Tidy Warnings",
      :summary => "Warnings for tidying your document (press escape to close):",
      :log     => log
    }
    TextMate::UI.simple_notification(options)
  end

end

if ENV['TM_SOFT_TABS'] == "YES"
  print result
else
  in_pre = false
  result.each_line do |line|
    unless in_pre
      tab_size = ENV["TM_TAB_SIZE"].to_i
      space, text = /( *)(.*)/m.match(line)[1..2]
      line = "\t" * (space.length / tab_size).floor + " "  * (space.length % tab_size) + text
    end

    print line

    in_pre = true  if line.include?("<pre>")
    in_pre = false if line.include?("</pre>")
  end
end

Name this command something along the lines of "HTML5 Tidy". Set the scope selection to "text.html". We'll set up a keyboard shortcut in a moment. Note that the "doctype" switch has been set to "omit", which removes the DocType declaration entirely.

You then need to record a macro from the Bundles menu with the following actions:

  • Selecting the "HTML5 Tidy" command you just created
  • Pressing CMD+Up to move to the beginning of the document
  • Typing <!DOCTYPE html>
  • Inserting a new line

Select the "Save Last Recording" menu item to store the macro. Name it something appropriate, such as "HTML5 Tidy + DocType", and set its scope to "text.html". You can then assign a keyboard shortcut for your completed macro using the "Key Equivalent" input.

This should allow you to use Tidy on your HTML5 documents without any problems.

清音悠歌 2024-10-21 02:19:36

Textmate 有一个捆绑包,可以根据 W3C 验证器进行验证 - http://validator.w3.org/

Textmate has a bundle that will validate against the W3C validator - http://validator.w3.org/

初熏 2024-10-21 02:19:36

我不得不说我对 TextMate 捆绑包并不熟悉,因为我个人不使用该编辑器。尽管如此,我发现他们有一个公共颠覆服务器,他们在其中保存不同的捆绑包。快速搜索没有发现任何 HTML5 捆绑包。您可以在其网站上找到有关捆绑包的更多信息。

如果您想要以开箱即用的方式在 HTML5 中创建 Web 内容,请查看 Aloha Editor

I have to say that I am not familiar with TextMate bundles because I do not personally use that editor. None the less, I found out that they have a public subversion server where they keep different bundles. A quick search did not reveal any HTML5 bundle. You can find more information about bundles on their website.

If you want an out of the box way of create web content in HTML5, have a look at Aloha Editor.

陌上青苔 2024-10-21 02:19:36

不关心 textmate 包,但是恐慌的尾声怎么样? www.panic.com/coda

Do not about textmate bundles, but how about coda from panic? www.panic.com/coda

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文