Skip to content

Commit

Permalink
JS added for new components and proper error handling
Browse files Browse the repository at this point in the history
Added js for new components to work and proper error handling
  • Loading branch information
Harshit2012 authored Jun 13, 2024
1 parent 6d4d674 commit b109ab7
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
document.getElementById('convert-button').addEventListener('click', function () {
document.getElementById('convert-button').addEventListener('click', function() {
const markdownText = document.getElementById('markdown-input').value;
if (markdownText.trim() === '') {
alert('Please enter some Markdown text.');
return;
}

const htmlContent = marked.parse(markdownText);
const formattedHtml = `
<!DOCTYPE html>
Expand All @@ -18,11 +23,25 @@ document.getElementById('convert-button').addEventListener('click', function ()
document.getElementById('html-output').textContent = formattedHtml;
});

document.getElementById('copy-button').addEventListener('click', function () {
document.getElementById('copy-html-button').addEventListener('click', function() {
const htmlOutput = document.getElementById('html-output').textContent;
navigator.clipboard.writeText(htmlOutput).then(function () {
navigator.clipboard.writeText(htmlOutput).then(function() {
alert('HTML copied to clipboard!');
}, function (err) {
}, function(err) {
alert('Could not copy text: ', err);
});
});
});

document.getElementById('copy-markdown-button').addEventListener('click', function() {
const markdownInput = document.getElementById('markdown-input').value;
navigator.clipboard.writeText(markdownInput).then(function() {
alert('Markdown copied to clipboard!');
}, function(err) {
alert('Could not copy text: ', err);
});
});

document.getElementById('preview-button').addEventListener('click', function() {
const htmlContent = marked.parse(document.getElementById('markdown-input').value);
document.getElementById('html-preview').innerHTML = htmlContent;
});

0 comments on commit b109ab7

Please sign in to comment.