use custom whitelister for tables

This commit is contained in:
Sam 2017-06-28 16:08:20 -04:00
parent f7b686117b
commit 0e391a72a1
2 changed files with 56 additions and 17 deletions

View File

@ -4,18 +4,28 @@ export function setup(helper) {
// this is built in now // this is built in now
// TODO: sanitizer needs fixing, does not properly support this yet // TODO: sanitizer needs fixing, does not properly support this yet
// we need a custom callback for style handling
helper.whiteList({
custom: function(tag,attr,val) {
if (tag !== 'th' && tag !== 'td') {
return false;
}
if (attr !== 'style') {
return false;
}
return (val === 'text-align:right' || val === 'text-align:left' || val === 'text-align:center');
}
});
helper.whiteList([ helper.whiteList([
'table', 'table',
'th[style=text-align:right]',
'th[style=text-align:left]',
'th[style=text-align:center]',
'tbody', 'tbody',
'thead', 'thead',
'tr', 'tr',
'th', 'th',
'td', 'td',
'td[style=text-align:right]',
'td[style=text-align:left]',
'td[style=text-align:center]'
]); ]);
} }

View File

@ -679,20 +679,49 @@ HTML
expect(quote.cooked).not_to include('[quote') expect(quote.cooked).not_to include('[quote')
end end
it "supports tables" do
markdown = <<~MD
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
MD
expected = <<~HTML
<table>
<thead>
<tr>
<th>Tables</th>
<th style="text-align:center">Are</th>
<th style="text-align:right">Cool</th>
</tr>
</thead>
<tbody>
<tr>
<td>col 3 is</td>
<td style="text-align:center">right-aligned</td>
<td style="text-align:right">$1600</td>
</tr>
</tbody>
</table>
HTML
expect(PrettyText.cook(markdown)).to eq(expected.strip)
end
it "do off topic quoting with emoji unescape" do it "do off topic quoting with emoji unescape" do
topic = Fabricate(:topic, title: "this is a test topic :slight_smile:") topic = Fabricate(:topic, title: "this is a test topic :slight_smile:")
expected = <<HTML expected = <<~HTML
<aside class="quote" data-topic="#{topic.id}" data-post="2"> <aside class="quote" data-topic="#{topic.id}" data-post="2">
<div class="title"> <div class="title">
<div class="quote-controls"></div> <div class="quote-controls"></div>
<a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/twitter/slight_smile.png?v=5" title="slight_smile" alt="slight_smile" class="emoji"></a> <a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/twitter/slight_smile.png?v=5" title="slight_smile" alt="slight_smile" class="emoji"></a>
</div> </div>
<blockquote> <blockquote>
<p>ddd</p> <p>ddd</p>
</blockquote> </blockquote>
</aside> </aside>
HTML HTML
expect(cook("[quote=\"EvilTrout, post:2, topic:#{topic.id}\"]\nddd\n[/quote]", topic_id: 1)).to eq(n(expected)) expect(cook("[quote=\"EvilTrout, post:2, topic:#{topic.id}\"]\nddd\n[/quote]", topic_id: 1)).to eq(n(expected))
end end