Skip to content

Commit

Permalink
better whitespace support for nasty HTML, fixed ie-close bug, empty c…
Browse files Browse the repository at this point in the history
…omment fix, empty doctype (?) fix
  • Loading branch information
colinta committed Feb 1, 2012
1 parent 8a52dd0 commit 02a5dd6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
15 changes: 8 additions & 7 deletions lib/htmlkup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{ {
"name": "htmlkup", "name": "htmlkup",
"description": "Converts html to coffeekup. Well tested state machine written in coffeescript.", "description": "Converts html to coffeekup. Well tested state machine written in coffeescript.",
"version": "1.2.5", "version": "1.2.6",
"author": "Colin Thomas-Arnold <colinta@gmail.com> http://colinta.com/", "author": "Colin Thomas-Arnold <colinta@gmail.com> http://colinta.com/",
"bin": { "htmlkup": "./bin/htmlkup" }, "bin": { "htmlkup": "./bin/htmlkup" },
"main": "./lib/htmlkup.js", "main": "./lib/htmlkup.js",
Expand Down
16 changes: 8 additions & 8 deletions src/htmlkup.coffee
Expand Up @@ -30,7 +30,7 @@ module.exports = (html, output_debug)->


'tag-open': ['attr-reset'] 'tag-open': ['attr-reset']
'tag-close': ['reset'] 'tag-close': ['reset']
'tag-ws': ['attr', 'singleton'] 'tag-ws': ['attr', 'singleton', 'tag-gt']
'tag-gt': ['cdata', 'reset'] 'tag-gt': ['cdata', 'reset']
'singleton': ['reset'] 'singleton': ['reset']


Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = (html, output_debug)->


'tag-open' : /^<[a-zA-Z]([-_]?[a-zA-Z0-9])*/ 'tag-open' : /^<[a-zA-Z]([-_]?[a-zA-Z0-9])*/
'tag-close' : /^<\/[a-zA-Z]([-_]?[a-zA-Z0-9])*>/ 'tag-close' : /^<\/[a-zA-Z]([-_]?[a-zA-Z0-9])*>/
'tag-ws' : /^[ ]/ 'tag-ws' : /^[ \t\n]+/
'tag-gt' : /^>/ 'tag-gt' : /^>/
'singleton' : /^\/>/ 'singleton' : /^\/>/


Expand All @@ -78,8 +78,8 @@ module.exports = (html, output_debug)->
'attr-dqt' : /^"/ 'attr-dqt' : /^"/
'attr-sqt' : /^'/ 'attr-sqt' : /^'/
'attr-value' : /^[a-zA-Z0-9]([-_]?[a-zA-Z0-9])*/ 'attr-value' : /^[a-zA-Z0-9]([-_]?[a-zA-Z0-9])*/
'attr-dvalue' : /^[^"\n]*/ 'attr-dvalue' : /^[^"]*/
'attr-svalue' : /^[^'\n]*/ 'attr-svalue' : /^[^']*/
'attr-cdqt' : /^"/ 'attr-cdqt' : /^"/
'attr-csqt' : /^'/ 'attr-csqt' : /^'/


Expand Down Expand Up @@ -122,7 +122,7 @@ module.exports = (html, output_debug)->
throw new Error "Missing possibles for #{state}" throw new Error "Missing possibles for #{state}"
nexts = (next for next in possibles[state] when current.match detect[next]) nexts = (next for next in possibles[state] when current.match detect[next])
if ! nexts.length if ! nexts.length
throw new Error "At: #{state} (#{JSON.stringify(if current.length > 10 then current.substring(0, 10) + '...' else current)}), expected: #{(noun for noun in possibles[state]).join ' '}, found #{(noun for noun, regex of detect when current.match regex).join ' '}" throw new Error "At: #{state} (#{JSON.stringify(if current.length > 10 then current.substring(0, 10) + '...' else current)} @#{c}), expected: #{(noun for noun in possibles[state]).join ' '}, found #{(noun for noun, regex of detect when current.match regex).join ' '}"


next = nexts[0] next = nexts[0]
value = (current.match detect[next])[0] value = (current.match detect[next])[0]
Expand Down Expand Up @@ -155,7 +155,7 @@ module.exports = (html, output_debug)->
if last_tag.is_singleton if last_tag.is_singleton
last_tag = parent_tags.pop() last_tag = parent_tags.pop()
console.error 'closing: ', last_tag if output_debug console.error 'closing: ', last_tag if output_debug
when 'singleton', 'tag-close' when 'singleton', 'tag-close', 'ie-close'
last_tag = parent_tags.pop() last_tag = parent_tags.pop()
console.error 'pop: ', parent_tags.length, last_tag if output_debug console.error 'pop: ', parent_tags.length, last_tag if output_debug
when 'text' when 'text'
Expand Down Expand Up @@ -214,14 +214,14 @@ render = (tags, indent = [])->
else else
ret += "#{indent.join('')}text #{JSON.stringify tag}" ret += "#{indent.join('')}text #{JSON.stringify tag}"
ret += "\n" ret += "\n"
else if tag.doctype else if tag.doctype?
mapped = doctypes[tag.doctype.replace(/\s+/g, ' ')] mapped = doctypes[tag.doctype.replace(/\s+/g, ' ')]
if mapped == '5' if mapped == '5'
ret += "doctype 5" ret += "doctype 5"
else else
ret += "doctype #{JSON.stringify (if mapped? then mapped else tag.doctype)}" ret += "doctype #{JSON.stringify (if mapped? then mapped else tag.doctype)}"
ret += "\n" ret += "\n"
else if tag.comment else if tag.comment?
ret += "#{indent.join('')}comment " ret += "#{indent.join('')}comment "
str = tag.comment.trim() str = tag.comment.trim()
if str.match(/\n/) if str.match(/\n/)
Expand Down

0 comments on commit 02a5dd6

Please sign in to comment.