Skip to content

Commit

Permalink
Merge pull request #24 from gulyapulya/issue-23
Browse files Browse the repository at this point in the history
Added italics and bold styling markdown syntax features
  • Loading branch information
rokaicker authored Sep 29, 2022
2 parents dfe336a + 1ad2c63 commit 4067f6d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
28 changes: 15 additions & 13 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -94,20 +92,24 @@ function generateSite(file, stylesheet = '') {
else if (line.startsWith('## '))
{
//cut the '## ' out of the line
text = line.substring(3);
body += `
<h2>${text}</h2>
`;
text = line.substring(3);
body += `
<h2>${text}</h2>
`;
}
else if (regex.test(line))
{
//convert markdown link to href
body += `
<p>${line.replaceAll(regex, '<a href="$2">$1</a>')}</p>
`;
}
else if (line != "")
{
//convert markdown link to href
line = line.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>');
//convert markdown bold ** to html <b> element
line = line.replace(/\*\*(.*)\*\*/g, '<b>$1</b>');
//convert markdown bold __ to html <b> element
line = line.replace(/__(.*)__/g, '<b>$1</b>');
//convert markdown italics * to html <i> element
line = line.replace(/\*(.*)\*/g, '<i>$1</i>');
//convert markdown italics _ to html <i> element
line = line.replace(/_(.*)_/g, '<i>$1</i>');

body += `
<p>${line}</p>
`;
Expand Down
9 changes: 7 additions & 2 deletions test/test-folder/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]([email protected]) in the same line.
This is another test for markdown [link2](https:dev.to/my-blog). One more [link3]([email protected]) 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___.
8 changes: 7 additions & 1 deletion test/testMarkdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ sample text

# final heading

final text
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___.

0 comments on commit 4067f6d

Please sign in to comment.