Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrutaJayanti authored Jun 2, 2024
1 parent 66beaba commit adc7338
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Binary file not shown.
21 changes: 21 additions & 0 deletions Vanilla-JS-Projects/Advanced/Markdown-Previewer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Markdown Previewer</title>

</head>
<body>
<div class="container">
<textarea id="markdown-input" placeholder="Enter Markdown here..."></textarea>
<div id="preview"></div>
</div>




<script src="script.js"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions Vanilla-JS-Projects/Advanced/Markdown-Previewer/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
document.addEventListener('DOMContentLoaded', function() {
const markdownInput = document.getElementById('markdown-input');
const preview = document.getElementById('preview');


function renderMarkdown(markdown) {
const lines = markdown.split('\n');
let html = '';
lines.forEach(line => {
const match = line.match(/^#+\s*(.*)$/);
if (match) {
const level = match[0].split('#').length - 1;
const text = match[1].trim();

html += `<h${level}>${text}</h${level}>`;
}
});

return html;
}




function updatePreview()
{
preview.innerHTML = renderMarkdown(markdownInput.value);
}
markdownInput.addEventListener('input', updatePreview);
});
31 changes: 31 additions & 0 deletions Vanilla-JS-Projects/Advanced/Markdown-Previewer/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

.container {
display: flex;
justify-content: space-around;
align-items: flex-start;
margin-top: 50px;
}

textarea {
width: 45%;
height: 400px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
}

#preview {
width: 45%;
height: 400px;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
overflow-y: auto;
}

0 comments on commit adc7338

Please sign in to comment.