Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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

room661
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした