A user struggles with importing posts using Markdown in Discourse, as the imported content displays raw markdown syntax instead of formatted text. Despite trying various solutions like changing the cook_method and using Rebuild HTML, the issue persists. After investigation, it’s discovered that the raw and cooked fields differ between a working and non-working post, indicating the post isn’t being properly processed. The issue is ultimately resolved by toggling the Topic Ratings Plugin off and on, suggesting a plugin-related conflict. n1bff shares the solution, noting that the plugin’s state affects Markdown rendering. Canapin and renato offer troubleshooting advice, including checking database fields and rebaking posts. pfaffman asks about editing behavior, which helps confirm the issue. n1bff concludes that the plugin interference was the root cause.
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!