For example a post might be **some text here in bold** and something else here
After importing Discourse shows it verbatim like that, not using the ** Markdown syntax to bold the “some text here in bold” part. And weirdly also if I try to edit such a post using the normal Discourse GUI, it will ignore any formatting.
The import script uses cook_method: Post.cook_methods[:raw_html],
I also tried cook_method: Post.cook_methods[:regular],
without any visible change.
How can I make Discourse recognise Markdown when importing data?
I took one of the offending posts, went into its edit mode, copied the contents and made a new posts with it. The new posts uses the Markdown formatting, I see bold text and a link with a title.
In the database their raw is identical but their cooked is not.
SELECT (SELECT raw FROM posts WHERE id = 13846) = (SELECT raw FROM posts WHERE id = 13735); → t
SELECT (SELECT cooked FROM posts WHERE id = 13846) = (SELECT cooked FROM posts WHERE id = 13735); → f
Clicking “Rebuild HTML” on the badly formatted posts does no change.
/logs/ shows nothing at this time (only older warnings and errors).
When I edit it, the preview looks correct, the Markdown formatting is applied there (e.g. “foo”). Once I save, the post will still show the formatting characters (e.g. “**foo**”)
/var/www/discourse$ bundle exec rails c
Loading production environment (Rails 7.0.7)
irb(main):001:0> Post.update_all(cook_method: Post.cook_methods[:regular])
=> 13809
irb(main):002:0>
Done! Sadly no change.
But I solved it. And I am sorry for not mentioning what plugins I had installed as they can interfere…
I have the Topic Ratings Plugin installed and enabled for the category into which my imports go.
On a whim I disabled the plugin and tried again to edit a “broken” post. Now upon saving, the Markdown formatting was used for fancy rendering. I re-enabled the plugin and tried again with success. I imported new posts and it also renders the posts correctly now (using cook_method: Post.cook_methods[:regular]).
I have no idea what is/was going on there but it seems to have been fixed by toggling the Topic Ratings Plugin off and on again.
Thank you all for the great suggestions and problem hunting!