-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66beaba
commit adc7338
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
Vanilla-JS-Projects/Advanced/Markdown-Previewer/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
Vanilla-JS-Projects/Advanced/Markdown-Previewer/styles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |