Skip to content

Commit

Permalink
Closes #8 adding the 'trim' option
Browse files Browse the repository at this point in the history
  • Loading branch information
kaievns committed Jun 24, 2012
1 parent 6b3bea2 commit fa45d6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions index.html
Expand Up @@ -210,9 +210,15 @@ <h2>Loooooooong Strings</h2>

<h2>With the `data-colorifier="{gutter: false}"` option</h2>
<pre data-lang="undefined" data-colorifier='{"gutter": false}'>
Some
random
code
Some
random
code
</pre>

<h2>Trailing spaces trimming disabled</h2>
<pre data-lang="undefined" data-colorifier='{"trim" : false}'>
something: ->
boo(hoo)
</pre>

<p class="white-space"></p>
Expand Down
7 changes: 4 additions & 3 deletions src/colorifier.coffee
Expand Up @@ -13,6 +13,7 @@ class Colorifier extends Element
attr: 'data-lang' # attribute that keeps the language name
theme: 'light' # color theme name
gutter: true # show or not the gutter
trim: true # automatically trim trailing spaces

# mass-initializer
initialize: ()->
Expand Down Expand Up @@ -44,20 +45,20 @@ class Colorifier extends Element
constructor: (element)->
return @ unless element

@setOptions(element.data('colorifier'))

super 'div', class: 'colorifier'

text = element.html()
text = text.replace(/</g, '&lt;')
text = text.replace(/>/g, '&gt;')
text = text.replace(/(^\s+)|(\s+$)/g, '')
text = text.replace(/(^\s*\n)|(\s+$)/g, '') if @options.trim

@ref = element.html(this.paint(text))

@style(element.style(@styles2copy))
@insertTo(element.hide(), 'before')

@setOptions(element.data('colorifier'))

if @options.gutter
nums = (i for line, i in text.split("\n"))
@insert(new Element('div', class: 'gutter', html: nums.join('<br/>')))
Expand Down

0 comments on commit fa45d6a

Please sign in to comment.