Ask coding questions

← Back to all posts
how to get replit markdown in python or django?
RYANTADIPARTHI (6048)

i just wanted to know how to get replit markdown in python or django. By that i mean, it should include the exact features of the replit markdown. Like code blocks for languages, bold, italics, and more.

Thanks!

Comments
hotnewtop
ch1ck3n (2393)

well oldwizard's answer is right but theres a better method

import markdown2 # the new updated version
my_content = "# whatever"
my_html = markdown2.markdown(my_content) # you don't need to create a object

print(my_html) # <h1>whatever</h1>
RYANTADIPARTHI (6048)

@ch1ck3n This works, but there's a problem. The problem is, anything I put in the my_content section, comes out in one code block. This means If i group anything with code, it shows up all joined in as a code block. Here's an example

So as you see in the screenshot, i put the header something, which is supposed to output:

Something

but, in the screen shot, it gets grouped with the code

next, the bold is also supposed to be bold and separate from the code block. So please let me know if you need further explanation. If you don't, please let me know an alternate option, or how to fix this.

Thanks!

ch1ck3n (2393)

@RYANTADIPARTHI i don't quite understand the problem??? what do you mean y "grouped"

RYANTADIPARTHI (6048)

@ch1ck3n did you look at the screenshot closely?

Notice the grey background? Notice how the bold and the header is also in the background? In replit markdown, that doesn't happen. I want the # something and **bold** to be separate. Isn't that replit markdown? The code should be in the grey background, and the other elements should be separate. Shouldn't they?

Please let me know if you need further explanation.

ch1ck3n (2393)

@RYANTADIPARTHI so you want the backgorund of the code to be gray

RYANTADIPARTHI (6048)

@ch1ck3n no, no. You don't seem to be getting it. Please look at the image closely. Do you see the gray background all over?

Do you see all over # something, the code and the **bold** right?

Does that seem correct? Does it look like the gray background should be all over? In replit markdown, gray background should only be in code blocks right? Like when you put `python?

But in this case, it's all over. That's incorrect. So could you fix that?

Please let me know if you need further explanation

ch1ck3n (2393)

@RYANTADIPARTHI, why can't you make the code blocks background grayer

RYANTADIPARTHI (6048)

@ch1ck3n i didn't say anything about making code blocks grayer or anything. Did you read my comments closely? alright, do you know replit markdown?

If you do, you would know, the gray background would only be on code blocks right? the gray will not be on anything else. Only on code blocks. The rest of them should be normal right? Without any background right? Like when you do bold, does it have a background? No. But if you look at mine, the background is not only on the code, but is also on everything else. Could you fix that? Or do you need further explaining?

RYANTADIPARTHI (6048)

@ch1ck3n sorry, it's a really huge repl, and everything's a mess, and all. Can't really send it. nothing will make sense. But please read my comments carefully, and look at the screenshot. You will understand everything.

If you don't, please let me know. I will explain.

ch1ck3n (2393)

@RYANTADIPARTHI i understand your issue

can you send me a screenshot again, just the whole page now

RYANTADIPARTHI (6048)

@ch1ck3n that is the whole page, I'll make it bigger.

can you see it now? Please let me know if you can't. If you want, I'll also show you the code I'm using. Do you want that?

Please let me know if you need more explanation, or if you code, or screenshots or anything. Just ask if you need anything.

Thanks!

P.S: I won't be answering for a few hours after this comment, I'll answer after a few hours, I'm going to be AFK. So if you have an answer, you can comment now, but I'll respond later. we can discuss when I'm back after a few hours again.

RYANTADIPARTHI (6048)

@ch1ck3n hi, i made an example repl, it's not the real one, but I put in the same code, and all. I'll invite you and oldwizard209 to it. It's kind of slow for me, but maybe not for you. You can fix it in there.

OldWizard209 (1643)

Markdown is universal, meaning it's there in most websites that allow you to post things because markdown is literally turning a few symbols into html code that can be parsed by any browser. So the way you do that in Django is pretty simple as well.

When you run a Django app, you most likely render a template file containing the HTML code. All you have to do is convert markdown into HTML, and put render that HTML into the template file. You can do that using the markdown package. Install it into your file using the pip command and use it like this:

import markdown as md
markdown_renderer = md.Markdown() # Create a markdown object.
markdown_renderer.convert("*This text will be italicized* ")
# .convert() will return HTML code like:
# <p><em>This text will be italicized</em><p> 

ALl you need to do down is to put this HTML code into the template. Hope I was helpful

:P

RYANTADIPARTHI (6048)

@OldWizard209 hi, this is resulting in the same problem as ch1ck3n's answer. please look at that comment for more details, and my explanation. Thanks!

OldWizard209 (1643)

Hey, I read all the comments but i still don't get the problem just like @ch1ck3n. What you can do is invite me and @chicken to a team and explain the problem more explicitly. I know you won't respond for wile but thats alright. I am live all the time at replit. @RYANTADIPARTHI

OldWizard209 (1643)

Hey, I am replying again. Try to fix the code block issue by using a horizontal rule. In markdown, you would do that like:

# Something
*** 
`

<CODE>

`
***
**bold**

@RYANTADIPARTHI

RYANTADIPARTHI (6048)

@OldWizard209 hi, i made an example repl, it's not the real one, but I put in the same code, and all. I'll invite you and chicken to it. It's kind of slow for me, but maybe not for you. You can fix it in there.

OldWizard209 (1643)

hey, i am working on it right now. can you join? @RYANTADIPARTHI

RYANTADIPARTHI (6048)

@OldWizard209 yes, i'm in right now. Can you join?