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
|
|
|
}
|
|
|
|
|
2019-03-13 06:24:33 +01:00
|
|
|
hook -once global BufSetOption filetype=(html|xml) %{
|
|
|
|
require-module html
|
|
|
|
}
|
|
|
|
|
|
|
|
provide-module html %[
|
|
|
|
|
|
|
|
try %{
|
|
|
|
require-module css
|
|
|
|
require-module javascript
|
|
|
|
}
|
|
|
|
|
2014-07-14 22:58:40 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-06-28 14:10:22 +02:00
|
|
|
add-highlighter shared/html regions
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/html/comment region <!-- --> fill comment
|
|
|
|
add-highlighter shared/html/tag region < > regions
|
|
|
|
add-highlighter shared/html/style region <style\b.*?>\K (?=</style>) ref css
|
|
|
|
add-highlighter shared/html/script region <script\b.*?>\K (?=</script>) ref javascript
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2018-06-28 14:10:22 +02:00
|
|
|
add-highlighter shared/html/tag/base default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/html/tag/ region '"' (?<!\\)(\\\\)*" fill string
|
|
|
|
add-highlighter shared/html/tag/ region "'" "'" fill string
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2018-06-28 14:10:22 +02:00
|
|
|
add-highlighter shared/html/tag/base/ regex \b([a-zA-Z0-9_-]+)=? 1:attribute
|
|
|
|
add-highlighter shared/html/tag/base/ regex </?(\w+) 1:keyword
|
|
|
|
add-highlighter shared/html/tag/base/ regex <(!DOCTYPE(\h+\w+)+) 1:meta
|
2014-07-14 22:58:40 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden html-trim-indent %{
|
2015-11-04 10:48:47 +01:00
|
|
|
# remove trailing white spaces
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -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-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %[
|
2014-07-14 22:58:40 +02:00
|
|
|
# align closing tag to opening when alone on a line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %[ execute-keys -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-&> ]
|
2017-10-30 06:52:07 +01:00
|
|
|
]
|
|
|
|
]
|
2014-07-14 22:58:40 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden html-indent-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2014-07-14 22:58:40 +02:00
|
|
|
# preserve previous line indent
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
2014-07-14 22:58:40 +02:00
|
|
|
# filter previous line
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : html-trim-indent <ret> }
|
2014-07-14 22:58:40 +02:00
|
|
|
# indent after lines ending with opening tag
|
2018-09-24 02:41:08 +02:00
|
|
|
try %{ execute-keys -draft k <a-x> <a-k> <lt>(?!area)(?!base)(?!br)(?!col)(?!command)(?!embed)(?!hr)(?!img)(?!input)(?!keygen)(?!link)(?!menuitem)(?!meta)(?!param)(?!source)(?!track)(?!wbr)(?!/)(?!>)[a-zA-Z0-9_-]+[^>]*?>$ <ret> j <a-gt> } }
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-11-28 10:39:15 +01:00
|
|
|
hook -group html-highlight global WinSetOption filetype=(html|xml) %{
|
|
|
|
add-highlighter "window/%val{hook_param_capture_1}" ref html
|
2018-12-11 00:11:35 +01:00
|
|
|
hook -once -always window WinSetOption "filetype=.*" "
|
2018-11-28 10:39:15 +01:00
|
|
|
remove-highlighter ""window/%val{hook_param_capture_1}""
|
|
|
|
"
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 10:39:15 +01:00
|
|
|
hook global WinSetOption filetype=(html|xml) %{
|
2018-12-19 10:10:26 +01:00
|
|
|
hook window ModeChange insert:.* -group "%val{hook_param_capture_1}-trim-indent" html-trim-indent
|
2018-11-28 10:39:15 +01:00
|
|
|
hook window InsertChar '>' -group "%val{hook_param_capture_1}-indent" html-indent-on-greater-than
|
|
|
|
hook window InsertChar \n -group "%val{hook_param_capture_1}-indent" html-indent-on-new-line
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2018-12-11 00:11:35 +01:00
|
|
|
hook -once -always window WinSetOption "filetype=.*" "
|
2018-11-28 10:39:15 +01:00
|
|
|
remove-hooks window ""%val{hook_param_capture_1}-.+""
|
|
|
|
"
|
2014-07-14 22:58:40 +02:00
|
|
|
}
|
2019-03-13 06:24:33 +01:00
|
|
|
|
|
|
|
]
|