diff --git a/frontend.js b/frontend.js index d9ff612..37d99dc 100644 --- a/frontend.js +++ b/frontend.js @@ -3,6 +3,96 @@ // Functions for commonly used elements +//Convert markdown to HTML and back +function markdownToHTML(markdown) { + // Replace headers (h1, h2, h3) with corresponding HTML tags + markdown = markdown.replace(/^# (.*$)/gim, '
tag
+ markdown = markdown.replace(/`(.*?)`/gim, '$1
');
+
+ // Replace blockquotes with HTML tag
+ markdown = markdown.replace(/^\s*> (.*)$/gim, '$1
');
+
+ // Replace horizontal rules with HTML
tag
+ markdown = markdown.replace(/^\s*[-*_]{3,}\s*$/gim, '
');
+
+ // Replace line breaks with HTML
tag
+ markdown = markdown.replace(/\n$/gim, '
');
+
+ // Replace images with HTML tag
+ markdown = markdown.replace(/!\[(.*?)\]\((.*?)\)/gim, '');
+
+ // Replace links with HTML tag
+ markdown = markdown.replace(/\[(.*?)\]\((.*?)\)/gim, '$1');
+
+ markdown = markdown.replaceAll("", "")
+
+ return markdown;
+}
+
+function htmlToMarkdown(html) {
+ // Replace headers (h1, h2, h3) with corresponding Markdown tags
+ html = html.replace(/(.*?)<\/h1>/gim, '# $1');
+ html = html.replace(/(.*?)<\/h2>/gim, '## $1');
+ html = html.replace(/(.*?)<\/h3>/gim, '### $1');
+
+ // Replace bold and italic text with corresponding Markdown tags
+ html = html.replace(/(.*?)<\/b>/gim, '**$1**');
+ html = html.replace(/(.*?)<\/i>/gim, '*$1*');
+
+ // Replace unordered list items with Markdown list tags
+ html = html.replace(/(.*?)<\/ul>/gim, function(match, p1) {
+ let listItems = p1.trim().split('
(.*?)<\/code>/gim, '`$1`');
+
+ // Replace blockquotes with Markdown blockquote tag
+ html = html.replace(/(.*?)<\/blockquote>/gim, '> $1');
+
+ // Replace horizontal rules with Markdown horizontal rules
+ html = html.replace(/
/gim, '---');
+
+ // Replace line breaks with Markdown line breaks
+ html = html.replace(/
/gim, '\n');
+
+ // Replace images with Markdown image syntax
+ html = html.replace(//gim, '![$1]($2)');
+
+ // Replace links with Markdown link syntax
+ html = html.replace(/(.*?)<\/a>/gim, '[$2]($1)');
+
+ html = html.replaceAll("", "")
+
+ html = html.replaceAll("
", "")
+
+ return html;
+}
+
// Generalized element creation
function createElement(tagName, elementID, attributes = {}) {
const element = document.createElement(tagName);