P
Patrick Gundlach
Hello out there,
I am experimenting with TagTreeScanner from Gavin Kistner. Has anybody
created a Wiki-markup parser for the mediawiki software?
I have succeded for a few tags, but I am currently stuck with
enumerations:
* one
*two
* three
** threeone
** threetwo
*four
should be represented by sth. like
<ol>
<li>one</li>
<li>two</li>
<li>three
<ol>
<li>threeone</li>
<li>threetwo</li>
</ol>
</li>
<li>four</li>
</ol>
This is what I have tried, but I have the feeling that is not the way
to proceed here. I only get <ol> </ol> around the string.
--------------------------------------------------
#!/opt/ruby/1.8.2/bin/ruby
require 'TagTreeScanner'
class SimpleMarkup < TagTreeScanner
@root_factory.allows_text = false
@tag_genres[ :root ] = [ ]
@tag_genres[ :root ] <<
TagFactory.new( l,
pen_match => /(\*.+?)\n+(?=[^*])/m,
pen_requires_bol => true,
:setup => lambda{ |tag, scanner, tagtree|
# Throw the contents I found into the tag
# but remove leading whitespace
tag << scanner[1] # [1].gsub( /\*/, '<li>' )
},
:allows_text => true,
:autoclose => :true,
# no effect: (??)
:allowed_genre => :list
)
@tag_genres[ :list ] = [ ]
@tag_genres[ :list ] <<
TagFactory.new( :li,
pen_match => /\*/,
:close_match => /\n/,
pen_requires_bol => true,
:allows_text => true
)
end
sample = <<EOS
* one
*two
* three
** threeone
** threetwo
*four
EOS
markup = SimpleMarkup.new(sample)
puts markup.to_xml
--------------------------------------------------
I am experimenting with TagTreeScanner from Gavin Kistner. Has anybody
created a Wiki-markup parser for the mediawiki software?
I have succeded for a few tags, but I am currently stuck with
enumerations:
* one
*two
* three
** threeone
** threetwo
*four
should be represented by sth. like
<ol>
<li>one</li>
<li>two</li>
<li>three
<ol>
<li>threeone</li>
<li>threetwo</li>
</ol>
</li>
<li>four</li>
</ol>
This is what I have tried, but I have the feeling that is not the way
to proceed here. I only get <ol> </ol> around the string.
--------------------------------------------------
#!/opt/ruby/1.8.2/bin/ruby
require 'TagTreeScanner'
class SimpleMarkup < TagTreeScanner
@root_factory.allows_text = false
@tag_genres[ :root ] = [ ]
@tag_genres[ :root ] <<
TagFactory.new( l,
pen_match => /(\*.+?)\n+(?=[^*])/m,
pen_requires_bol => true,
:setup => lambda{ |tag, scanner, tagtree|
# Throw the contents I found into the tag
# but remove leading whitespace
tag << scanner[1] # [1].gsub( /\*/, '<li>' )
},
:allows_text => true,
:autoclose => :true,
# no effect: (??)
:allowed_genre => :list
)
@tag_genres[ :list ] = [ ]
@tag_genres[ :list ] <<
TagFactory.new( :li,
pen_match => /\*/,
:close_match => /\n/,
pen_requires_bol => true,
:allows_text => true
)
end
sample = <<EOS
* one
*two
* three
** threeone
** threetwo
*four
EOS
markup = SimpleMarkup.new(sample)
puts markup.to_xml
--------------------------------------------------