Sha256: cb704365020ece8583afd06848810439de341e678c49416f653a00a8174bb806

Contents?: true

Size: 1.22 KB

Versions: 19

Compression:

Stored size: 1.22 KB

Contents

require 'rdoc/markup'
require 'rdoc/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>.
    #
    # FIXME: Can't get `brackets` to work.
    class Markup

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

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

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

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

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

    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
qed-2.9.2 lib/qed/document/markup.rb
qed-2.9.1 lib/qed/document/markup.rb
qed-2.9.0 lib/qed/document/markup.rb
qed-2.8.8 lib/qed/document/markup.rb
qed-2.8.7 lib/qed/document/markup.rb
qed-2.8.6 lib/qed/document/markup.rb
qed-2.8.5 lib/qed/document/markup.rb
qed-2.8.4 lib/qed/document/markup.rb
qed-2.8.3 lib/qed/document/markup.rb
qed-2.8.2 lib/qed/document/markup.rb
qed-2.8.1 lib/qed/document/markup.rb
qed-2.8.0 lib/qed/document/markup.rb
qed-2.7.0 lib/qed/document/markup.rb
qed-2.6.3 lib/qed/document/markup.rb
qed-2.6.2 lib/qed/document/markup.rb
qed-2.6.1 lib/qed/document/markup.rb
qed-2.6.0 lib/qed/document/markup.rb
qed-2.5.1 lib/qedoc/document/markup.rb
qed-2.5.0 lib/qedoc/document/markup.rb