Skip to content

Commit

Permalink
Adding escaped characters and tests, small optimization.
Browse files Browse the repository at this point in the history
Escaped characters only apply inside templates.  I think this breaks \| outside
of templates though.  Ugh.
  • Loading branch information
rdblue committed Jul 11, 2010
1 parent f87f517 commit 72d1c15
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/marker.rb
Expand Up @@ -22,6 +22,8 @@

require 'marker/language'

$stderr.puts "loading Marker at #{__FILE__}"

#:include:README
module Marker
class << self
Expand Down
20 changes: 13 additions & 7 deletions lib/marker/language.treetop
Expand Up @@ -477,6 +477,8 @@ module Marker
/
url
/
escaped_char
/
plain_word
/
bold_toggle # allow unmatched delimiters after we have ruled out structures
Expand Down Expand Up @@ -517,13 +519,7 @@ module Marker
# end
# }}
rule plain_word
(!delimiter ![ \t\r\n] .)+ <Word>
/
"\\\\" <Word> # fixup vim syntax --> "
/
"\\|" <Word>
/
"\\=" <Word>
(!delimiter [^ \t\r\n])+ <Word>
end

##### delimiters
Expand Down Expand Up @@ -551,6 +547,8 @@ module Marker
arg_delimiter
/
term_delimiter
/
escaped_char
end

rule bold_toggle
Expand Down Expand Up @@ -659,6 +657,14 @@ module Marker
# [A-Z_]+
# end

rule escaped_char
"\\\\" <Escaped> # fix vim highlighting => "
/
"\\|" <Escaped>
/
"\\=" <Escaped>
end

rule number
[1-9] digit* {
def to_i
Expand Down
10 changes: 10 additions & 0 deletions lib/marker/text.rb
Expand Up @@ -74,6 +74,16 @@ def to_s( options = {} )
end
end

class Escaped < ParseNode
def to_html( options = {} )
text_value.slice(-1,1)
end

def to_s( options = {} )
text_value.slice(-1,1)
end
end

class HorizRule < ParseNode
def to_html( options = {} )
"<hr />" +
Expand Down
10 changes: 10 additions & 0 deletions test/templates_test.rb
Expand Up @@ -52,4 +52,14 @@ def test_rendered_args
assert_match("<p>render:template( :html, [\"<a href='http://www.example.com'>Example</a>\"], {} )</p>", markup.to_html)
end

def test_escaped_characters
# the single quotes are important here, to make sure the "\" are in the actual text
# this test is messed up right now. we should have a way to send a single
# '\' through, but ruby seems to have errors with it! for now, just removing that case.
text = '{{ template | \| | a \= b | \|a, b\| }}'
markup = Marker.parse text

assert_match('<p>render:template( :html, ["|", "a = b", "|a, b|"], {} )</p>', markup.to_html)
end

end
2 changes: 1 addition & 1 deletion test/test_helper.rb
@@ -1,2 +1,2 @@
require 'test/unit'
$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
$LOAD_PATH.unshift File.expand_path( File.dirname(__FILE__) + '/../lib' )

0 comments on commit 72d1c15

Please sign in to comment.