Skip to content

Commit

Permalink
Merge pull request #34 from ycechungAI/issue-29
Browse files Browse the repository at this point in the history
Issue 29
  • Loading branch information
Eugene Chung committed Sep 30, 2021
2 parents 4ff2d56 + 1ce075d commit 9129099
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 59 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Expand Up @@ -15,7 +15,6 @@
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/explicit-module-boundary-types": "off"
"@typescript-eslint/no-var-requires": 0
}
}
13 changes: 1 addition & 12 deletions .gitignore
Expand Up @@ -10,9 +10,6 @@ lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Personal backups (https://nodejs.org)
.backups
.cache
# Runtime data
pids
*.pid
Expand Down Expand Up @@ -119,12 +116,4 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.eslintrc.json
.vs/VSWorkspaceState.json
.vs/ProjectSettings.json
.backup/old lock.json
.backup/old code.js
package-lock.json
.vs/ProjectSettings.json
.vs/VSWorkspaceState.json
.pnp.*
21 changes: 5 additions & 16 deletions README.md
Expand Up @@ -15,7 +15,8 @@ deliverable 0.1 for OSD600 open source course at seneca
"node": ">=16.9.1",
"npm": ">=7.23.0"
```
run npm install chalk if you run into package errors
```

## Screen Shot

Expand All @@ -27,17 +28,11 @@ deliverable 0.1 for OSD600 open source course at seneca

```
git clone <this repo>
Linux: npm install
sudo npm install -g .
Windows: npm install
npm install -g .
Macs: <not fully supported>
npm install -g .
ssgy <command option>
Example:
[x] ssgy -i examples
[x] ssgy -i examples/md -s sample_css/new.css
Example:
ssgy -i examples
```

## FEATURES :
Expand All @@ -62,14 +57,8 @@ ssgy <command option>
- [x] Parse Heading syntax
- [x] Parse Italics & Bold syntax

# Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
```
Special Thanks : Kevan Yang
Markdown Feature: Oliver Pham
Author : Eugene Chung
```

# License
[MIT](LICENSE)
44 changes: 27 additions & 17 deletions bin/index.js
Expand Up @@ -68,9 +68,7 @@ const msgHelp = boxen(helpMsg, boxenOptions);
const isFileSupported = (extension) => {
return supportedExtensions.includes(extension);
}
const getFileName = (filepath) => {
return path.basename(filepath).split('.')[0];
}

// readFile

const readFile = (filepath) => {
Expand All @@ -86,10 +84,20 @@ const readFile = (filepath) => {
};

// createHTML
const createHtmlFile = async (fileName, data, stylesheet = "", outputPath) => {
const createHtmlFile = async (basename, data, stylesheet = "", outputPath) => {
const fileName = basename.split('.')[0];
let dataTreated = { title: "", content: "" };

if (path.extname(basename) === '.md') {
dataTreated = treatMarkdownData(data);
}
else if (path.extname(basename) === '.txt') {
dataTreated = treatData(data);
}
let htmlOption = {
...treatData(data),
style: stylesheet,
...dataTreated,
style: stylesheet,
fileExtname: path.extname(basename),
};
const underscoreFileName = fileName.replaceAll(" ", "_");
await fs.promises.writeFile(
Expand Down Expand Up @@ -156,14 +164,14 @@ const convertToHtml = async (
//Check if ./dist folder exist
//Remove if exist
if (fs.existsSync("./dist") && outputPath === "./dist") {
await fs.promises.rm("./dist", { force: true, recursive: true }, (err) => {
if (err) throw new Error(err);
});
await fs.promises.rm("./dist", { force: true, recursive: true }, (err) => {
if (err) throw new Error(err);
});
}
if (outputPath === "./dist")
//Create a new folder call ./dist
await fs.promises.mkdir("./dist", { recursive: true }, (err) => {
if (err) throw new Error(err);
await fs.promises.mkdir("./dist", { recursive: true }, (err) => {
if (err) throw new Error(err);
});

if (isFile) {
Expand All @@ -172,7 +180,7 @@ const convertToHtml = async (

//Create the html file
let createdFileName = await createHtmlFile(
getFileName(inputPaths),
path.basename(inputPaths),
data,
stylesheet,
outputPath
Expand All @@ -195,9 +203,9 @@ const convertToHtml = async (
const listFolderPath = [];
//Remove root folder and removes duplicates
for (let filePath of filesPathList) {
filePath = path.basename(filePath);
[...new Set (filePath)]

filePath = filePath.split(/\\|\//);
filePath.shift();
filePath = filePath.join("/");
if (!listFolderPath.includes(path.dirname(filePath))) {
listFolderPath.push(path.dirname(filePath));
}
Expand All @@ -219,7 +227,9 @@ const convertToHtml = async (
const data = await readFile(filePath);

//Remove root folder
noRootFilePath = path.basename(filePath);
filePath = filePath.split(/\\|\//);
filePath.shift();
const noRootFilePath = filePath.join("/");

//Create the html file
let createdFileName = await createHtmlFile(
Expand Down Expand Up @@ -333,7 +343,7 @@ if (options.version) {
} else {
//no input given
process.exit(0);
throw new error("No supported files");
throw new error(chalk.red("No supported files"));

}
}
2 changes: 1 addition & 1 deletion dist/Silver_Blaze.html
Expand Up @@ -6,7 +6,7 @@
<title>Silver Blaze</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>Silver Blaze</h1>
Expand Down
2 changes: 1 addition & 1 deletion dist/The_Adventure_of_the_Six_Napoleans.html
Expand Up @@ -6,7 +6,7 @@
<title>THE ADVENTURE OF THE SIX NAPOLEONS</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>THE ADVENTURE OF THE SIX NAPOLEONS</h1>
Expand Down
2 changes: 1 addition & 1 deletion dist/The_Adventure_of_the_Speckled_Band.html
Expand Up @@ -6,7 +6,7 @@
<title>THE ADVENTURE OF THE SPECKLED BAND</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>THE ADVENTURE OF THE SPECKLED BAND</h1>
Expand Down
2 changes: 1 addition & 1 deletion dist/The_Naval_Treaty.html
Expand Up @@ -6,7 +6,7 @@
<title>The Naval Treaty</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>The Naval Treaty</h1>
Expand Down
2 changes: 1 addition & 1 deletion dist/The_Red_Headed_League.html
Expand Up @@ -6,7 +6,7 @@
<title>The Red Headed League</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>The Red Headed League</h1>
Expand Down
3 changes: 2 additions & 1 deletion dist/index.html
Expand Up @@ -6,7 +6,7 @@
<title>Home</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>Home menu</h1>
Expand All @@ -17,6 +17,7 @@ <h2>Summary</h2>
<li><a href='The Adventure of the Speckled Band.html'>The Adventure of the Speckled Band</a></li>
<li><a href='The Naval Treaty.html'>The Naval Treaty</a></li>
<li><a href='The Red Headed League.html'>The Red Headed League</a></li>
<li><a href='lab3.html'>lab3</a></li>
<li><a href='md/exampletest1.html'>exampletest1</a></li>
<li><a href='test/test2/test.html'>test</a></li>
<li><a href='test/test2.html'>test2</a></li>
Expand Down
19 changes: 19 additions & 0 deletions dist/lab3.html
@@ -0,0 +1,19 @@

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>Document</h1>
<h1>Lab 3 Test</h1>
<p><hr>testing lab3</hr> hello world</p>
<p>new paragraph <hr>should be hr tag within</hr></p>
<p>done</p>
</body>
</html>

8 changes: 6 additions & 2 deletions dist/md/exampletest1.html
Expand Up @@ -6,7 +6,7 @@
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>Document</h1>
Expand All @@ -23,6 +23,10 @@ <h2>Emphasis</h2>
<p><i>This is italic text</i></p>
<p><i>This is italic text</i></p>
<p>~~Strikethrough~~</p>
<h2>Lab 3 Test</h2>
<p><hr> thematic break </hr></p>
<p>what about this <hr>test</hr></p>
<p><hr>test2</hr>hmm ok</p>
<p>+ Create a list by starting a line with `+`, `-`, or `*`</p>
<p>+ Sub-lists are made by indenting 2 spaces:</p>
<p>- Marker character change forces new list start:</p>
Expand All @@ -36,7 +40,7 @@ <h2>Emphasis</h2>
<p>```</p>
<h2>Tables</h2>
<p>| Option | Description |</p>
<p>| ------ | ----------- |</p>
<p>| <hr>--- | --------</hr> |</p>
<p>| data | path to data files to supply the data that will be passed into templates. |</p>
<p>| engine | engine to be used for processing templates. Handlebars is the default. |</p>
<p>| ext | extension to be used for dest files. |</p>
Expand Down
2 changes: 1 addition & 1 deletion dist/test/test2.html
Expand Up @@ -6,7 +6,7 @@
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>Document</h1>
Expand Down
2 changes: 1 addition & 1 deletion dist/test/test2/test.html
Expand Up @@ -6,7 +6,7 @@
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="sample_css/test.css">
<link rel="stylesheet" href="sample_css/new.css">
</head>
<body>
<h1>Document</h1>
Expand Down
5 changes: 5 additions & 0 deletions examples/lab3.md
@@ -0,0 +1,5 @@
# Lab 3 Test
---testing lab3--- hello world

new paragraph ---should be hr tag within---
done
8 changes: 7 additions & 1 deletion examples/md/exampletest1.md
Expand Up @@ -21,14 +21,20 @@ _This is italic text_

~~Strikethrough~~


## Lab 3 Test
--- thematic break ---
what about this ---test---
---test2---hmm ok


+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!

Block code "fences"

```
Expand Down
4 changes: 4 additions & 0 deletions lib/parser/markdown.js
Expand Up @@ -39,6 +39,10 @@ const markdown = {
regex: /\*(.+)\*|_(.+)_/g,
htmlTemplate: "<i>$1$2</i>",
},
hr: {
regex: /\*(.+)\*|---(.+)---/g,
htmlTemplate: "<hr>$1$2</hr>"
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9129099

Please sign in to comment.