Class: MediaWikiHTMLGenerator
- Inherits:
-
MediaWikiWalker
- Object
- MediaWikiWalker
- MediaWikiHTMLGenerator
- 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
Defined Under Namespace
Classes: TextGenerator, TocGenerator
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Returns the value of attribute html.
Attributes inherited from MediaWikiWalker
Class Method Summary collapse
-
.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.
-
.escape(str) ⇒ Object
Utility method that returns the string with ‘<’, ‘>’, ‘&’ and ‘“’ escaped as XHTML character entities.
Instance Method Summary collapse
Methods inherited from MediaWikiWalker
Instance Attribute Details
#html ⇒ Object (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 '<' when '>' then '>' when '&' then '&' when '"' then '"' 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 |