Class: RDoc::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/markup.rb,
lib/rdoc/markup/attr_changer.rb

Overview

frozen_string_literal: false

Defined Under Namespace

Classes: AttrChanger, AttrSpan, AttributeManager, Attributes, BlankLine, BlockQuote, Document, Formatter, FormatterTestCase, HardBreak, Include, IndentedParagraph, List, ListItem, Paragraph, Parser, PreProcess, Raw, Rule, Special, TextFormatterTestCase, ToAnsi, ToBs, ToHtml, ToHtmlCrossref, ToHtmlSnippet, ToJoinedParagraph, ToLabel, ToMarkdown, ToRdoc, ToTableOfContents, ToTest, ToTtOnly, Verbatim

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_manager = nil) ⇒ Markup

Take a block of text and use various heuristics to determine its structure (paragraphs, lists, and so on). Invoke an event handler as we identify significant chunks.



778
779
780
781
# File 'lib/rdoc/markup.rb', line 778

def initialize attribute_manager = nil
  @attribute_manager = attribute_manager || RDoc::Markup::AttributeManager.new
  @output = nil
end

Instance Attribute Details

#attribute_managerObject (readonly)

An AttributeManager which handles inline markup.



743
744
745
# File 'lib/rdoc/markup.rb', line 743

def attribute_manager
  @attribute_manager
end

Class Method Details

.parse(str) ⇒ Object

Parses str into an RDoc::Markup::Document.



748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/rdoc/markup.rb', line 748

def self.parse str
  RDoc::Markup::Parser.parse str
rescue RDoc::Markup::Parser::Error => e
  $stderr.puts <<-EOF
While parsing markup, RDoc encountered a #{e.class}:

#{e}
\tfrom #{e.backtrace.join "\n\tfrom "}

---8<---
#{text}
---8<---

RDoc #{RDoc::VERSION}

Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_RELEASE_DATE}

Please file a bug report with the above information at:

https://github.com/rdoc/rdoc/issues

  EOF
  raise
end

Instance Method Details

#add_html(tag, name) ⇒ Object

Add to the sequences recognized as general markup.



795
796
797
# File 'lib/rdoc/markup.rb', line 795

def add_html(tag, name)
  @attribute_manager.add_html(tag, name)
end

#add_special(pattern, name) ⇒ Object

Add to other inline sequences. For example, we could add WikiWords using something like:

parser.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)

Each wiki word will be presented to the output formatter via the accept_special method.



808
809
810
# File 'lib/rdoc/markup.rb', line 808

def add_special(pattern, name)
  @attribute_manager.add_special(pattern, name)
end

#add_word_pair(start, stop, name) ⇒ Object

Add to the sequences used to add formatting to an individual word (such as bold). Matching entries will generate attributes that the output formatters can recognize by their name.



788
789
790
# File 'lib/rdoc/markup.rb', line 788

def add_word_pair(start, stop, name)
  @attribute_manager.add_word_pair(start, stop, name)
end

#convert(input, formatter) ⇒ Object

We take input, parse it if necessary, then invoke the output formatter using a Visitor to render the result.



816
817
818
819
820
821
822
823
824
825
# File 'lib/rdoc/markup.rb', line 816

def convert input, formatter
  document = case input
             when RDoc::Markup::Document then
               input
             else
               RDoc::Markup::Parser.parse input
             end

  document.accept formatter
end