Skip to content

Commit

Permalink
added horizontal rule parsing to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
pbelokon committed Sep 26, 2023
1 parent c6e0a68 commit 69bcdf6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Heading 3

---

first paragraph from md file

second paragraph from md file
Expand All @@ -13,3 +15,5 @@ third paragraph from md file
_Italic font_

String _Italic font_ String

---
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.

1 change: 1 addition & 0 deletions src/generator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
import fs from "fs-extra";
import path from "path";
import { parseText, parseFileName, parseMarkDown } from "./parser.js";
Expand Down
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
function buildHtml(title, body) {
return `
<!doctype html>
Expand Down Expand Up @@ -45,6 +46,7 @@ function parseMarkDown(content, filename) {
let slicedLine;

const italic = /\_([^*><]+)\_/g;
const horizontalRule = /^( ?[-_*]){3,} ?[\t]*$/g;

// to convert md lines to html tags
const body = content
Expand All @@ -60,6 +62,8 @@ function parseMarkDown(content, filename) {
return `<h3>${slicedLine}</h3>`;
} else if (line.match(italic)) {
return line.replace(italic, "<i>$1</i>");
} else if (line.match(horizontalRule)) {
return line.replace(horizontalRule, "<hr>");
} else {
return `<p>${line}</p>`;
}
Expand Down

0 comments on commit 69bcdf6

Please sign in to comment.