Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Markdown: A better format than HTML
Lecture: Converting markdown to HTML

Login or purchase this course to watch this video and the rest of the course contents.
0:00 we've seen our page looks pretty awesome, doesn't it? No, it doesn't. We have to convert this to HTML. How do we do that?
0:07 Well, you definitely don't want to go and try to convert it yourself in Python.
0:13 There's many libraries, and of course, there's a great library here as well. So let's go over to our requirements, Doc here.
0:20 And let's put in one called Mark down to. There's a couple of different mark town libraries we can use.
0:27 But this one didn't work Well, I'll just go and let pie term install that Now. Over here, we've got our HTML is just the page contents.
0:37 That's not really what we want. We want to do a little bit more than that. So what we're gonna dio is we're gonna add a function.
0:44 It's gonna add a function of this thing for the moment. We're going to do something pretty different later.
0:48 But for now, I'm just gonna do it here, converge, do mark down. And I guess we could say returns a string over here.
0:57 We're going to write the code to convert it to mark down, and I just say it's gonna be nothing and it's going to take wouldn't pass it over to take some contents here So we can say itself dot convert to mark down and will pass over the page contents.
1:13 It's going to take that and convert it well from markdown over to HTML.
1:18 And it might not surprise you that were going to use mark down to the using marked down to is pretty easy.
1:28 In fact, we could actually do this in one line. We could say, Actually, this is not we want to call it when you call it MD text or something like that.
1:36 It is not yet. HTML. We're gonna go over here and we could just say HTML equals Mark down to all marked down.
1:43 We give it the text, we can pass some extra features to turn on. We're gonna not do that for the minute, once a safe mode.
1:52 But now I'm going to say true later.
1:54 We're gonna want to really relax that a little bit, and then we just return the HTML and I think this is just complaining. That could be static.
2:02 I don't really want it to be started for the moment.
2:03 All right, let's give this a shot that one change up here where we said, instead of just trying to show the contents, were gonna take the contents and convert them to mark down and then show them that would be great.
2:15 It's gonna break the other pages, but right, that's I think that's OK. We'll deal that a second, right to see if it works. 00 that is so sweet.
2:26 Now, you might be wondering maybe why these Look, you know, like this Red Code thing here and this this looks like that and what not?
2:36 It's cause we've already added some CSS styles to render code in a certain way. So it I can't remember if I added it or if it came included.
2:45 But either way, if you have code blocks, then the CSS styles are already there is not some sort of magic that did that.
2:52 But otherwise, this This looks really good and there's no way for us to break our page because, you know, worst case may we could leave something bold farther than we intended, but for the most part, this is it.
3:06 This is really, really good. I think this came out great, and you could see that It's super, super easy to dio to convert this over Now.
3:13 There's a lot of things we need to do. We're not done. It might look Oh, like Oh, yeah, we're We've done this and it's great.
3:19 And now we're just ready to call this section done. But there's a couple of things that we want to focus on in order to get this to work better.
3:26 First, we're going to need a proper editor, right?
3:31 Even as somebody who is an expert in marked down, it would be nice if I could highlight this and hit command be.
3:39 And instead of having my bookmarks show up, actually turn that into bold like right, This for me, right?
3:48 Also, especially for people who are new, having the rich editor with the toolbar, that would be really helpful.
3:55 Another one that's not so obvious is the general performance.
3:59 Now, if we look at this, this small amount of mark, that might be fast enough, but let's just have a look and see where we are.
4:05 We'll do just this one, so we make a request here. This page is rendering and 42 milliseconds that may or may not seem okay to you.
4:14 But for example, if I go over here, this one is rendering in six milliseconds.
4:19 If I go over to the admin one, this one is 8 10 8 this one at 43 starting to get long. Now it's only, you know, two pages. Let's update.
4:30 That's just a little bit. Make it more realistic for a large piece of content. How do we prevent we're going to put this was a little trick here.
4:44 They want to take this. I'm gonna have 20 times as much content. All right? That's just that's away toe. Put new lines.
4:50 There's have 20 copies of this in Python. Now, if I hit refresh notice the the bar here is longer. We go to help it.
5:00 You can see it spinning for a second. Holy moly.
5:03 Okay, let's go to inspect element and good or network and see how long it takes to go to help Half a 2nd 0 no, You did not just take that long.
5:12 This is not gonna be OK, especially in high traffic websites.
5:15 It's not OK for pages to load this slow and even on traffic sites that don't have a lot of traffic you still wanted to be super super quick.
5:24 You wanted to be the eight millisecond variety. Not the half a second, So we're not done. But we do have all in place, I guess.
5:32 One final thing that we could look at. Here, let me go ahead and take this off.
5:36 Yeah, I'll leave this bit in for you, just in case you want to play with it. One of the thing that work on, I guess really quickly, is our other pages.
5:52 Does this page look OK? Actually, beautiful. He it does.
5:57 So most these other pages, they don't really have much of this one notice we have it in safe mode. So this one's not gonna work.
6:04 Let's go ahead and just fix that one real quick. Edit this instead of saying all this HTML junk, we can just write it like this and mark down the way.
6:14 We have hyperlinks as we take the content that we want to show the hyperlink text when put in brackets and we put the link we want to go to in following from disease.
6:28 Here we go, David, There we go. All right. Working again. Now we have our site using marked down. That was pretty easy, right?


Talk Python's Mastodon Michael Kennedy's Mastodon