Skip to content

Commit

Permalink
Allow HTML tags with quoted attributes to be inside link text.
Browse files Browse the repository at this point in the history
To do this, I had to remove the possibility that attributes in HTML tags could have spaces around the equals sign or unquoted attributes.  This change also greatly expands the complexity of the state machine, so compilation takes a long time. Sorry.
  • Loading branch information
jgarber committed Mar 9, 2009
1 parent 28f97a5 commit df84e47
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
=== Edge

* Allow HTML tags with quoted attributes to be inside link text. To do this, I had to remove the possibility that attributes in HTML tags could have spaces around the equals sign or unquoted attributes. This change also greatly expands the complexity of the state machine, so compilation takes a long time. Sorry.

=== 4.1.9 / February 20, 2009

* Make compatible with Ruby 1.9.
Expand Down
2 changes: 1 addition & 1 deletion ext/redcloth_scan/redcloth_common.rl
Expand Up @@ -70,7 +70,7 @@
Q2Attr = [^"]* ;
UnqAttr = ( space | [^ \t\r\n<>"'] [^ \t\r\n<>]* ) ;
Nmtoken = NameChar+ ;
Attr = NameAttr space* "=" space* ('"' Q2Attr '"' | "'" Q1Attr "'" | UnqAttr space+ ) space* ;
Attr = NameAttr "=" ('"' Q2Attr '"' | "'" Q1Attr "'" ) space* ;
AttrEnd = ( NameAttr space* "=" space* UnqAttr? | Nmtoken ) ;
AttrSet = ( Attr | Nmtoken space+ ) ;

Expand Down
32 changes: 20 additions & 12 deletions ext/redcloth_scan/redcloth_inline.rl
Expand Up @@ -7,13 +7,27 @@

machine redcloth_inline;

# html
start_tag_noactions = "<" Name space+ AttrSet* (AttrEnd)? ">" | "<" Name ">" ;
empty_tag_noactions = "<" Name space+ AttrSet* (AttrEnd)? "/>" | "<" Name "/>" ;
end_tag_noactions = "</" Name space* ">" ;
any_tag_noactions = ( start_tag_noactions | empty_tag_noactions | end_tag_noactions ) ;

start_tag = start_tag_noactions >X >A %T ;
empty_tag = empty_tag_noactions >X >A %T ;
end_tag = end_tag_noactions >X >A %T ;
html_comment = ("<!--" (default+) :>> "-->") >X >A %T;

# links
mtext_noquotes = mtext -- '"' ;
quoted_mtext = '"' mtext_noquotes '"' ;
mtext_including_quotes = (mtext_noquotes ' "' mtext_noquotes '" ' mtext_noquotes?)+ ;
link_says = ( C_noactions "."* " "* ((quoted_mtext | mtext_including_quotes | mtext_noquotes) -- '":') ) >A %{ STORE("name"); } ;
link_says_noquotes_noactions = ( C_noquotes_noactions "."* " "* ((mtext_noquotes) -- '":') ) ;
link = ( '"' link_says '":' %A uri %{ STORE_URL("href"); } ) >X ;
link_text_char = (default - [ "<>]) ;
link_text_char_or_tag = ( link_text_char | any_tag_noactions ) ;
link_mtext = ( link_text_char+ (mspace link_text_char+)* ) ;
quoted_mtext = '"' link_mtext '"' ;
link_mtext_including_tags = ( link_text_char_or_tag+ (mspace link_text_char_or_tag+)* ) ;
mtext_including_quotes = (link_mtext ' "' link_mtext '" ' link_mtext?)+ ;
link_says = ( C_noactions "."* " "* (quoted_mtext | mtext_including_quotes | link_mtext_including_tags ) ) >A %{ STORE("name"); } ;
link_says_noquotes_noactions = ( C_noquotes_noactions "."* " "* ((link_mtext) -- '":') ) ;
link = ( '"' link_says :>> '":' %A uri %{ STORE_URL("href"); } ) >X ;
link_noquotes_noactions = ( '"' link_says_noquotes_noactions '":' uri ) ;
bracketed_link = ( '["' link_says '":' %A uri %{ STORE("href"); } :> "]" ) >X ;

Expand Down Expand Up @@ -57,12 +71,6 @@
quote2 = ('"' >X %A ( mtext_inside_quotes - (mtext_inside_quotes html_tag_up_to_attribute_quote ) ) %T :> '"' ) ;
multi_paragraph_quote = (('"' when starts_line) >X %A ( chars -- '"' ) %T );

# html
start_tag = ( "<" Name space+ AttrSet* (AttrEnd)? ">" | "<" Name ">" ) >X >A %T ;
empty_tag = ( "<" Name space+ AttrSet* (AttrEnd)? "/>" | "<" Name "/>" ) >X >A %T ;
end_tag = ( "</" Name space* ">" ) >X >A %T ;
html_comment = ("<!--" (default+) :>> "-->") >X >A %T;

# glyphs
ellipsis = ( " "? >A %T "..." ) >X ;
emdash = "--" ;
Expand Down
8 changes: 7 additions & 1 deletion test/links.yml
Expand Up @@ -282,4 +282,10 @@ name: with caps in the title
in: |-
"British Skin Foundation (BSF)":http://www.britishskinfoundation.org.uk
html: |-
<p><a href="http://www.britishskinfoundation.org.uk" title="BSF">British Skin Foundation</a></p>
<p><a href="http://www.britishskinfoundation.org.uk" title="BSF">British Skin Foundation</a></p>
---
name: containing HTML tags with quotes
in: |-
"<r:attachment:image name="checkmark.gif" alt="Apply online" />*apply online*":/admissions/apply/
html: |-
<p><a href="/admissions/apply/"><r:attachment:image name="checkmark.gif" alt="Apply online" /><strong>apply online</strong></a></p>

0 comments on commit df84e47

Please sign in to comment.