Skip to content

Commit

Permalink
fix raw tag parser to allow multi-line html
Browse files Browse the repository at this point in the history
  • Loading branch information
SampsonCrowley committed May 6, 2019
1 parent 208ade8 commit e9c5dc8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ Here are the names of the defaults:
}
```

## Raw HTML

If you need to include raw html, you can wrap raw content in `<raw>` tags

```html
<raw>
<button></button>
<asdf></asdf>
</raw>
```

This is a feature intended for advanced users. You will be responsible for ensuring all markup between `<raw>` tags is valid. All content after an opening `<raw>` tag will be inserted "As Is" until the next closing `</raw>` tag.

This means that `<raw>` tags CANNOT be nested


## Programmatic Use

The Inky parser can be accessed directly for programmatic use.
Expand Down
2 changes: 1 addition & 1 deletion lib/inky.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def transform_doc(elem)
def self.extract_raws(string)
raws = []
i = 0
regex = %r(< *raw *>(.*?)</ *raw *>)
regex = %r((?:\n *)?< *raw *>([\s\S]*?)</ *raw *>(?: *\n)?)i
str = string
while raw = str.match(regex)
raws[i] = raw[1]
Expand Down
9 changes: 9 additions & 0 deletions spec/cases/raw/raw_multiple_lines_and_tags.inky
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<raw>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>
</raw>
<button href="#">Test</button>
<raw>
<asdf>more raw content</asdf>
</raw>
</div>
7 changes: 7 additions & 0 deletions spec/cases/raw/raw_multiple_lines_invalid_closing_tag.inky
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
<raw>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>
</raw>
<button href="#">Test</button>
</raw>
</div>
6 changes: 6 additions & 0 deletions spec/cases/raw/raw_multiple_lines_single_tag.inky
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<raw>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>\
<button href="#">Test</button>
</raw>
</div>
1 change: 1 addition & 0 deletions spec/cases/raw/raw_single_line_multiple_tags.inky
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div><raw><<LCG ProgramTG LCG Coupon Code Default='246996'>></raw><button href="#">Test</button><raw><asdf>more raw content</asdf></raw></div>
1 change: 1 addition & 0 deletions spec/cases/raw/raw_single_line_single_tag.inky
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<raw><<LCG ProgramTG LCG Coupon Code Default='246996'>></raw>

0 comments on commit e9c5dc8

Please sign in to comment.