Having raw_html in a system created post

I am attempting to create system managed posts that utilize raw html on a website plugin (in development). Looking at the documentation and various posts, I think I took the right approach, however the preprocessor still <code>'s out various parts of my post.

This is how it turns out:

This is how it should turn out (I edited in browser):

This is the code I am using to create the post:

post = PostCreator.new(Discourse.system_user,
    title: mmbill.getTitle(),
    raw: cooked,
    cooked: cooked,
    cook_methods: Post.cook_methods[:raw_html],
    archetype: 'regular',
    created_at: createdAt,
    skip_validations: true,
    category: Mmbill.getCatId(),
    is_warning: false,
    meta_data: { mm_type: 'bill', mm_id: final[:bill_id] },
    shared_draft: false,
    topic_opts: {}
 )

Thank you for any help you have to offer!

I’ve run into a similar problem before where the code that creates the raw post content has extra spaces at the beginning of some of its lines. Since the raw output is interpreted as Markdown, extra spaces at the beginning of a line will be considered to be a code block. Depending on how you are creating the raw content, you might be able to fix the problem by reformatting your HTML.

3 Likes

Looks like unnecessary leading spaces in the lines to me. Remove the leading spaces from those lines to correct the problem.

2 Likes

This was it thanks! It is now formatted as written in html. The issue was ruby included the tabs that I used to format my code inside of the string.

It decided to remove the iframe, but I think that has to do with the admin iframe settings.

2 Likes