Search code examples
javascripthtmlexpressejsblogs

How to render markdown in ejs page


i want to create small blog using express , ejs and markdown but when i tried to load markdown on page i saw this: enter image description here

my code:

<!DOCTYPE html>
<html lang="pl">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Blog</title>
    <link rel="stylesheet" href="/css/style.css" />
  </head>

  <body>
    <%=title%> <%=body%>
  </body>
</html>

Solution

  • It is simple you have to change your tags to <%- yourVar%>

    <!DOCTYPE html>
    <html lang="pl">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Blog</title>
        <link rel="stylesheet" href="/css/style.css" />
      </head>
    
      <body>
        <%-title%> <%-body%>
      </body>
    </html>