Discourse.Dialect.postProcessText() handle is called for every line in a post. Is there any handle that provides the entire post, perhaps as an array of text lines?
My first question is why? What do you need to post process that is not done one line at a time?
I’m experimenting with writing a plugin for tables. I need to be able to be aware of what the first line was, and, more importantly, the next line. Here is a standard format for a table:
Header | Header ============ Value | Value
For the headers, I need to be able to detect that the next line is a bar, and give them the appropriate format.
That’s going to be an ambitious plugin to write Ideally it needs to be written as a
Discourse.Dialect which would be very complicated as it has multiple lines and states.
There is currently no API to get at the final string, but I wouldn’t be against adding one if you want to submit a PR similar to
addPostProcessor that would run after everything happened.
That would be perfect! However I don’t think I’ll be able to pull that off - I don’t know how Discourse works well enough, and I’m no master at JS yet ;). If you or someone else ends up doing it, I would love to see how it works so that I can learn :).
If you want to give me some pointers I’ll do my best.
Getting started with Discourse’s markdown parser is Hell. Capital H.
discourse/dialects/dialect.js and step through the code as it – simply start composing a post and type anything.
This file defines the Discourse-specific Markdown dialect as well as a bunch of helper functions to process bbcode-style block tags and the like, which are defined in the other files in the same folder. The Markdown parser itself lives in
assets/better_markdown.js, and it contains all of the Gruber-style markdown handlers.
You could theoretically write your table parser as a pre-processor that itself calls the parser to render each cell to HTML.
By the way, be prepared to do a lot of beancounting and manual string searching and splitting. JS’s regex parser has less features than a particularly uninteresting rock; most importantly, recursive pattern re-execution and certain assertions are just missing.
Wow, I had no idea you could use Chrome’s debugger like that, that’s awesome! Thank you! .
I already wrote a working prototype parser, hopefully I can just integrate it straight into Discourse :).
EDIT: Is there any way to run Discourse in dev mode without running it locally?
If it’s local or not technically doesn’t matter, but you cannot use the Docker install method since the launcher doesn’t install the development dependencies.
As you can probably see in my screenshot, I’m working on a Windows PC, but the Discourse instance that’s open in the debugger is running on a Linux box in the basement. The dev server (
rails s) is running in a PuTTY window in the background while my editor is running on Windows, accessing files via a mounted Samba share.
If you don’t already have a dedicated server in your household (that Linux box is also my mailserver, router, firewall, VCR…), you can always set up a virtual machine on your main computer and install the latest Ubuntu server with Ruby, PostgreSQL, Redis and Samba. I tweaked Postgres’ auth settings a bit to give my default user superuser access, but I don’t think there’s any more to be done in terms of system setup. Altho, if you’re going with Ubuntu, you may need to install
gcc and a bunch of libraries and
-dev packages to successfully compile certain gems’ native extensions.
Everything else can be done without root privileges, i.e. clone Discourse,
gem install bundler,
bundle install – but I’m probably being optimistic.