2014-07-14 22:58:40 +02:00
|
|
|
# http://w3.org/html
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-12-14 14:40:00 +01:00
|
|
|
hook global BufCreate .*\.html %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype html
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
|
2016-12-14 14:40:00 +01:00
|
|
|
hook global BufCreate .*\.xml %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype xml
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/ regions html \
|
2014-07-14 22:58:40 +02:00
|
|
|
comment <!-- --> '' \
|
|
|
|
tag < > '' \
|
2016-04-21 21:43:17 +02:00
|
|
|
style <style\b.*?>\K (?=</style>) '' \
|
|
|
|
script <script\b.*?>\K (?=</script>) ''
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/html/comment fill comment
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/html/style ref css
|
|
|
|
add-highlighter shared/html/script ref javascript
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/html/tag regex \b([a-zA-Z0-9_-]+)=? 1:attribute
|
|
|
|
add-highlighter shared/html/tag regex </?(\w+) 1:keyword
|
|
|
|
add-highlighter shared/html/tag regex <(!DOCTYPE(\h+\w+)+) 1:meta
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/html/tag regions content \
|
2014-07-14 22:58:40 +02:00
|
|
|
string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
string "'" "'" ''
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/html/tag/content/string fill string
|
2014-07-14 22:58:40 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden html-filter-around-selections %{
|
2015-11-04 10:48:47 +01:00
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden html-indent-on-greater-than %[
|
2017-10-30 06:52:07 +01:00
|
|
|
eval -draft -itersel %[
|
2014-07-14 22:58:40 +02:00
|
|
|
# align closing tag to opening when alone on a line
|
2017-10-30 06:52:07 +01:00
|
|
|
try %[ exec -draft <space> <a-h> s ^\h+<lt>/(\w+)<gt>$ <ret> {c<lt><c-r>1,<lt>/<c-r>1<gt> <ret> s \A|.\z <ret> 1<a-&> ]
|
|
|
|
]
|
|
|
|
]
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden html-indent-on-new-line %{
|
2014-07-14 22:58:40 +02:00
|
|
|
eval -draft -itersel %{
|
|
|
|
# preserve previous line indent
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft \; K <a-&> }
|
2014-07-14 22:58:40 +02:00
|
|
|
# filter previous line
|
2017-01-13 01:56:30 +01:00
|
|
|
try %{ exec -draft k : html-filter-around-selections <ret> }
|
2014-07-14 22:58:40 +02:00
|
|
|
# indent after lines ending with opening tag
|
2017-01-13 01:50:03 +01:00
|
|
|
try %{ exec -draft k <a-x> <a-k> <[^/][^>]+>$ <ret> j <a-gt> }
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group html-highlight global WinSetOption filetype=(?:html|xml) %{ add-highlighter window ref html }
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2016-12-14 14:40:00 +01:00
|
|
|
hook global WinSetOption filetype=(?:html|xml) %{
|
2017-01-13 01:56:30 +01:00
|
|
|
hook window InsertEnd .* -group html-hooks html-filter-around-selections
|
2017-10-30 06:52:07 +01:00
|
|
|
hook window InsertChar '>' -group html-indent html-indent-on-greater-than
|
2017-01-13 01:56:30 +01:00
|
|
|
hook window InsertChar \n -group html-indent html-indent-on-new-line
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group html-highlight global WinSetOption filetype=(?!html)(?!xml).* %{ remove-highlighter window/html }
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2017-10-02 14:59:22 +02:00
|
|
|
hook global WinSetOption filetype=(?!html)(?!xml).* %{
|
2017-01-04 01:07:45 +01:00
|
|
|
remove-hooks window html-indent
|
|
|
|
remove-hooks window html-hooks
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|