Class: Jazzy::Markdown::JazzyDeclarationHTML

Inherits:
JazzyHTML
  • Object
show all
Defined in:
lib/jazzy/jazzy_markdown.rb

Overview

Spot and capture returns & param HTML for separate display.

Constant Summary collapse

INTRO_PAT =
'\A(?<intro>\s*(<p>\s*)?)'.freeze
OUTRO_PAT =
'(?<outro>.*)\z'.freeze
RETURNS_REGEX =
/#{INTRO_PAT}returns:#{OUTRO_PAT}/im
IDENT_PAT =
'(?<param>\S+)'.freeze
PARAM_PAT1 =

Param formats: normal swift, objc via sourcekitten, and possibly inside ‘Parameters:’

"(parameter +#{IDENT_PAT}\\s*:)".freeze
PARAM_PAT2 =
"(parameter:\\s*#{IDENT_PAT}\\s+)".freeze
PARAM_PAT3 =
"(#{IDENT_PAT}\\s*:)".freeze
PARAM_PAT =
"(?:#{PARAM_PAT1}|#{PARAM_PAT2}|#{PARAM_PAT3})".freeze
PARAM_REGEX =
/#{INTRO_PAT}#{PARAM_PAT}#{OUTRO_PAT}/im

Constants inherited from JazzyHTML

Jazzy::Markdown::JazzyHTML::ELIDED_LI_TOKEN, Jazzy::Markdown::JazzyHTML::GENERAL_CALLOUTS, Jazzy::Markdown::JazzyHTML::SPECIAL_LIST_TYPES, Jazzy::Markdown::JazzyHTML::SPECIAL_LIST_TYPE_REGEX, Jazzy::Markdown::JazzyHTML::UNIQUELY_HANDLED_CALLOUTS

Instance Attribute Summary collapse

Attributes inherited from JazzyHTML

#default_language

Instance Method Summary collapse

Methods inherited from JazzyHTML

#block_code, #header, #list, #render_aside, #rouge_formatter

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



124
125
126
# File 'lib/jazzy/jazzy_markdown.rb', line 124

def parameters
  @parameters
end

#returnsObject (readonly)

Returns the value of attribute returns.



124
125
126
# File 'lib/jazzy/jazzy_markdown.rb', line 124

def returns
  @returns
end

Instance Method Details

#list_item(text, _list_type) ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'lib/jazzy/jazzy_markdown.rb', line 148

def list_item(text, _list_type)
  if text =~ RETURNS_REGEX
    @returns = render_param_returns(Regexp.last_match)
  elsif text =~ PARAM_REGEX
    @parameters[Regexp.last_match(:param)] =
      render_param_returns(Regexp.last_match)
  end
  super
end

#render_param_returns(matches) ⇒ Object



158
159
160
161
162
163
# File 'lib/jazzy/jazzy_markdown.rb', line 158

def render_param_returns(matches)
  body = matches[:intro].strip + matches[:outro].strip
  body = "<p>#{body}</p>" unless body.start_with?('<p>')
  # call smartypants for pretty quotes etc.
  postprocess(body)
end

#resetObject



126
127
128
129
# File 'lib/jazzy/jazzy_markdown.rb', line 126

def reset
  @returns = nil
  @parameters = {}
end