Tell us what’s happening:
Please can someone help me out. I can’t pass 32 and many more ![]()
![]()
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown to HTML Converter</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Markdown to HTML Converter</h1>
<div id="container">
<div class="container">
<h2>Markdown Input:</h2>
<textarea id="markdown-input" placeholder="Enter your markdown here..."></textarea>
</div>
<div class="container">
<h2>Raw HTML Output:</h2>
<div id="html-output"></div>
</div>
<div class="container">
<h2>HTML Preview:</h2>
<div id="preview"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
padding: 20px;
}
#markdown-input {
width: 100%;
height: 100px;
}
#html-output, #preview {
height: 100px;
display: inline-block;
width: 100%;
border: 1px solid #ccc;
padding: 10px;
margin: auto;
white-space: pre-wrap;
background-color: #f9f9f9;
}
@media (min-width: 600px) {
#markdown-input, #html-output, #preview {
height: 200px;
margin: 0;
}
#container {
display: flex;
justify-content: space-evenly;
gap: 10px;
}
}
/* file: script.js */
const markdown = document.getElementById("markdown-input")
const rawOut = document.getElementById("html-output")
const output = document.getElementById("preview")
function convertMarkdown(){
let value = markdown.value
const heading = /^(#{1,3})\s+(.+)/gm
if(heading.test(value)){
return value.replace(heading, (fullContent, firstCaptured, secondCaptured) => {
return `<h${firstCaptured.length}>${secondCaptured}</h${firstCaptured.length}>`})
}
const strong = /(_|\*){2}(.+)(_|\*){2}/gm
if(strong.test(value)){
return value.replace(strong, (rawContext,el,content) => {
return `<strong>${content}</strong>`
})
}
const italic = /^(\*|_)(.+)(\*|_)$/gm
if(italic.test(value)){
return value.replace(italic, (rawContent, first, content) => {
return `<em>${content}</em>`
})
}
const img = /^(!\[.+])(.+)$/gm
if(img.test(value)){
return value.replace(img, (rawContent, first, second) => {
return `<img alt="${first.slice(2, first.length - 1)}" src="${second.slice(1, second.length - 1)}">`
})
}
const anchor = /^(\[.+])(.+)$/gm
if(anchor.test(value)){
return value.replace(anchor, (rawContent, first, second) => {
return `<a href="${second.slice(1, second.length - 1)}>${first.slice(1, first.length - 1)}</a>`
} )
}
const quote = /^(>)\s+(.+)/gm
if(quote.test(value)){
return value.replace(quote, (rawContent, first, second) => {
return `<blockquote>${second}</blockquote>`
})
}
return value
}
markdown.addEventListener("input", () => {
rawOut.innerText = convertMarkdown()
output.innerHTML = convertMarkdown()
})
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Mobile Safari/537.36
Challenge Information:
Build a Markdown to HTML Converter - Build a Markdown to HTML Converter


