0

I am migrating a discussion forum from OSQA to Discourse. I am stuck at one problem in doing so.

Since its a discussion forum for coding related topics, much of the posts contains code snippets. Many of the users being beginners do not format their code properly i.e. do not indent while including a code block or use back-ticks before starting a code-block and after ending one.

Now, such unformatted code snippet worked in OSQA but not in Discourse.

Discourse hides <iostream> much like stackoverflow (perhaps considering the former as an HTML tag?).

Also, if a user directly pastes his/her code, the the formatting starts once an indentation starts.

Example:

#include <stdio.h>

int main()
{
    // formatting starts from here as prinf("Hi"); is indented.
    // the first two statements are not formatted as they have not been indetned.
    printf("Hi");
    return 0;
}

I hope you all get the idea. It looks way bizarre. Let me add a image for more clarity.

enter image description here

Did you see what I was trying to say?

Now, Discourse will not allow to post such posts. But what about the imported 20k+ posts ?

How do I detect if the posts has proper markdown or not? Please help me here :(

Alfarhan Zahedi
  • 141
  • 2
  • 13
  • How are you doing the import? Or has it already been done and you've noticed they're malformatted? How is Rails involved? – Schwern Mar 22 '19 at 22:48

1 Answers1

2

I don't think it's a matter of users not formatting their code properly, but rather than OSQA and Discourse having different formatting rules. When importing OSQA posts to Discourse you'll have to translate their formatting.

OSQA appears to be using Pegdown.

We leverage https://github.com/sirthias/pegdown for our Markdown parsing and have enabled the following: Extensions.ABBREVIATIONS | Extensions.FENCED_CODE_BLOCKS. We also do autolinking of both protocol and non-protocol urls, and email addresses. We also support @ mentions and standard code blocks that automatically get syntax highlighting.

Discourse allows three formats, Common Markdown as well as a subset of BBCode and also HTML.

You'll have to translate the formatting from OSQA to Discourse. Discourse has import scripts for many different systems, but not OSQA. You may want to write one using the existing scripts as examples.

Discourse hides much like stackoverflow (perhaps considering the former as an HTML tag?).

This is likely because Discourse allows HTML. You'll have to escape all the HTML entities for them to display correctly in Discourse.

Also, if a user directly pastes his/her code, the the formatting starts once an indentation starts.

To avoid this, replace the indentation with &nbsp;.

Schwern
  • 153,029
  • 25
  • 195
  • 336