Class: MediaWikiHTMLGenerator

Inherits:
MediaWikiWalker show all
Defined in:
lib/mediacloth/mediawikihtmlgenerator.rb

Overview

HTML generator for a MediaWiki parse tree

Typical use case: parser = MediaWikiParser.new parser.lexer = MediaWikiLexer.new ast = parser.parse(input) walker = MediaWikiHTMLGenerator.new walker.parse(ast) puts walker.html

Direct Known Subclasses

TocGenerator

Defined Under Namespace

Classes: TextGenerator, TocGenerator

Instance Attribute Summary collapse

Attributes inherited from MediaWikiWalker

#params, #template_handler

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MediaWikiWalker

#link_handler, #link_handler=

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



15
16
17
# File 'lib/mediacloth/mediawikihtmlgenerator.rb', line 15

def html
  @html
end

Class Method Details

.anchor_for(str) ⇒ Object

Utility method that converts the string specified into a specially formatted text string which can be used as an XHTML link anchor name.



40
41
42
# File 'lib/mediacloth/mediawikihtmlgenerator.rb', line 40

def MediaWikiHTMLGenerator.anchor_for(str)
  str.strip.squeeze(' ').gsub(' ', '_').gsub('\'', '_')
end

.escape(str) ⇒ Object

Utility method that returns the string with ‘<’, ‘>’, ‘&’ and ‘“’ escaped as XHTML character entities



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mediacloth/mediawikihtmlgenerator.rb', line 25

def MediaWikiHTMLGenerator.escape(str)
    r = str.gsub(%r{[<>&"]}) do
        |match|
        case match
        when '<' then '&lt;'
        when '>' then '&gt;'
        when '&' then '&amp;'
        when '"' then '&quot;'
        end
    end
    r
end

Instance Method Details

#parse(ast) ⇒ Object



17
18
19
20
21
# File 'lib/mediacloth/mediawikihtmlgenerator.rb', line 17

def parse(ast)
    @html = ""
    @ast = ast
    @html = super(ast)
end