Skip to content

Commit

Permalink
implementing proper html5 syntax checking (,5 mapping)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Host committed Nov 27, 2011
1 parent 35732df commit 39cb951
Show file tree
Hide file tree
Showing 37 changed files with 339 additions and 1 deletion.
99 changes: 99 additions & 0 deletions .gitmodules
@@ -0,0 +1,99 @@
[submodule "bundle/vim-pathogen"]
path = bundle/vim-pathogen
url = https://github.com/tpope/vim-pathogen.git
[submodule "bundle/tartify"]
path = bundle/tartify
url = git://github.com/peterhost/tartify.git
[submodule "bundle/vim-fugitive"]
path = bundle/vim-fugitive
url = git://github.com/tpope/vim-fugitive.git
[submodule "bundle/vim-git-branch-info"]
path = bundle/vim-git-branch-info
url = git://github.com/taq/vim-git-branch-info.git
[submodule "bundle/jshint.vim"]
path = bundle/jshint.vim
url = git://github.com/wookiehangover/jshint.vim.git
[submodule "bundle/csapprox"]
path = bundle/csapprox
url = git://github.com/godlygeek/csapprox.git
[submodule "bundle/vim-bufexplorer"]
path = bundle/vim-bufexplorer
url = git://github.com/slack/vim-bufexplorer.git
[submodule "bundle/LustyJuggler"]
path = bundle/LustyJuggler
url = git://github.com/vim-scripts/LustyJuggler.git
[submodule "bundle/syntastic"]
path = bundle/syntastic
url = git://github.com/scrooloose/syntastic.git
[submodule "bundle/vim-matchit"]
path = bundle/vim-matchit
url = git://github.com/mhz/vim-matchit.git
[submodule "bundle/nerdcommenter"]
path = bundle/nerdcommenter
url = git://github.com/scrooloose/nerdcommenter.git
[submodule "bundle/vim-markdown"]
path = bundle/vim-markdown
url = git://github.com/plasticboy/vim-markdown.git
[submodule "bundle/vim-surround"]
path = bundle/vim-surround
url = git://github.com/tpope/vim-surround.git
[submodule "bundle/repeat.vim"]
path = bundle/repeat.vim
url = git://github.com/vim-scripts/repeat.vim.git
[submodule "bundle/vim-css-color"]
path = bundle/vim-css-color
url = git://github.com/skammer/vim-css-color.git
[submodule "bundle/vim-javascript"]
path = bundle/vim-javascript
url = git://github.com/pangloss/vim-javascript.git
[submodule "bundle/YankRing.vim"]
path = bundle/YankRing.vim
url = git://github.com/vim-scripts/YankRing.vim.git
[submodule "bundle/session.vim--Odding"]
path = bundle/session.vim--Odding
url = git://github.com/vim-scripts/session.vim--Odding.git
[submodule "bundle/vim-colors-solarized"]
path = bundle/vim-colors-solarized
url = git://github.com/altercation/vim-colors-solarized.git
[submodule "bundle/vim-bclose"]
path = bundle/vim-bclose
url = git://github.com/cespare/vim-bclose.git
[submodule "bundle/Decho"]
path = bundle/Decho
url = git://github.com/vim-scripts/Decho.git
[submodule "bundle/vim-unimpaired"]
path = bundle/vim-unimpaired
url = git://github.com/tpope/vim-unimpaired.git
[submodule "bundle/vim-git"]
path = bundle/vim-git
url = git://github.com/tpope/vim-git.git
[submodule "bundle/scss-syntax.vim"]
path = bundle/scss-syntax.vim
url = git://github.com/cakebaker/scss-syntax.vim.git
[submodule "bundle/html5-syntax.vim"]
path = bundle/html5-syntax.vim
url = git://github.com/othree/html5-syntax.vim.git
[submodule "bundle/L9"]
path = bundle/L9
url = git://github.com/vim-scripts/L9.git
[submodule "bundle/FuzzyFinder"]
path = bundle/FuzzyFinder
url = git://github.com/vim-scripts/FuzzyFinder.git
[submodule "bundle/PreciseJump"]
path = bundle/PreciseJump
url = git@github.com:peterhost/PreciseJump.git
[submodule "bundle/neocomplcache"]
path = bundle/neocomplcache
url = git://github.com/Shougo/neocomplcache.git
[submodule "bundle/SearchComplete"]
path = bundle/SearchComplete
url = git://github.com/vim-scripts/SearchComplete.git
[submodule "bundle/vim-markdown-preview"]
path = bundle/vim-markdown-preview
url = git://github.com/peterhost/vim-markdown-preview.git
[submodule "bundle/vim-taglist-plus"]
path = bundle/vim-taglist-plus
url = git://github.com/int3/vim-taglist-plus.git
[submodule "bundle/snipMate"]
path = bundle/snipMate
url = git://github.com/vim-scripts/snipMate.git
15 changes: 14 additions & 1 deletion bin/bootstrap
Expand Up @@ -30,5 +30,18 @@ if ! which node >/dev/null 2>&1 || ! which jsctags >/dev/null 2>&1 ;then
echo " echo "
WARN : either node.js or jsctags (jsdoctor) seems to be missing on your WARN : either node.js or jsctags (jsdoctor) seems to be missing on your
system. vim-taglist-plus will use CTAGS instead of JSCTAGS for js system. vim-taglist-plus will use CTAGS instead of JSCTAGS for js
(https://github.com/pcwalton/doctorjs.git)" (https://github.com/pcwalton/doctorjs.git)
"
fi


if ! which html5check >/dev/null 2>&1 ;then
echo "
WARN : html5check is not in your path, do:
ln -s ~/.vim/lib/html5check /usr/local/bin/html5check
so that you can use the ",5" mapping to properly validate
HTML5 files (syntastic's based on tidy and is broken)
"
fi fi
1 change: 1 addition & 0 deletions bundle/Decho
Submodule Decho added at 3a55ac
1 change: 1 addition & 0 deletions bundle/FuzzyFinder
Submodule FuzzyFinder added at b9f165
1 change: 1 addition & 0 deletions bundle/L9
Submodule L9 added at c822b0
1 change: 1 addition & 0 deletions bundle/LustyJuggler
Submodule LustyJuggler added at 6722d3
1 change: 1 addition & 0 deletions bundle/PreciseJump
Submodule PreciseJump added at 72bc53
1 change: 1 addition & 0 deletions bundle/SearchComplete
Submodule SearchComplete added at d85ccf
1 change: 1 addition & 0 deletions bundle/YankRing.vim
Submodule YankRing.vim added at 280ca1
1 change: 1 addition & 0 deletions bundle/csapprox
Submodule csapprox added at f98bf4
1 change: 1 addition & 0 deletions bundle/html5-syntax.vim
Submodule html5-syntax.vim added at 2f82fc
1 change: 1 addition & 0 deletions bundle/jshint.vim
Submodule jshint.vim added at dd2e24
1 change: 1 addition & 0 deletions bundle/neocomplcache
Submodule neocomplcache added at d847ce
1 change: 1 addition & 0 deletions bundle/nerdcommenter
Submodule nerdcommenter added at b28e7b
1 change: 1 addition & 0 deletions bundle/repeat.vim
Submodule repeat.vim added at 6336f3
1 change: 1 addition & 0 deletions bundle/scss-syntax.vim
Submodule scss-syntax.vim added at d4016f
1 change: 1 addition & 0 deletions bundle/session.vim--Odding
Submodule session.vim--Odding added at d99521
1 change: 1 addition & 0 deletions bundle/snipMate
Submodule snipMate added at 018e0d
1 change: 1 addition & 0 deletions bundle/syntastic
Submodule syntastic added at 3c2674
1 change: 1 addition & 0 deletions bundle/tartify
Submodule tartify added at 08170d
1 change: 1 addition & 0 deletions bundle/vim-bclose
Submodule vim-bclose added at b93bc4
1 change: 1 addition & 0 deletions bundle/vim-bufexplorer
Submodule vim-bufexplorer added at 3af553
1 change: 1 addition & 0 deletions bundle/vim-colors-solarized
Submodule vim-colors-solarized added at 528a59
1 change: 1 addition & 0 deletions bundle/vim-css-color
Submodule vim-css-color added at 417eaf
1 change: 1 addition & 0 deletions bundle/vim-fugitive
Submodule vim-fugitive added at 1b7e40
1 change: 1 addition & 0 deletions bundle/vim-git
Submodule vim-git added at 0a0d79
1 change: 1 addition & 0 deletions bundle/vim-git-branch-info
Submodule vim-git-branch-info added at fc4313
1 change: 1 addition & 0 deletions bundle/vim-javascript
Submodule vim-javascript added at 9990a7
1 change: 1 addition & 0 deletions bundle/vim-markdown
Submodule vim-markdown added at f3f96f
1 change: 1 addition & 0 deletions bundle/vim-markdown-preview
Submodule vim-markdown-preview added at b0842f
1 change: 1 addition & 0 deletions bundle/vim-matchit
Submodule vim-matchit added at 67cc55
1 change: 1 addition & 0 deletions bundle/vim-pathogen
Submodule vim-pathogen added at ab64b4
1 change: 1 addition & 0 deletions bundle/vim-surround
Submodule vim-surround added at 4eb2cd
1 change: 1 addition & 0 deletions bundle/vim-taglist-plus
Submodule vim-taglist-plus added at fc9f1c
1 change: 1 addition & 0 deletions bundle/vim-unimpaired
Submodule vim-unimpaired added at 440629
186 changes: 186 additions & 0 deletions lib/html5check
@@ -0,0 +1,186 @@
#!/usr/bin/python

# Copyright (c) 2007-2008 Mozilla Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

import httplib
import os
import sys
import re
import urlparse
import string
import gzip
import StringIO

extPat = re.compile(r'^.*\.([A-Za-z]+)$')
extDict = {
"html" : "text/html",
"htm" : "text/html",
"xhtml" : "application/xhtml+xml",
"xht" : "application/xhtml+xml",
"xml" : "application/xml",
}

argv = sys.argv[1:]

forceXml = 0
forceHtml = 0
gnu = 0
errorsOnly = 0
encoding = None
fileName = None
contentType = None
inputHandle = None
service = 'http://html5.validator.nu/'

for arg in argv:
if '--help' == arg:
print '-h : force text/html'
print '-x : force application/xhtml+xml'
print '-g : GNU output'
print '-e : errors only (no info or warnings)'
print '--encoding=foo : declare encoding foo'
print '--service=url : the address of the HTML5 validator'
print 'One file argument allowed. Leave out to read from stdin.'
sys.exit(0)
elif arg.startswith("--encoding="):
encoding = arg[11:]
elif arg.startswith("--service="):
service = arg[10:]
elif arg.startswith("--"):
sys.stderr.write('Unknown argument %s.\n' % arg)
sys.exit(2)
elif arg.startswith("-"):
for c in arg[1:]:
if 'x' == c:
forceXml = 1
elif 'h' == c:
forceHtml = 1
elif 'g' == c:
gnu = 1
elif 'e' == c:
errorsOnly = 1
else:
sys.stderr.write('Unknown argument %s.\n' % arg)
sys.exit(3)
else:
if fileName:
sys.stderr.write('Cannot have more than one input file.\n')
sys.exit(1)
fileName = arg

if forceXml and forceHtml:
sys.stderr.write('Cannot force HTML and XHTML at the same time.\n')
sys.exit(2)

if forceXml:
contentType = 'application/xhtml+xml'
elif forceHtml:
contentType = 'text/html'
elif fileName:
m = extPat.match(fileName)
if m:
ext = m.group(1)
ext = ext.translate(string.maketrans(string.ascii_uppercase, string.ascii_lowercase))
if extDict.has_key(ext):
contentType = extDict[ext]
else:
sys.stderr.write('Unable to guess Content-Type from file name. Please force the type.\n')
sys.exit(3)
else:
sys.stderr.write('Could not extract a filename extension. Please force the type.\n')
sys.exit(6)
else:
sys.stderr.write('Need to force HTML or XHTML when reading from stdin.\n')
sys.exit(4)

if encoding:
contentType = '%s; charset=%s' % (contentType, encoding)

if fileName:
inputHandle = open(fileName, "rb")
else:
inputHandle = sys.stdin

data = inputHandle.read()

buf = StringIO.StringIO()
gzipper = gzip.GzipFile(fileobj=buf, mode='wb')
gzipper.write(data)
gzipper.close()
gzippeddata = buf.getvalue()
buf.close()

connection = None
response = None
status = 302
redirectCount = 0

url = service
if gnu:
url = url + '?out=gnu'
else:
url = url + '?out=text'

if errorsOnly:
url = url + '&level=error'

while (status == 302 or status == 301 or status == 307) and redirectCount < 10:
if redirectCount > 0:
url = response.getheader('Location')
parsed = urlparse.urlsplit(url)
if parsed[0] != 'http':
sys.stderr.write('URI scheme %s not supported.\n' % parsed[0])
sys.exit(7)
if redirectCount > 0:
connection.close() # previous connection
print 'Redirecting to %s' % url
print 'Please press enter to continue or type "stop" followed by enter to stop.'
if raw_input() != "":
sys.exit(0)
connection = httplib.HTTPConnection(parsed[1])
connection.connect()
connection.putrequest("POST", "%s?%s" % (parsed[2], parsed[3]), skip_accept_encoding=1)
connection.putheader("Accept-Encoding", 'gzip')
connection.putheader("Content-Type", contentType)
connection.putheader("Content-Encoding", 'gzip')
connection.putheader("Content-Length", len(gzippeddata))
connection.endheaders()
connection.send(gzippeddata)
response = connection.getresponse()
status = response.status
redirectCount += 1

if status != 200:
sys.stderr.write('%s %s\n' % (status, response.reason))
sys.exit(5)

if response.getheader('Content-Encoding', 'identity').lower() == 'gzip':
response = gzip.GzipFile(fileobj=StringIO.StringIO(response.read()))

if fileName and gnu:
quotedName = '"%s"' % fileName.replace('"', '\\042')
for line in response:
sys.stdout.write(quotedName)
sys.stdout.write(line)
else:
sys.stdout.write(response.read())

connection.close()
7 changes: 7 additions & 0 deletions vimrc
Expand Up @@ -781,6 +781,8 @@ let g:CommandTMaxHeight=20
let g:syntastic_auto_loc_list=2 let g:syntastic_auto_loc_list=2


" Disable for HTML as it doesn't play nicely " Disable for HTML as it doesn't play nicely
" (cf. http://stackoverflow.com/questions/5237275/how-can-i-validate-html5-directly-in-vim)
" SEE HTML5 validation further on
let g:syntastic_disabled_filetypes = ['html'] let g:syntastic_disabled_filetypes = ['html']


"1}}} "1}}}
Expand Down Expand Up @@ -1398,6 +1400,11 @@ vnoremap ~ ygv"=TwiddleCase(@")<CR>Pgv
map <S-Enter> O<ESC> " awesome, inserts new line without going into insert mode map <S-Enter> O<ESC> " awesome, inserts new line without going into insert mode


"1}}}
"--------HTML5 validation--------------{{{1
"check html
map ,5 :!html5check %<CR>
"1}}} "1}}}


"------------------------------------------------------------------------------ "------------------------------------------------------------------------------
Expand Down

0 comments on commit 39cb951

Please sign in to comment.