mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: site setting to allow html tables (which may come from imports)
(allow_html_tables , disabled by default)
This commit is contained in:
@@ -475,7 +475,7 @@ Discourse.Dialect = {
|
||||
|
||||
**/
|
||||
replaceBlock: function(args) {
|
||||
this.registerBlock(args.start.toString(), function(block, next) {
|
||||
var fn = function(block, next) {
|
||||
|
||||
var linebreaks = dialect.options.traditional_markdown_linebreaks ||
|
||||
Discourse.SiteSettings.traditional_markdown_linebreaks;
|
||||
@@ -565,7 +565,13 @@ Discourse.Dialect = {
|
||||
var emitterResult = args.emitter.call(this, contentBlocks, match, dialect.options);
|
||||
if (emitterResult) { result.push(emitterResult); }
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
if (args.priority) {
|
||||
fn.priority = args.priority;
|
||||
}
|
||||
|
||||
this.registerBlock(args.start.toString(), fn);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
52
app/assets/javascripts/discourse/dialects/table_dialect.js
Normal file
52
app/assets/javascripts/discourse/dialects/table_dialect.js
Normal file
@@ -0,0 +1,52 @@
|
||||
var flattenBlocks = function(blocks) {
|
||||
var result = "";
|
||||
blocks.forEach(function(b) {
|
||||
result += b;
|
||||
if (b.trailing) { result += b.trailing; }
|
||||
});
|
||||
|
||||
// bypass newline insertion
|
||||
return result.replace(/[\n\r]/g, " ");
|
||||
};
|
||||
|
||||
var emitter = function(contents) {
|
||||
// TODO event should be fired when sanitizer loads
|
||||
if (window.html4 && window.html4.ELEMENTS.td !== 1) {
|
||||
window.html4.ELEMENTS.table = 0;
|
||||
window.html4.ELEMENTS.tbody = 1;
|
||||
window.html4.ELEMENTS.td = 1;
|
||||
window.html4.ELEMENTS.thead = 1;
|
||||
window.html4.ELEMENTS.th = 1;
|
||||
window.html4.ELEMENTS.tr = 1;
|
||||
}
|
||||
return ['table', {"class": "md-table"}, flattenBlocks.apply(this, [contents])];
|
||||
};
|
||||
|
||||
var tableBlock = {
|
||||
start: /(<table>)([\S\s]*)/igm,
|
||||
stop: /<\/table>/igm,
|
||||
rawContents: true,
|
||||
emitter: emitter,
|
||||
priority: 1
|
||||
};
|
||||
|
||||
var init = function(){
|
||||
if (Discourse.SiteSettings.allow_html_tables) {
|
||||
Discourse.Markdown.whiteListTag("table");
|
||||
Discourse.Markdown.whiteListTag("table", "class", "md-table");
|
||||
Discourse.Markdown.whiteListTag("tbody");
|
||||
Discourse.Markdown.whiteListTag("thead");
|
||||
Discourse.Markdown.whiteListTag("tr");
|
||||
Discourse.Markdown.whiteListTag("th");
|
||||
Discourse.Markdown.whiteListTag("td");
|
||||
Discourse.Dialect.replaceBlock(tableBlock);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (Discourse.SiteSettings) {
|
||||
init();
|
||||
} else {
|
||||
Discourse.initializer({initialize: init, name: 'enable-html-tables'});
|
||||
}
|
||||
|
||||
@@ -243,4 +243,20 @@ blockquote > *:last-child {
|
||||
}
|
||||
|
||||
|
||||
table.md-table {
|
||||
thead {
|
||||
border-bottom: 2px solid lighten($primary, 80%);
|
||||
th {
|
||||
text-align: left;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
td,th {
|
||||
padding: 3px 3px 3px 10px;
|
||||
}
|
||||
tr {
|
||||
border-bottom: 1px solid lighten($primary, 80%);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user