Skip to content

Commit

Permalink
Merge pull request #8 from zijunhz/inlineCode
Browse files Browse the repository at this point in the history
feat: add inline code blocks support
  • Loading branch information
zpatronus authored Aug 13, 2022
2 parents d320038 + abebb85 commit 05376df
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 281 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0.0)
project(markdown2html VERSION 1.1.0)
project(markdown2html VERSION 1.1.1)

add_compile_options(-Wall -Wextra -Wpedantic -std=c++1z)

Expand Down
14 changes: 14 additions & 0 deletions MarkdownSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ void MarkdownSource::convertTo(ofstream& outFile) {
}
continue;
}
bool isInInlineCode = false;
while (i < len) {
// remember to add i
Type theType = startWith(l, i);
if (isInInlineCode && (theType != InlineCode)) {
theType = Text;
}
if (theType == Hr) {
outFile << "<hr>";
break;
Expand Down Expand Up @@ -143,6 +148,15 @@ void MarkdownSource::convertTo(ofstream& outFile) {
outFile << "<li>" << endl;
i = (theType == Uli) ? indentCnt + 2 : findChar(l, indentCnt, '.', "") + 2;
}
if (theType == InlineCode) {
if (!isInInlineCode) {
outFile << "<code>";
} else {
outFile << "</code>";
}
isInInlineCode = !isInInlineCode;
i++;
}
if (theType == Text) {
outFile << l[i];
i++;
Expand Down
3 changes: 2 additions & 1 deletion MarkdownSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ enum Type {
Img,
ImgBracket,
Hyper,
CodeBlock // start with
CodeBlock, // start with
InlineCode
};

#include <fstream>
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Unordered/ordered list

Plain text

Code blocks (` ``` `)
Code blocks (` ``` ``` `)

Inline code blocks (` `` `)

## How to compile

Expand Down
4 changes: 3 additions & 1 deletion settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ void Settings::afterBody() {
}
file.close();
// select style
file.open("./source/" + selectTheme() + "Css.html");
file.open("./source/" + selectTheme() + ".css");
if (!(file.is_open())) {
cout << "Error opening css file" << endl;
return;
}
outFile << "<style>" << endl;
while (!file.eof()) {
string theLine;
getline(file, theLine);
outFile << theLine << endl;
}
outFile << "</style>" << endl;
}
59 changes: 40 additions & 19 deletions source/darkCss.html → source/dark.css
Original file line number Diff line number Diff line change
@@ -1,80 +1,101 @@
<style>
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background: #151515;
background: #151515
}

#app {
margin: 0;
padding: 0;
padding: 0
}

* {
font-family: 'Courier New', Courier, monospace;
font-family: monospace, "Courier New", Courier;
color: #aaa;
font-size: 16px;
font-weight: 400;
line-height: 24px;
line-height: 24px
}

h1 {
color: #eee;
font-size: 32px;
font-weight: 600;
line-height: 40px;
line-height: 40px
}

h2 {
margin: 5px 0 5px 0;
color: #eee;
font-size: 24px;
font-weight: 600;
line-height: 30px;
line-height: 30px
}

h3 {
margin: 5px 0 5px 0;
color: #bbb;
font-size: 18px;
line-height: 24px;
font-weight: 600;
font-weight: 600
}

a {
text-decoration: underline;
color: #ddd;
font-weight: 100;
font-weight: 100
}

a:hover {
color: #fff;
color: #fff
}

ul {
margin: 5px 0 5px 0;
margin: 5px 0 5px 0
}

li {
margin: 3px 0 3px 0 !important;
margin: 3px 0 3px 0 !important
}

hr {
border: none;
border-top: 1px solid #444;
margin: 15px 0 15px 0;
margin: 15px 0 15px 0
}

#realBody {
max-width: 900px;
margin: 3% auto 8% auto;
padding: 40px 20px 0 20px;
padding: 40px 20px 0 20px
}

#avatar {
width: 20%;
margin-bottom: 3%;
border: 3px dashed white;
border: 3px dashed #fff
}

li {
margin-bottom: 10px;
margin-bottom: 10px
}

img {
max-width: 100%;
max-width: 100%
}

pre {
background-color: #080808;
padding: 12px;
border-radius: 4px;
border-radius: 4px
}

code {
background-color: #080808;
padding: .2em .4em;
font-size: 85%;
border-radius: 3px;
font-family: "Courier New", Courier, monospace
}
</style>
61 changes: 41 additions & 20 deletions source/darkCompactCss.html → source/darkCompact.css
Original file line number Diff line number Diff line change
@@ -1,81 +1,102 @@
<style>
body {
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background: #151515;
background: #151515
}

#app {
margin: 0;
padding: 0;
padding: 0
}

* {
font-family: 'Courier New', Courier, monospace;
font-family: monospace, "Courier New", Courier;
color: #aaa;
font-size: 16px;
font-weight: 400;
line-height: 20px;
line-height: 20px
}

h1 {
color: #eee;
font-size: 32px;
font-weight: 600;
line-height: 36px;
margin: 5px 0 5px 0;
margin: 5px 0 5px 0
}

h2 {
margin: 5px 0 5px 0;
color: #eee;
font-size: 24px;
font-weight: 600;
line-height: 24px;
line-height: 24px
}

h3 {
margin: 5px 0 5px 0;
color: #bbb;
font-size: 18px;
line-height: 18px;
font-weight: 600;
font-weight: 600
}

a {
text-decoration: underline;
color: #ddd;
font-weight: 100;
font-weight: 100
}

a:hover {
color: #fff;
color: #fff
}

ul {
margin: 5px 0 5px 0;
margin: 5px 0 5px 0
}

li {
margin: 3px 0 3px 0 !important;
margin: 3px 0 3px 0 !important
}

hr {
border: none;
border-top: 1px solid #444;
margin: 15px 0 15px 0;
margin: 15px 0 15px 0
}

#realBody {
max-width: 900px;
margin: 3% auto 8% auto;
padding: 40px 20px 0 20px;
padding: 40px 20px 0 20px
}

#avatar {
width: 20%;
margin-bottom: 3%;
border: 3px dashed white;
border: 3px dashed #fff
}

li {
margin-bottom: 10px;
margin-bottom: 10px
}

img {
max-width: 100%;
max-width: 100%
}

pre {
background-color: #080808;
padding: 12px;
border-radius: 4px;
border-radius: 4px
}

code {
background-color: #080808;
padding: .2em .4em;
font-size: 85%;
border-radius: 3px;
font-family: "Courier New", Courier, monospace
}
</style>
1 change: 1 addition & 0 deletions source/default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

19 changes: 0 additions & 19 deletions source/defaultCss.html

This file was deleted.

1 change: 1 addition & 0 deletions source/githubDark.css

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

Loading

0 comments on commit 05376df

Please sign in to comment.