首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MacOS X上的HTML5格式化?(最好使用TextMate)

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

Stack Overflow用户
提问于 2011-01-23 04:29:32
回答 6查看 2.8K关注 0票数 7

对于支持HTML5文档格式的MacOS X,有没有可用的编辑器或包?在像canvas这样的新标签上出现整洁的错误。

EN

Stack Overflow用户

发布于 2011-03-04 03:08:28

我设法使用在this question中找到的信息向TextMate添加了一个HTML5 Tidy。TextMate似乎不接受自定义字符串作为宏,所以我使用Tidy宏来插入一个有效的宏。可能有一种更优雅的方式来做这件事,但它可以完成这项工作!

首先,我们需要为Tidy创建一个与HTML5配合得很好的TextMate命令。从Bundles菜单访问"Bundle Editor“,并创建一个包含以下内容的新命令:

代码语言:javascript
运行
复制
#!/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声明。

然后,您需要使用以下操作从Bundles菜单录制宏:

新行选择“

  • ”命令you created
  • Pressing CMD+Up to created
  • Pressing to document
  • Typing <!DOCTYPE html>
  • Inserting to the of the document
    • Typing<!DOCTYPE html>
    • Inserting a CMD+Up

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

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

票数 2
EN
查看全部 6 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4770375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档