Hello. Is there any way to create tables in posts? Price tables for example. I'm already tried to use markdown code, bbcode, html code, all of them didn't work. It show as text and don't translated to code.
Tables in posts
That's correct, there's no table markup by default. You'd need an admin interface to add custom BBCodes or an extension that enables HTML.
The current implementation of Flarum's Markdown does not allow to easily add tables. Messages are stored in the database is already compiled into HTML and for editing it used reverse compilation. But I think it can try to write an extension that will produce a compilation Markdown to HTML with JavaScript in client browser. Then it can add tables. Maybe later I'll try to write such an extension.
Balancer You could also try extending the current implementation to add Github's style of tables. They don't allow for extreme styling or customization, but they help organize tabular data when it needs to be presented.
- Edited
Balancer Messages are stored in the database is already compiled into HTML and for editing it used reverse compilation.
Actually it's XML; You can get the original message by loading it into a DOMDocument and reading its textContent, or by stripping tags/decoding XML entities, which is functionally equivalent.
I've just published a plugin for s9e\TextFormatter (which powers Flarum's markup) that handles the same kind of pipe tables used by PHP Markdown Extra and GitHub-flavored Markdown. @Toby Is that something you want to enable in the Markdown extension? If so you need to upgrade to 0.8.4 and load the PipeTables
plugin. Since it's implemented as its own plugin I guess it could be enabled via a separate extension for people who want pipe tables but no Markdown. I don't know whether it's worth making an extension for it.
References:
Toby Judging by this commit it's something like 1.8 KB minified and 0.7 KB gzipped.
- Edited
JoshyPHP Too much. Sorry.
That's a joke, couldn't not do it ?
JoshyPHP BlackSheep Not really. I think 0.7 KB is acceptable. The question is whether we do actually want to have it on by default, or as an option in the Markdown extension, or as a separate extension. Any thoughts anyone?
I think that having it as an extension is fine. Ideally something that's bundled with Flarum but disabled by default.
If you make an extension for it, you may want to consider enabling the tables BBCodes in addition to the PipeTables plugin. The PipeTables plugin will create the relevant tags for it, all you have to do is enable them to be used in BBCodes if the BBCodes plugin is enabled. Maybe something like that:
if (isset($configurator->BBCodes))
{
$configurator->BBCodes->add('TABLE');
$configurator->BBCodes->add('THEAD');
$configurator->BBCodes->add('TBODY');
$configurator->BBCodes->add('TR');
$configurator->BBCodes->add('TD', ['defaultAttribute' => 'align']);
$configurator->BBCodes->add('TH', ['defaultAttribute' => 'align']);
}
The tables extension would need to call Illuminate\Events\Dispatcher::listen()
with a priority that guarantees it'll be called after the BBCodes extension.
JoshyPHP Yep, let's keep the extension system ?
What about tables. Exists any way to enable it or exists any extension for this purpose?
Thanks in advance ?
Is there any official markup in commonmark for tables?
- Edited
If it can be done with css only, I'll work on a few bbcode varieties.
This looks doable:
https://webdesignerhut.com/pure-css-responsive-tables/
The question is what should the most common dimensions be, column and width wise ? 5 x 5, 6 x 6 up to 12 x 12?
Think it would be better to have someone with more experience making extensions that handle js to create a csv, xls plugin or even a embeded iframe of Google docs/sheets whatever.
https://github.com/0E800/flarum-ext-bbcode-tables
Seems to work nicely.