Commit 5b08c1aa authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Avoid detecting @tags inside indented code blocks.

parent 5c1c5aa5
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -162,10 +162,13 @@ module JsDuck
    #
    # There must be space before the next @tag - this ensures that we
    # don't detect tags inside "foo@example.com" or "{@link}".
    #
    # Also check that the @tag is not part of an indented code block -
    # in which case we also ignore the tag.
    def skip_to_next_at_tag
      @current_tag[:doc] += match(/[^@]+/)

      while !prev_char_is_whitespace? && look(/@/)
      while look(/@/) && (!prev_char_is_whitespace? || indented_as_code?)
        @current_tag[:doc] += match(/@+[^@]+/)
      end
    end
@@ -174,6 +177,10 @@ module JsDuck
      @current_tag[:doc][-1,1] =~ /\s/
    end

    def indented_as_code?
      @current_tag[:doc] =~ /^ {4,}[^\n]*\Z/
    end

    # Processes anything else beginning with @-sign.
    #
    # - When @ is not followed by any word chards, do nothing.
+37 −0
Original line number Diff line number Diff line
@@ -157,4 +157,41 @@ describe JsDuck::DocParser do
    end
  end

  describe "@tag indented by 4+ spaces" do
    before do
      @tag = parse_single(<<-EOS.strip)[0]
         * Code example:
         *
         *     @method
      EOS
    end
    it "is treated as plain text within code example" do
      @tag[:doc].should == "Code example:\n\n    @method"
    end
  end

  describe "@tag indented by 4+ spaces and preceded by additional code" do
    before do
      @tag = parse_single(<<-EOS.strip)[0]
         * Code example:
         *
         *     if @method then
      EOS
    end
    it "is treated as plain text within code example" do
      @tag[:doc].should == "Code example:\n\n    if @method then"
    end
  end

  describe "@tag simply separated by 4+ spaces" do
    before do
      @tag = parse_single(<<-EOS.strip)[1]
         * Foo:    @method
      EOS
    end
    it "is parsed as normal tag" do
      @tag[:tagname].should == :method
    end
  end

end