use custom whitelister for tables
This commit is contained in:
parent
f7b686117b
commit
0e391a72a1
|
@ -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]'
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -679,10 +679,39 @@ 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>
|
||||||
|
|
Loading…
Reference in New Issue