Outputs RDoc markup as paragraphs with inline markup only.
- A
- C
- G
- H
- L
- N
- O
- S
- T
[R] | character_limit | After this many characters the input will be cut off. |
[R] | mask | The attribute bitmask |
[R] | paragraph_limit | After this many paragraphs the input will be cut off. |
[R] | paragraphs | Count of paragraphs found |
Creates a new ToHtmlSnippet formatter that
will cut off the input on the next word boundary after the given number of
characters
or paragraphs
of text have been
encountered.
# File lib/rdoc/markup/to_html_snippet.rb, line 36 def initialize options, characters = 100, paragraphs = 3, markup = nil super options, markup @character_limit = characters @paragraph_limit = paragraphs @characters = 0 @mask = 0 @paragraphs = 0 @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF end
Adds heading
to the output as a paragraph
Finishes consumption of list_item
Prepares the visitor for consuming list_item
Prepares the visitor for consuming list
Adds verbatim
to the output
Throws :done
when #paragraph_limit
paragraphs have been encountered
Marks up content
Converts flow items flow
# File lib/rdoc/markup/to_html_snippet.rb, line 214 def convert_flow flow throw :done if @characters >= @character_limit res = [] @mask = 0 flow.each do |item| case item when RDoc::Markup::AttrChanger then off_tags res, item on_tags res, item when String then text = convert_string item res << truncate(text) when RDoc::Markup::Special then text = convert_special item res << truncate(text) else raise "Unknown flow element: #{item.inspect}" end if @characters >= @character_limit then off_tags res, RDoc::Markup::AttrChanger.new(0, @mask) break end end res << ' ...' if @characters >= @character_limit res.join end
Returns just the text of link
, url
is only used
to determine the link type.
# File lib/rdoc/markup/to_html_snippet.rb, line 167 def gen_url url, text if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then type = "link" elsif url =~ /([A-Za-z]+):(.*)/ then type = $1 else type = "http" end if (type == "http" or type == "https" or type == "link") and url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then '' else text.sub(%r^#{type}:/*%, '') end end
Removes escaping from the cross-references in special
special
is a
In snippets, there are no lists
Lists are paragraphs, but notes and labels have a separator
# File lib/rdoc/markup/to_html_snippet.rb, line 142 def list_item_start list_item, list_type throw :done if @characters >= @character_limit case list_type when :BULLET, :LALPHA, :NUMBER, :UALPHA then "<p>" when :LABEL, :NOTE then labels = Array(list_item.label).map do |label| to_html label end.join ', ' labels << " — " unless labels.empty? start = "<p>#{labels}" @characters += 1 # try to include the label start else raise RDoc::Error, "Invalid list type: #{list_type.inspect}" end end
Maintains a bitmask to allow HTML elements to be closed properly. See RDoc::Markup::Formatter.
Maintains a bitmask to allow HTML elements to be closed properly. See RDoc::Markup::Formatter.
Prepares the visitor for HTML snippet generation
Truncates text
at the end of the first word after the
character_limit.
# File lib/rdoc/markup/to_html_snippet.rb, line 269 def truncate text length = text.length characters = @characters @characters += length return text if @characters < @character_limit remaining = @character_limit - characters text =~ /\A(.{#{remaining},}?)(\s|$)/m # TODO word-break instead of \s? $1 end