Skip to content

Commit acecc09

Browse files
authored
Merge pull request #347 from hannesfostie/hf/backtick-bug-fix
ensure regexp in tables is rendered correctly
2 parents 34b747a + 84f89c2 commit acecc09

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/prmd/templates/schemata/helper.erb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@
137137
end
138138

139139
if value['pattern']
140-
# Prevent the pipe regex pattern characters from being interpreted as markdown table:
141-
pattern = value['pattern'].gsub(/\|/, '|')
140+
# Prevent the pipe regex pattern characters from being interpreted
141+
# as markdown table.
142+
# Prevent instances of []() in regexes from being rendered as
143+
# markdown links.
144+
# Prevent patterns with * being rendered as having emphasis
145+
# or being an unordered list.
146+
pattern = value['pattern']
147+
.gsub(/\|/, '|')
148+
.gsub(/\[/, '[')
149+
.gsub(/\*/, '*')
142150

143151
description += "<br/> **pattern:** <pre>#{pattern}</pre>"
144152
end

test/commands/render_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_render_for_example_as_an_array
5151
end
5252

5353
def test_render_for_regex_patterns_with_pipes
54-
expression = /<pre>\(\^first\$&#x7c;\^second\$\)<\/pre> \| \`"second"\` \|\n/
54+
expression = /<pre>\^&lbrack;a-z\]\(\?:&lbrack;a&vert;b\]\)\&ast;&lbrack;a-z]&ast;\$/
5555
markdown = render
5656
assert_match expression, markdown
5757
end
@@ -123,7 +123,7 @@ def data
123123
'description' => 'A string with a regex pattern applied to it.',
124124
'type' => 'string',
125125
'example' => 'second',
126-
'pattern' => '(^first$|^second$)'
126+
'pattern' => '^[a-z](?:[a|b])*[a-z]*$'
127127
},
128128
'option1' => {
129129
'properties' => {

0 commit comments

Comments
 (0)