 
       # If we reached the end of a multiline comment,
       # set inMulti to false and reset multiAccum
-      if line.match(language.multi_end_matcher)
+      if lang.checkType(line) is 'multiend'
         inMulti = no
         docs = multiAccum
         multiAccum = ''
 
     # Single line comment
-    else if line.match(language.comment_matcher) and not line.match(language.comment_filter)
+    else if lang.checkType(line) is 'single'
       if hasCode
-        save docs, code
-        hasCode = docs = code = ''
-      docs += line.replace(language.comment_matcher, '') + '\n'
+        hasCode = no
+        sections.push { docs: marked(docs), code }
+        docs = code = ''
+      docs += lang.filter(line) + '\n'
 
     # Code
     else


# The CSS styles we'd like to apply to the documentation.
docco_styles    = fs.readFileSync(__dirname + '/../resources/docco.css').toString()

# The start of each Pygments highlight block.
highlight_start = '<pre><code>'

# The end of each Pygments highlight block.
highlight_end   = '</code></pre>'

# Process our arguments, passing an array of sources to generate docs for,
# and an optional relative root.

_      = require 'underscore'
walk   = require 'walk'


# Configuration
# =============

marked.setOptions sanitize: false


# Generate the documentation for a source file by reading it in, splitting it
# up into comment/code sections, and merging them into an HTML template.
generateDocumentation = (sourceFile, context, cb) ->
  fs.readFile sourceFile, "utf-8", (err, code) ->
    throw err if err
    sections = makeSections getLanguage(sourceFile), code
    generate_source_html sourceFile, context, sections
    cb()


class Language

  constructor: (@symbols, @preprocessor) ->
    @regexs = {}
    @regexs.single = new RegExp('^\\s*' + @symbols.single + '\\s?') if @symbols.single
    # Hard coded /* */ for now
    @regexs.multi_start = new RegExp(/^[\s]*\/\*[.]*/)
    @regexs.multi_end = new RegExp(/.*\*\/.*/)

  # Check type of string
  checkType: (str) ->
    if str.match @regexs.multi_start
      'multistart'
    else if str.match @regexs.multi_end
      'multiend'
    else if @regexs.single? and str.match @regexs.single
      'single'
    else
      'code'

  # Filter out comment symbols
  filter: (str) ->
    for n, re of @regexs
      str = str.replace re, ''
    str


# A list of the supported stylesheet languages and their comment symbols
# and optional preprocessor command.
languages =
  '.css':  new Language { multi: [ "/*", "*/" ] }
  '.scss': new Language { single: '//', multi: [ "/*", "*/" ] }, 'scss'
  '.sass': new Language { single: '//', multi: [ "/*", "*/" ] }, 'sass'
  '.less': new Language { single: '//', multi: [ "/*", "*/" ] }, 'less'
  '.styl': new Language { single: '//', multi: [ "/*", "*/" ] }, 'stylus'



# Given a string of source code, find each comment and the code that
# follows it, and create an individual **section** for the code/doc pair.
makeSections = (lang, data) ->
  
  lines = data.split '\n'
  
