From 8c464190fadbb229f24ceb5727ec9d685ffa4d45 Mon Sep 17 00:00:00 2001 From: Gulnur Baimukhambetova Date: Wed, 28 Sep 2022 18:56:32 -0400 Subject: [PATCH 1/2] Italic and bold styling --- src/helper.js | 28 +++++++++++++++------------- test/test-folder/markdown.md | 9 +++++++-- test/testMarkdown.md | 8 +++++++- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/helper.js b/src/helper.js index aeca2ff..d1c1575 100644 --- a/src/helper.js +++ b/src/helper.js @@ -53,8 +53,6 @@ function generateSite(file, stylesheet = '') { //variable to hold whether the file is markdown let fileMarkdown = false; - // regex to find markdown link - const regex = /\[(.*?)\]\((.*?)\)/g; rl.on('line', (line) => { if (ext == '.txt') { @@ -94,20 +92,24 @@ function generateSite(file, stylesheet = '') { else if (line.startsWith('## ')) { //cut the '## ' out of the line - text = line.substring(3); - body += ` -

${text}

- `; + text = line.substring(3); + body += ` +

${text}

+ `; } - else if (regex.test(line)) - { - //convert markdown link to href - body += ` -

${line.replaceAll(regex, '$1')}

- `; - } else if (line != "") { + //convert markdown link to href + line = line.replace(/\[(.*?)\]\((.*?)\)/g, '$1'); + //convert markdown bold ** to html element + line = line.replace(/\*\*(.*)\*\*/g, '$1'); + //convert markdown bold __ to html element + line = line.replace(/__(.*)__/g, '$1'); + //convert markdown italics * to html element + line = line.replace(/\*(.*)\*/g, '$1'); + //convert markdown italics _ to html element + line = line.replace(/_(.*)_/g, '$1'); + body += `

${line}

`; diff --git a/test/test-folder/markdown.md b/test/test-folder/markdown.md index 4242d55..cd44c8f 100644 --- a/test/test-folder/markdown.md +++ b/test/test-folder/markdown.md @@ -4,11 +4,16 @@ this is not a heading # this is another heading - ## this is heading 2 Above is to test heading 2 to see if markdown heading is converted into html link This line is to test markdown [link1](http://test.com/test). -This is another test for markdown [link2](https:dev.to/my-blog). One more [link3](test@test.com) in the same line. \ No newline at end of file +This is another test for markdown [link2](https:dev.to/my-blog). One more [link3](test@test.com) in the same line. + +This line is to test italics in different forms such as : *asterisk italics* and _underscore italics_. + +This line is to test bold in different forms such as : **asterisk bold** and __underscore bold__. + +This line is to test bold and italics combined : ***asterisk bold and italic*** and ___underscore bold and italic___. \ No newline at end of file diff --git a/test/testMarkdown.md b/test/testMarkdown.md index b073ab6..7123391 100644 --- a/test/testMarkdown.md +++ b/test/testMarkdown.md @@ -16,4 +16,10 @@ sample text # final heading -final text \ No newline at end of file +final text + +This line is to test italics in different forms such as : *asterisk italics* and _underscore italics_. + +This line is to test bold in different forms such as : **asterisk bold** and __underscore bold__. + +This line is to test bold and italics combined : ***asterisk bold and italic*** and ___underscore bold and italic___. From 1ad2c63eda853487dd6427e1558057c068eb3143 Mon Sep 17 00:00:00 2001 From: Gulnur Baimukhambetova Date: Wed, 28 Sep 2022 22:41:42 -0400 Subject: [PATCH 2/2] Updated README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ddcb493..1aaa053 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ ## Overview This tool enables the user to: - 1. Specify a ".txt" or ".md" file to have it converted into an HTML webpage + 1. Specify a ".txt" or ".md" file to have it converted into an HTML webpage. 2. Specify a folder containing multiple ".txt" and ".md" files to convert all of them into HTML web pages. The program will recursively search subfolders for ".txt" files as well. +For markdown files, we currently support proper styling syntax features for italics, bold, heading 1, heading 2, and a link. + NOTE: This tool requires the use of a BASH shell.