Luicid is experiencing an issue where HTML content posted via the API (posts.json) displays as plain text in the edit composer, unlike when posting directly via the form.
Canapin explained that the raw content composer displays HTML tags in plain text. To avoid this, Canapin suggested replacing HTML tags with line breaks (\n) to create paragraphs.
Luicid confirmed that replacing <p> and <br> tags with \n would resolve the issue. Canapin provided an example of sanitizing imported HTML content by replacing paragraphs with line breaks.
Regarding adding mentions via the API, Luicid asked for help and Canapin provided a JSON payload example that successfully creates a working mention. However, Luicid later realized that the issue was due to using a lowercase username instead of the exact case-sensitive username.
Additionally, pfaffman suggested using an import script for bulk data imports, while Luicid explained his preference for using a Python script for synchronizing data. Canapin also corrected Luicid that mentions should work even with varying capitalization.
Note: paragraphs are created automatically depending on the context when the post is processed, so there’s no need to add these tags to your query raw input.
Ok, I see. So the only option to have a clean display when users edit their migratedHTMLposts via the API is to replace all <p> and <br> tags with \n if I understand correctly?
If you try to sanitize some imported HTML content, I suppose you can replace paragraphs with line breaks as well, so you’ll be sure there are line breaks, and the post will be processed properly.
Ok, thank you
Last question:
Is there any way you can tell me how to add a mention, like this one: @Canapin, in a post via the API? I tried using @username in the raw field, but it doesn’t work.
Honestly, I created a POC with an import script in Ruby, but since I need to synchronize data for several days between an old solution and Discourse, I prefer running a simple Python script. It’s much faster to set up and maintain. Additionally, it’s consistent, as I scrape the old data with Python. The previous provider won’t grant us access to the database, so I scraped all the content into a database.
But of course it’s a better solution if it’s a simple migration