Skip to content

Commit

Permalink
Updated to allow line-anchored markup in templates.
Browse files Browse the repository at this point in the history
Previously, newlines were allowed inside templates, but line-anchored markup
(lists, verbatim, etc.) was not possible.  These changes make it possible to
have line anchored markup render correctly when inside templates.

The changes move delimiters for templates ("|" and "}}")  up to the block
level, along with list, text, and others.  This way, the delimiters will still
match as text when they are not part of a template.  However, they are easily
removed for the new arg_markup, arg_block, etc. rules that match more markup
inside templates, without missing the template's delimiters.

These changes should help when writing templates that don't use formatted
parameters, like syntax highlighting templates.  Those templates will now have
access to the original whitespace that was previously stripped by the rule,
since whitespace rules around template arguments were removed--the markup rules
handle whitespace themselves.

The line rule is now gone.  It was merged into the block rule (and now
arg_block), which makes more sense since line contained a couple of multi-line
rules.  It was intended to mean line-anchored, but wasn't really necesary and
it made sense to remove it.

Next problems to solve:
1. | and }}, when caught at the block level, will be rendered as paragraphs
2. In general, html paragraphs will need to be reworked
3. Templates that contain "|" as content will be difficult to write
  • Loading branch information
rdblue committed Nov 19, 2010
1 parent c9a713c commit 1f79fab
Showing 1 changed file with 62 additions and 90 deletions.
152 changes: 62 additions & 90 deletions lib/marker/language.treetop
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ module Marker
end

rule block
line
heading
/
list
/
verbatim_area
/
horiz_rule
/
text
/
template_end
/
arg_delimiter
/
ws { # allows blank lines
def to_html( options = {} )
""
Expand All @@ -29,15 +39,6 @@ module Marker
end

##### special lines
rule line
heading
/
list
/
verbatim_area
/
horiz_rule
end

rule heading
s:heading_toggle+ ws l:heading_enclosed_text ws e:heading_toggle+ <Heading>
Expand Down Expand Up @@ -78,10 +79,6 @@ module Marker
/
template_start
/
template_end
/
arg_delimiter
/
term_delimiter
end

Expand Down Expand Up @@ -161,10 +158,6 @@ module Marker
external_link_end
/
template_start
/
template_end
/
arg_delimiter
end

rule verbatim_area
Expand Down Expand Up @@ -194,9 +187,9 @@ module Marker

# a block of normal text, including single newlines but not a special line
rule text
!line h:phrase ws rnl r:text <Paragraph>
!(heading / list / verbatim_area / horiz_rule) h:phrase ws rnl r:text <Paragraph>
/
!line h:phrase ws <Paragraph>
!(heading / list / verbatim_area / horiz_rule) h:phrase ws <Paragraph>
end

# a block of text that does not require a !line check
Expand Down Expand Up @@ -233,7 +226,23 @@ module Marker
/
plain_word
/
delimiter # catch all remaining unmatched delimiters
bold_toggle
/
italic_toggle
/
heading_toggle
/
internal_link_start
/
internal_link_end
/
external_link_start
/
external_link_end
/
template_start
/
term_delimiter
end

##### text markup
Expand Down Expand Up @@ -272,10 +281,6 @@ module Marker
/
template_start
/
template_end
/
arg_delimiter
/
term_delimiter
end

Expand Down Expand Up @@ -313,10 +318,6 @@ module Marker
/
template_start
/
template_end
/
arg_delimiter
/
term_delimiter
end

Expand All @@ -330,7 +331,6 @@ module Marker
# [[ link target | link label ]]
# * can contain white space
# * cannot contain new lines
#-- TODO: handle [[ url | label ]] and variants ++
rule internal_link
internal_link_start ws t:plain_text ws a:arg_delimiter ws l:internal_link_enclosed_text ws internal_link_end <InternalLink>
/
Expand Down Expand Up @@ -368,10 +368,6 @@ module Marker
/
template_start
/
template_end
/
arg_delimiter
/
term_delimiter
end

Expand Down Expand Up @@ -434,72 +430,66 @@ module Marker
/
template_start
/
template_end
/
arg_delimiter
/
term_delimiter
end

rule template
template_start aws t:plain_text aws arg_delimiter aws args:arg_list aws template_end <Template>
template_start aws t:plain_text aws arg_delimiter args:arg_list template_end <Template>
/
template_start aws t:plain_text aws template_end <Template>
end

rule arg_list
h:arg aws arg_delimiter aws r:arg_list <Arguments>
h:arg arg_delimiter r:arg_list <Arguments>
/
h:arg "" <Arguments>
end

# a plain (positional) argument or a named (name=text) argument
rule arg
name:plain_text aws heading_toggle aws val:arg_list_enclosed_text <Argument>
ws name:plain_text ws heading_toggle val:arg_markup <Argument>
/
val:arg_list_enclosed_text "" <Argument>
val:arg_markup "" <Argument>
/
"" "" <Argument>
end

rule arg_list_enclosed_text
h:arg_list_enclosed_word aws r:arg_list_enclosed_text <Phrase>
rule arg_markup
h:arg_block ws rnl r:arg_markup <Markup>
/
h:arg_list_enclosed_word "" <Phrase>
h:arg_block ws <Markup>
end

rule arg_list_enclosed_word
bold
/
italic
/
link
/
template
/
url
/
escaped_char
/
plain_word
/
bold_toggle # allow unmatched delimiters after we have ruled out structures
/
italic_toggle
rule arg_block
heading
/
heading_toggle
list
/
internal_link_start
arg_verbatim_area
/
internal_link_end
/
external_link_start
horiz_rule
/
external_link_end
text
/
template_start
ws { # allows blank lines
def to_html( options = {} )
""
end

def to_s( options = {} )
""
end
}
end

rule arg_verbatim_area
h:arg_verbatim rnl r:arg_verbatim_area <VerbatimArea>
/
term_delimiter
h:arg_verbatim "" <VerbatimArea>
end

rule arg_verbatim
" " v:( !("\n" / arg_delimiter / template_end) .)* <Verbatim>
end

# a phrase of plain words
Expand All @@ -511,15 +501,7 @@ module Marker

# avoids using a white-list so that utf-8 characters are accepted
#
# matches anything up to a delimiter or whitespace
#
# escaped delimiters for templates go here too. this enables markup to
# pass pipes and equals signs into templates. for example:
# {{ highlight | format=ruby |
# array.map do \|el\|
# el.reverse
# end
# }}
# matches anything other than a delimiter or whitespace
rule plain_word
(!delimiter [^ \t\r\n])+ <Word>
end
Expand Down Expand Up @@ -549,8 +531,6 @@ module Marker
arg_delimiter
/
term_delimiter
/
escaped_char
end

rule bold_toggle
Expand Down Expand Up @@ -659,14 +639,6 @@ 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

0 comments on commit 1f79fab

Please sign in to comment.