forked from VimPlug/emmet-vim
support 'a[href=http://www.google.com]{Google}'
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
" File: zencoding.vim
|
" File: zencoding.vim
|
||||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||||
" Last Change: 19-Feb-2010.
|
" Last Change: 19-Feb-2010.
|
||||||
" Version: 0.7
|
" Version: 0.8
|
||||||
" WebPage: http://github.com/mattn/zencoding-vim
|
" WebPage: http://github.com/mattn/zencoding-vim
|
||||||
" Description: vim plugins for HTML and CSS hi-speed coding.
|
" Description: vim plugins for HTML and CSS hi-speed coding.
|
||||||
" SeeAlso: http://code.google.com/p/zen-coding/
|
" SeeAlso: http://code.google.com/p/zen-coding/
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
" script type: plugin
|
" script type: plugin
|
||||||
|
|
||||||
if &cp || (exists('g:loaded_zencoding_vim') && g:loaded_zencoding_vim)
|
if &cp || (exists('g:loaded_zencoding_vim') && g:loaded_zencoding_vim)
|
||||||
finish
|
"finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_zencoding_vim = 1
|
let g:loaded_zencoding_vim = 1
|
||||||
|
|
||||||
@@ -798,9 +798,10 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
" TODO : expandos
|
" TODO : expandos
|
||||||
let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)\+$', '\=s:zen_expandos(submatch(1), type)', 'i')
|
let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)\+$', '\=s:zen_expandos(submatch(1), type)', 'i')
|
||||||
|
|
||||||
let mx = '\([\+>]\)\{-}\(@\{-}[a-z][a-z0-9:\!\-]*\)\(#[0-9A-Za-z_\-\$]\+\)\{0,1}\(\%(\.[0-9A-Za-z_\-\$]\+\)*\)\%(\*\([0-9]\+\)\)\{0,1}'
|
let mx = '\([\+>]\|<\+\)\{-}\(@\{-}[a-z][a-z0-9:\!\-]*\)\(#[0-9A-Za-z_\-\$]\+\)\{0,1}\(\%(\[[^\]]\+\]\)*\)\(\%(\.[0-9A-Za-z_\-\$]\+\)*\)\({[^}]\+}\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}'
|
||||||
let last = {}
|
let last = {}
|
||||||
let parent = { 'name': '', 'attr': [], 'child': [], 'snippet': '', 'multiplier': 1 }
|
let parent = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '' }
|
||||||
|
let granma = parent
|
||||||
let root = parent
|
let root = parent
|
||||||
while len(abbr)
|
while len(abbr)
|
||||||
let match = matchstr(abbr, mx)
|
let match = matchstr(abbr, mx)
|
||||||
@@ -808,8 +809,10 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
let operator = substitute(match, mx, '\1', 'ig')
|
let operator = substitute(match, mx, '\1', 'ig')
|
||||||
let tag_name = substitute(match, mx, '\2', 'ig')
|
let tag_name = substitute(match, mx, '\2', 'ig')
|
||||||
let id = substitute(match, mx, '\3', 'ig')
|
let id = substitute(match, mx, '\3', 'ig')
|
||||||
let class_name = substitute(match, mx, '\4', 'ig')
|
let attr = substitute(match, mx, '\4', 'ig')
|
||||||
let multiplier = 0 + substitute(match, mx, '\5', 'ig')
|
let class_name = substitute(match, mx, '\5', 'ig')
|
||||||
|
let value = substitute(match, mx, '\6', 'ig')
|
||||||
|
let multiplier = 0 + substitute(match, mx, '\7', 'ig')
|
||||||
if multiplier <= 0
|
if multiplier <= 0
|
||||||
let multiplier = 1
|
let multiplier = 1
|
||||||
endif
|
endif
|
||||||
@@ -818,7 +821,7 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
let tag_name = s:zen_settings[type]['aliases'][tag_name]
|
let tag_name = s:zen_settings[type]['aliases'][tag_name]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let current = { 'name': '', 'attr':[], 'child': [], 'snippet': '', 'multiplier': 1 }
|
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '' }
|
||||||
if has_key(s:zen_settings[type]['snippets'], tag_name)
|
if has_key(s:zen_settings[type]['snippets'], tag_name)
|
||||||
let current['snippet'] = s:zen_settings[type]['snippets'][tag_name]
|
let current['snippet'] = s:zen_settings[type]['snippets'][tag_name]
|
||||||
else
|
else
|
||||||
@@ -829,12 +832,12 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
if type(default_attributes[tag_name]) == 4
|
if type(default_attributes[tag_name]) == 4
|
||||||
let a = default_attributes[tag_name]
|
let a = default_attributes[tag_name]
|
||||||
for k in keys(a)
|
for k in keys(a)
|
||||||
call add(current['attr'], {'name': k, 'value': a[k]})
|
let current['attr'][k] = a[k]
|
||||||
endfor
|
endfor
|
||||||
else
|
else
|
||||||
for a in default_attributes[tag_name]
|
for a in default_attributes[tag_name]
|
||||||
for k in keys(a)
|
for k in keys(a)
|
||||||
call add(current['attr'], {'name': k, 'value': a[k]})
|
let current['attr'][k] = a[k]
|
||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
@@ -842,15 +845,36 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if len(id)
|
if len(id)
|
||||||
call add(current['attr'], {'name': 'id', 'value': id[1:]})
|
let current['attr']['id'] = id[1:]
|
||||||
endif
|
endif
|
||||||
if len(class_name)
|
if len(class_name)
|
||||||
call add(current['attr'], {'name': 'class', 'value': class_name[1:]})
|
let current['attr']['class'] = class_name[1:]
|
||||||
endif
|
endif
|
||||||
|
if len(attr)
|
||||||
|
let attrs = split(attr, '\[\|\]\[\|\]')
|
||||||
|
unlet! aa
|
||||||
|
unlet! ka
|
||||||
|
for aa in attrs
|
||||||
|
let kk = split(aa, '=')
|
||||||
|
let current['attr'][kk[0]] = len(kk) > 1 ? join(kk[1:], '=') : ''
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
let current['value'] = value
|
||||||
let current['multiplier'] = multiplier
|
let current['multiplier'] = multiplier
|
||||||
if operator == '>' && !empty(last)
|
if operator == '>' && !empty(last)
|
||||||
|
let tmp = parent
|
||||||
unlet! parent
|
unlet! parent
|
||||||
let parent = last
|
let parent = last
|
||||||
|
let parent['parent'] = tmp
|
||||||
|
endif
|
||||||
|
if operator =~ '<'
|
||||||
|
for c in split(operator, '\zs')
|
||||||
|
let tmp = parent['parent']
|
||||||
|
if empty(tmp)
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let parent = tmp
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
call add(parent['child'], current)
|
call add(parent['child'], current)
|
||||||
let last = current
|
let last = current
|
||||||
@@ -858,8 +882,10 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
echo "str=".str
|
echo "str=".str
|
||||||
echo "operator=".operator
|
echo "operator=".operator
|
||||||
echo "tag_name=".tag_name
|
echo "tag_name=".tag_name
|
||||||
echo "class_name=".class_name
|
|
||||||
echo "id=".id
|
echo "id=".id
|
||||||
|
echo "class_name=".class_name
|
||||||
|
echo "attr=".attr
|
||||||
|
echo "value=".value
|
||||||
echo "multiplier=".multiplier
|
echo "multiplier=".multiplier
|
||||||
echo "\n"
|
echo "\n"
|
||||||
endif
|
endif
|
||||||
@@ -886,21 +912,18 @@ function! s:zen_toString(...)
|
|||||||
while m <= current['multiplier']
|
while m <= current['multiplier']
|
||||||
if len(current['name']) && type == 'html'
|
if len(current['name']) && type == 'html'
|
||||||
let str .= '<' . current['name']
|
let str .= '<' . current['name']
|
||||||
let n = 0
|
for attr in keys(current['attr'])
|
||||||
while n < len(current['attr'])
|
if current['multiplier'] > 1 && current['attr'][attr] =~ '\$$'
|
||||||
let attr = current['attr'][n]
|
let str .= ' ' . attr . '="' . current['attr'][attr][:-2] . m . '"'
|
||||||
if current['multiplier'] > 1 && attr['value'] =~ '\$$'
|
|
||||||
let str .= ' ' . attr['name'] . '="' . attr['value'][:-2] . m . '"'
|
|
||||||
else
|
else
|
||||||
let str .= ' ' . attr['name'] . '="' . attr['value'] . '"'
|
let str .= ' ' . attr . '="' . current['attr'][attr] . '"'
|
||||||
endif
|
endif
|
||||||
let n = n + 1
|
endfor
|
||||||
endwhile
|
let inner = current['value'][1:-2]
|
||||||
let inner = ''
|
|
||||||
for child in current['child']
|
for child in current['child']
|
||||||
let inner .= s:zen_toString(child, type)
|
let inner .= s:zen_toString(child, type)
|
||||||
endfor
|
endfor
|
||||||
if len(inner)
|
if len(current['child'])
|
||||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||||
let inner = substitute(inner, indent . "$", "", 'g')
|
let inner = substitute(inner, indent . "$", "", 'g')
|
||||||
let str .= ">\n" . indent . inner . "</" . current['name'] . ">\n"
|
let str .= ">\n" . indent . inner . "</" . current['name'] . ">\n"
|
||||||
@@ -909,9 +932,9 @@ function! s:zen_toString(...)
|
|||||||
let str .= " />\n"
|
let str .= " />\n"
|
||||||
else
|
else
|
||||||
if stridx(','.s:zen_settings[type]['block_elements'].',', ','.current['name'].',') != -1 && len(current['child'])
|
if stridx(','.s:zen_settings[type]['block_elements'].',', ','.current['name'].',') != -1 && len(current['child'])
|
||||||
let str .= ">\n|</" . current['name'] . ">\n"
|
let str .= ">\n" . inner . "|</" . current['name'] . ">\n"
|
||||||
else
|
else
|
||||||
let str .= ">|</" . current['name'] . ">\n"
|
let str .= ">" . inner . "|</" . current['name'] . ">\n"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -1017,5 +1040,9 @@ endif
|
|||||||
"echo ZenExpand('html:4t>div#wrapper>div#header+div#contents+div#footer', '')
|
"echo ZenExpand('html:4t>div#wrapper>div#header+div#contents+div#footer', '')
|
||||||
"echo ZenExpand('a[href=http://www.google.com/].foo#hoge', '')
|
"echo ZenExpand('a[href=http://www.google.com/].foo#hoge', '')
|
||||||
"echo ZenExpand('a+b', '')
|
"echo ZenExpand('a+b', '')
|
||||||
|
"echo ZenExpand('a>b>c<d', '')
|
||||||
|
"echo ZenExpand('a>b>c<<d', '')
|
||||||
|
"echo ZenExpand('a[href=foo][class=bar]', '')
|
||||||
|
"echo ZenExpand('a[a=b][b=c=d][e]{foo}*2', '')
|
||||||
|
|
||||||
" vim:set et:
|
" vim:set et:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ script_name: ZenCoding.vim
|
|||||||
script_id: '2981'
|
script_id: '2981'
|
||||||
script_type: utility
|
script_type: utility
|
||||||
script_package: zencoding.vim
|
script_package: zencoding.vim
|
||||||
script_version: '0.7'
|
script_version: '0.8'
|
||||||
required_vim_version: '7.0'
|
required_vim_version: '7.0'
|
||||||
summary: vim plugins for HTML and CSS hi-speed coding.
|
summary: vim plugins for HTML and CSS hi-speed coding.
|
||||||
|
|
||||||
@@ -67,6 +67,8 @@ install_details: |
|
|||||||
copy zencoding.vim to your plugin directory.
|
copy zencoding.vim to your plugin directory.
|
||||||
|
|
||||||
versions:
|
versions:
|
||||||
|
- '0.8': |
|
||||||
|
This is an upgrade for ZenCoding.vim: support 'a[href=http://www.google.com]{Google}'
|
||||||
- '0.7': |
|
- '0.7': |
|
||||||
This is an upgrade for ZenCoding.vim: fixed behavior in 'a+b'.
|
This is an upgrade for ZenCoding.vim: fixed behavior in 'a+b'.
|
||||||
- '0.6': |
|
- '0.6': |
|
||||||
|
|||||||
Reference in New Issue
Block a user