Sha256: 0b8493e1e41a5c164cfc9d9d0c16ebf6f14f7dde55406e323ed18d7025464f66

Contents?: true

Size: 1.03 KB

Versions: 12

Compression:

Stored size: 1.03 KB

Contents

require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'

module QED
class Document

  # = QED Document Markup
  #
  # QED Document Markup is based on RDoc's SimpleMarkup format but adds
  # some additional features.
  #
  # * `[no-spaces]` produces <code>[no-space]</code>.
  #
  class Markup

    def initialize(text, options={})
      @text = text
    end

    def to_html
      parser.convert(@text, formatter)
    end

    def parser
      @parser ||= (
        p = SM::SimpleMarkup.new
        #p.add_word_pair("{", "}", :STRIKE)
        #p.add_html("no", :STRIKE)
        #p.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
        p.add_special(/\`(\S+?)\`/, :CODE)
        p
      )
    end

    def formatter
      @formatter ||= (
        f = ToHTML.new
        #f.add_tag(:STRIKE, "<strike>", "</strike>")
        f
      )
    end

    # Formatter
    class ToHTML < SM::ToHtml
      def handle_special_CODE(special)
        "<code>" + special.text.sub('`','').chomp('`') + "</code>"
      end
    end

  end

end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
qed-2.4.0 lib/qedoc/document/markup.rb
qed-2.3.0 lib/qedoc/document/markup.rb
qed-2.2.2 lib/qedoc/document/markup.rb
qed-2.2.1 lib/qedoc/document/markup.rb
qed-2.2.0 lib/qedoc/document/markup.rb
qed-2.1.1 lib/qedoc/document/markup.rb
qed-2.0.0 lib/qedoc/document/markup.rb
qed-2.1.0 lib/qedoc/document/markup.rb
qed-1.3 lib/qed/document/markup.rb
qed-1.2 lib/qed/document/markup.rb
qed-1.1.0 lib/qed/document/markup.rb
qed-1.0.0 lib/qed/document/markup.rb