LoginSignup
0
0

More than 5 years have passed since last update.

highlightの ERBなXMLのための プラグイン

Posted at

highlight というアプリで erbなXML/HTMLをハイライトするためのプラグイン。

文字列中の埋め込みrubyコード (<% ... %> で囲まれた部分) をハイライトする。HTMLの場合はjspコードとして誤解釈されないようにしている。

ただし属性値の埋め込み部分はハイライトできない (「効果」参照)。これは Stringsとして定義された部分 (HTML/XMLではダブルクォートで囲まれた部分) の処理が優先されるというHighlightの仕様によるもの。

xml_erb.lua
--[[
USAGE: highlight -I main.cpp --plug-in=xml_erb.lua
]]

Description="Add ERB blocks to XML keywords"

-- function to update language definition with ERB
-- optional parameter: syntax description
function syntaxUpdate(desc)
  if desc=="HTML" or desc=="XML" then
    -- insert <%...%> for Ruby
    table.insert( Keywords,
                  { Id=5, Regex=[[<\%.+?\%>]]
                   } )

    Strings={
       Delimiter=[["|']],
    }

    if desc=="HTML" then
       NestedSections = {
          { Lang="php", Delimiter= { [[<\?php]], [[\?>]] } },
          -- { Lang="jsp", Delimiter= { [[<\%[@!\=]?]], [[.*(%>).*]] } },
          { Lang="css", Delimiter= { [[<style\s+type\=[\'\"]text\/css[\'\"]>]], [[<\/style>]] } },
          { Lang="js", Delimiter= { [[<script>]], [[<\/script>]] } },
          { Lang="js", Delimiter= { [[<script\s+language\=\"[jJ]ava[sS]cript\"(?:\s+type\=\"text\/javascript\")?>]], [[<\/script>]] } },
          { Lang="js", Delimiter= { [[<script\s+language=[\"\'][jJ]ava[sS]cript[\"\'](?:\s+type=[\"\']text/javascript[\"\'])?[^>]*>]], [[<\/script>]] } },
          { Lang="js", Delimiter= { [[<script(?:\s+type=[\"\']text/javascript[\"\'])\s+language=[\"\'][jJ]ava[sS]cript[\"\']?[^>]*>]], [[<\/script>]] } },
          { Lang="js", Delimiter= { [[<script(?:\s+type=[\"\']text/javascript[\"\'])>]], [[<\/script>]] } },
       }       
    end
  end
end


-- function to update theme definition
-- optional parameter: theme description
function themeUpdate(desc)
  --add 5th keyword style for <%..%> defined in  syntaxUpdate()
   if #Keywords==4 then
     table.insert(Keywords, { Colour="#660000", Italic=true })
   end
end


--The Plugins array assigns code chunks to themes or language definitions.
--The chunks are interpreted after the theme or lang file were parsed,
--so you can refer to elements of these files

Plugins={

  { Type="theme", Chunk=themeUpdate },
  { Type="lang", Chunk=syntaxUpdate },

}

使用法

capture_highlight_tabs.JPG

  1. Highlight を起動。
  2. Plug-insタブの "Add plug-in to pool" にて上記の xml_erb.lua を選択。
  3. FilesタブもしくはClipboardタブからハイライトしたいソースコードを選択もしくはペースト
  4. Plug-insタブのpoolにて、 xml_erb.lua にチェックすればハイライトが適用される。

効果

使用前

capture_before.JPG

使用後

capture_after.JPG

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0