Skip to content
Browse files

Add support for CSS selector style in output

  • Loading branch information...
1 parent 9db6c27 commit 04188fb1a1d7b71a7d117ee1f48120673e449455 @brandonbloom committed Nov 2, 2011
Showing with 16 additions and 8 deletions.
  1. +12 −4 lib/convert.coffee
  2. +3 −3 test/simple.coffee
  3. +1 −1 test/simple.html
View
16 lib/convert.coffee
@@ -11,8 +11,9 @@ exports.convert = (html, stream, options, callback) ->
if not callback
callback = (->)
- {prefix} = options
+ {prefix, selectors} = options
prefix ?= ''
+ selectors ?= false
depth = 0
@@ -44,10 +45,17 @@ exports.convert = (html, stream, options, callback) ->
extractAttrib = (key) ->
value = tag.attribs[key]
if value
- attribs.push [key, value]
+ attribs.push [key, value] unless selectors
delete tag.attribs[key]
- extractAttrib 'id'
- extractAttrib 'class'
+ value
+ id = extractAttrib 'id'
+ cls = extractAttrib 'class'
+ if selectors and (id or cls)
+ selector = ''
+ selector += "##{id}" if id
+ selector += ".#{cls.replace(' ', '.')}" if cls
+ code += " '#{selector}'"
+ called = true
for key, value of tag.attribs
attribs.push [key, value]
View
6 test/simple.coffee
@@ -3,15 +3,15 @@ html ->
head ->
title 'A simple test page'
style type: 'text/css', '.foo {\n color: red\n }'
- body class: 'awesome', ->
- div id: 'root', class: 'special', ->
+ body '.awesome', ->
+ div '#root.super.special', ->
comment 'This page is rapidly becoming not-so-simple'
h1 'A simple test page'
p ->
text 'With some awesome text, and a'
a href: 'http://www.google.com', 'link'
text '.'
- p id: 'paragraph_2', ->
+ p '#paragraph_2', ->
text 'And here is an image:'
img src: 'fake/source', title: 'not really'
text 'As well as a disabled select:'
View
2 test/simple.html
@@ -9,7 +9,7 @@
</style>
</head>
<body class="awesome">
- <div id="root" class="special">
+ <div id="root" class="super special">
<!-- This page is rapidly becoming not-so-simple -->
<h1>A simple test page</h1>
<p>

0 comments on commit 04188fb

Please sign in to comment.
Something went wrong with that request. Please try again.