Method: JsDuck::Format::Subproperties#format_type

Defined in:
lib/jsduck/format/subproperties.rb

#format_type(type) ⇒ Object

Formats the given type definition string using TypeParser.

  • On success returns HTML-version of the type definition.

  • On failure logs error and returns the type string with only HTML escaped.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jsduck/format/subproperties.rb', line 43

def format_type(type)
  # Skip the formatting entirely when type-parsing is turned off.
  return Util::HTML.escape(type) if @skip_type_parsing

  tp = TypeParser.new(@formatter)
  if tp.parse(type)
    tp.out
  else
    context = @formatter.doc_context
    if tp.error == :syntax
      Logger.warn(:type_syntax, "Incorrect type syntax #{type}", context)
    else
      Logger.warn(:type_name, "Unknown type #{type}", context)
    end
    Util::HTML.escape(type)
  end
end