# SimpleTextMarkup is a XHTML compliant markup class, this was based # on RedCloth and was written as a custom lightweight replacement. # class SimpleTextMarkup # How to Use: # # Create the SimpletextMarkup object # oMarkup = SimpleTextMarkup.new(pYourString) # # Return converted to xhtml # oMarkup.to_xhtml #=> "html code" # # # # How to Markup: # # ==Strong Text # To make some text use a strong CSS class, put a * around the text # # Example # *Strong Text* # # Will become: # Strong Text # # # # == Code # To make a pre tag, put the content in [code] tags. # # Optional: To use a terminal class within you CSS to display text # differently use [terminal] tags. # # Example: # [code]this is some code[/code] # [terminal]this is a command[/terminal] # # Will become: #
this is some code
#
this is a command
# # attr_accessor :string # # Returns a new SimpleTextMarkup # # Example: # oMarkup = SimpleTextMarkup.new(pYourString) def initialize(pString) self.string = pString end # # Create the XHTML from the SimpleTextMarkup # # Example: # oMarkup = SimpleTextMarkup.new(pYourString) # oMarkup.to_xhtml #=> "html code" def to_xhtml return self.string if self.string.blank? #add paragraphs stm_add_paragraph #replace [code] with
        stm_code_to_pre

        #replace [terminal] with 
        stm_terminal_to_pre

        #cleanup un-used paragraphs
        stm_remove_empty_paragraphs


        return self.string
    end
    
    
    #
    # Create the basic XHTML from the SimpleTextMarkup
    # 
    # Example:
    #  oMarkup = SimpleTextMarkup.new(pYourString)
    #  oMarkup.to_xhtml_basic #=> "html code"
    def to_xhtml_basic
        return self.string if self.string.blank?
        
        #add paragraphs
        stm_add_paragraph

        #cleanup un-used paragraphs
        stm_remove_empty_paragraphs

        return self.string
    end
    
protected
#
#new tags
#
    #
    # add paragraph
    def stm_add_paragraph
        self.string ='

' + self.string + '

' end # #replace functions # # # replace [code] with
    def stm_code_to_pre
        self.string.gsub!(/\[code\]/, '

')
        self.string.gsub!(/\[\/code\]/, '

') end # # replace [terminal] with

    def stm_terminal_to_pre
        self.string.gsub!(/\[terminal\]/, '

')
        self.string.gsub!(/\[\/terminal\]/, '

') end # #cleanup functons # # # remove empty paragraphs def stm_remove_empty_paragraphs self.string.gsub!(/

<\/p>/, '') end end