Commit 32764d98 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Better left-margin detection for doc-comments.

Now comments like:

        /**
         Some text here
	 Another line.
	 */

are handled as the author intended.  Previously this text would have
been parsed by Markdown as code-block as it's indented.  Now we remove
the indentation also at the beginning of these lines that don't begin
with '*'.
parent e7d26f90
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -59,12 +59,23 @@ module JsDuck
      # Now we are left with only two types of lines:
      # - those beginning with *
      # - and those without it
      indent = nil
      input.each_line do |line|
        line.chomp!
        if line =~ /\A\s*\*\s?(.*)\Z/
          # When comment contains *-lines, switch indent-trimming off
          indent = 0
          result << $1
        else
        elsif line =~ /\A\s*\Z/
          # pass-through empty lines
          result << line
        elsif indent == nil && line =~ /\A(\s*)(.*?\Z)/
          # When indent not measured, measure it and remember
          indent = $1.length
          result << $2
        else
          # Trim away indent if available
          result << line.sub(/\A\s{0,#{indent||0}}/, "")
        end
      end
      return result.join("\n")
+18 −0
Original line number Diff line number Diff line
@@ -99,5 +99,23 @@ describe JsDuck::DocParser do
    end
  end

  describe "doc-comment without *-s on left side" do
    before do
      @tag = parse_single("/**
        @event blah
        Some comment.
        More text.

            code sample
      */")[0]
    end
    it "detects the @event tag" do
      @tag[:tagname].should == :event
    end
    it "trims whitespace at beginning of lines up to first line" do
      @tag[:doc].should == "Some comment.\nMore text.\n\n    code sample"
    end
  end

end