Skip to content

Commit fb9a5a1

Browse files
committed
ensure regexp in tables is rendered correctly
1 parent 34b747a commit fb9a5a1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/prmd/templates/schemata/helper.erb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@
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+
pattern = value['pattern'].gsub(/\|/, '|').gsub(/\[/, '[')
142145

143146
description += "<br/> **pattern:** <pre>#{pattern}</pre>"
144147
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>\^&#91;a-z\]\(\?:&#91;a-z\]&#x7c;\)\+&#91;a-z\]\$/
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-z]&#x7c;)+[a-z]$'
127127
},
128128
'option1' => {
129129
'properties' => {

0 commit comments

Comments
 (0)