Tell us what’s happening:
I’m at the point where the only tests failing are 48-50, and I’m getting brain block really bad with this lol.
It’s to the point that I even tried putting this all on vscode and seeing if copilot could help me better understand how to solve this, but haven’t had any success with its suggestions.
Could I get a point in the right direction?
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>
</body>
<script src="script.js"></script>
</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 */
//Assign elements
let textInput = document.querySelector("#markdown-input");
let rawOutput = document.querySelector("#html-output");
let htmlPreview = document.querySelector("#preview");
//Regexes
let heading1Regex = /^\s?(?<!#)#(?!#)\s+([^\r\n#]+)/gm;
let heading2Regex = /^\s?(?<!#)##(?!#)\s+([^\r\n#]+)/gm;
let heading3Regex = /^\s?(?<!#)###(?!#)\s+([^\r\n#]+)/gm;
let boldRegex = /(?<!\*)\*\*(?!\*)([^*]+?)(?<!\*)\*\*(?!\*)|(?<!_)__(?!_)([^*]+?)(?<!_)__(?!_)/gm;
let italicRegex = /(?<!\*)\*(?!\*)([^*]+?)(?<!\*)\*(?!\*)|(?<!_)_(?!_)([^*]+?)(?<!_)_(?!_)/gm;
let imgRegex = /!\[([^\]]+)\]\(([^\)]+)\)/gm;
let linkRegex = /\[([^\]]+)\]\(([^\)]+)\)/gm;
let blockQuote = /^\s?>\s(.+)/gm;
function convertMarkdown() {
let textContent = textInput.value;
let textConvert = textContent
.replace(heading1Regex, "<h1>$1</h1>")
.replace(heading2Regex, "<h2>$1</h2>")
.replace(heading3Regex, "<h3>$1</h3>")
.replace(blockQuote, "<blockquote>$1</blockquote>")
.replace(boldRegex, (match, g1, g2) => {
return `<strong>${g1 || g2}</strong>`;
})
.replace(italicRegex, (match, g1, g2) => {
return `<em>${g1 || g2}</em>`;
})
.replace(imgRegex, '<img alt="$1" src="$2">')
.replace(linkRegex, '<a href="$2">$1</a>');
return textConvert;
};
textInput.addEventListener("input", () => {
rawOutput.innerText = convertMarkdown();
htmlPreview.innerHTML = convertMarkdown();
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Challenge Information:
Build a Markdown to HTML Converter - Build a Markdown to HTML Converter