summaryrefslogtreecommitdiff
path: root/jni/ruby/lib/rdoc/markup/heading.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/lib/rdoc/markup/heading.rb
Fresh start
Diffstat (limited to 'jni/ruby/lib/rdoc/markup/heading.rb')
-rw-r--r--jni/ruby/lib/rdoc/markup/heading.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/jni/ruby/lib/rdoc/markup/heading.rb b/jni/ruby/lib/rdoc/markup/heading.rb
new file mode 100644
index 0000000..535e310
--- /dev/null
+++ b/jni/ruby/lib/rdoc/markup/heading.rb
@@ -0,0 +1,78 @@
+##
+# A heading with a level (1-6) and text
+
+RDoc::Markup::Heading =
+ Struct.new :level, :text do
+
+ @to_html = nil
+ @to_label = nil
+
+ ##
+ # A singleton RDoc::Markup::ToLabel formatter for headings.
+
+ def self.to_label
+ @to_label ||= RDoc::Markup::ToLabel.new
+ end
+
+ ##
+ # A singleton plain HTML formatter for headings. Used for creating labels
+ # for the Table of Contents
+
+ def self.to_html
+ return @to_html if @to_html
+
+ markup = RDoc::Markup.new
+ markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
+
+ @to_html = RDoc::Markup::ToHtml.new nil
+
+ def @to_html.handle_special_CROSSREF special
+ special.text.sub(/^\\/, '')
+ end
+
+ @to_html
+ end
+
+ ##
+ # Calls #accept_heading on +visitor+
+
+ def accept visitor
+ visitor.accept_heading self
+ end
+
+ ##
+ # An HTML-safe anchor reference for this header.
+
+ def aref
+ "label-#{self.class.to_label.convert text.dup}"
+ end
+
+ ##
+ # Creates a fully-qualified label which will include the label from
+ # +context+. This helps keep ids unique in HTML.
+
+ def label context = nil
+ label = aref
+
+ label = [context.aref, label].compact.join '-' if
+ context and context.respond_to? :aref
+
+ label
+ end
+
+ ##
+ # HTML markup of the text of this label without the surrounding header
+ # element.
+
+ def plain_html
+ self.class.to_html.to_html(text.dup)
+ end
+
+ def pretty_print q # :nodoc:
+ q.group 2, "[head: #{level} ", ']' do
+ q.pp text
+ end
+ end
+
+end
+