mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-09-07 12:10:42 +02:00
Compare commits
26 Commits
a59773ef3e
...
84148f92df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84148f92df | ||
|
|
2013826acb | ||
|
|
bdcf7cf5da | ||
| 858bd19f10 | |||
| eecadf4fab | |||
| 8556937f58 | |||
| bc9228cdc7 | |||
| 74b46f4923 | |||
| 763761ea82 | |||
| 1668cb8563 | |||
| 5fa62d64ee | |||
| b171f11982 | |||
|
|
d2efd637cd | ||
| 90adcd88e7 | |||
| ddc590571a | |||
| 35cb6e3d82 | |||
| a2d76d4c4f | |||
| ef8fbfbb53 | |||
| e9b88530c2 | |||
| 322df82288 | |||
| fe02a16416 | |||
|
|
dd2c6ca810 | ||
| 2c8b9f2cfc | |||
| cf3b502509 | |||
| 1754c9fbab | |||
| 763a941042 |
13
.github/workflows/c-cpp.yml
vendored
13
.github/workflows/c-cpp.yml
vendored
@@ -10,7 +10,10 @@ jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./src
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
@@ -18,6 +21,8 @@ jobs:
|
||||
sudo apt update
|
||||
sudo apt install -y g++ catch2 libmd4c-dev libmd4c-html0-dev libtomlplusplus-dev
|
||||
- name: make
|
||||
run: make -C src
|
||||
- name: make check
|
||||
run: make check -C src
|
||||
run: make
|
||||
- name: make test
|
||||
run: make test
|
||||
- name: make clean
|
||||
run: make clean
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,4 +1,7 @@
|
||||
out/
|
||||
posts/
|
||||
src/tests/tests
|
||||
src/build/
|
||||
/src/blog
|
||||
/src/tests
|
||||
/src/.cache/
|
||||
*.o
|
||||
|
||||
74
src/compile_commands.json
Normal file
74
src/compile_commands.json
Normal file
@@ -0,0 +1,74 @@
|
||||
[
|
||||
{
|
||||
"file": "main.cpp",
|
||||
"arguments": [
|
||||
"g++",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
"-I",
|
||||
".",
|
||||
"-c",
|
||||
"main.cpp",
|
||||
"-o",
|
||||
"build/main.o"
|
||||
],
|
||||
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||
"output": "build/main.o"
|
||||
},
|
||||
{
|
||||
"file": "config/config.cpp",
|
||||
"arguments": [
|
||||
"g++",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
"-I",
|
||||
".",
|
||||
"-c",
|
||||
"config/config.cpp",
|
||||
"-o",
|
||||
"build/config/config.o"
|
||||
],
|
||||
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||
"output": "build/config/config.o"
|
||||
},
|
||||
{
|
||||
"file": "format/format.cpp",
|
||||
"arguments": [
|
||||
"g++",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
"-I",
|
||||
".",
|
||||
"-c",
|
||||
"format/format.cpp",
|
||||
"-o",
|
||||
"build/format/format.o"
|
||||
],
|
||||
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||
"output": "build/format/format.o"
|
||||
},
|
||||
{
|
||||
"file": "markdown/markdown.cpp",
|
||||
"arguments": [
|
||||
"g++",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
"-I",
|
||||
".",
|
||||
"-c",
|
||||
"markdown/markdown.cpp",
|
||||
"-o",
|
||||
"build/markdown/markdown.o"
|
||||
],
|
||||
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||
"output": "build/markdown/markdown.o"
|
||||
}
|
||||
]
|
||||
@@ -5,10 +5,10 @@
|
||||
#include <toml++/impl/parser.hpp>
|
||||
#include <toml++/toml.hpp>
|
||||
|
||||
Config get_config(const std::string &CONFIG_FILE) {
|
||||
Config get_config(const std::string &CONFIGURATION) {
|
||||
toml::table toml_table;
|
||||
try {
|
||||
toml_table = toml::parse_file(CONFIG_FILE);
|
||||
toml_table = toml::parse(CONFIGURATION);
|
||||
} catch (const toml::parse_error &err) {
|
||||
std::cerr << "Parsing failed:" << std::endl << err << std::endl;
|
||||
}
|
||||
@@ -17,4 +17,7 @@ struct Config {
|
||||
General general;
|
||||
};
|
||||
|
||||
Config get_config(const std::string &CONFIG_FILE);
|
||||
// @brief Load config into `Config` struct
|
||||
// @param CONFIGURATION content of `.toml` file containing configuration
|
||||
// @return Config with parsed configuration
|
||||
Config get_config(const std::string &CONFIGURATION);
|
||||
11
src/format/format.cpp
Normal file
11
src/format/format.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "markdown/markdown.hpp"
|
||||
#include <string>
|
||||
|
||||
static bool replace_once(std::string &str, const std::string &from,
|
||||
const std::string &to) {
|
||||
size_t start_pos = str.find(from);
|
||||
if (start_pos == std::string::npos)
|
||||
return false;
|
||||
str.replace(start_pos, from.length(), to);
|
||||
return true;
|
||||
}
|
||||
7
src/format/format.hpp
Normal file
7
src/format/format.hpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <string>
|
||||
|
||||
// Change template from file into html
|
||||
// Return html in string
|
||||
std::string inject_html_into_template(const std::string &FILE_NAME,
|
||||
const std::string &TEMPLATE,
|
||||
const std::string &HTML);
|
||||
36
src/io/io.cpp
Normal file
36
src/io/io.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "io/io.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
std::string read_file(const std::string &FILE_PATH) {
|
||||
std::ifstream file(FILE_PATH);
|
||||
if (!file) {
|
||||
throw std::runtime_error("Error while opening file at " + FILE_PATH);
|
||||
}
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
|
||||
if (file.bad()) {
|
||||
throw std::runtime_error("Error while reading file at " + FILE_PATH);
|
||||
}
|
||||
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
void write_file(const std::string &FILE_PATH, const std::string &CONTENT) {
|
||||
std::ofstream out(FILE_PATH);
|
||||
if (!out) {
|
||||
throw std::runtime_error("Error while opening file for writing at " +
|
||||
FILE_PATH);
|
||||
}
|
||||
|
||||
out << CONTENT;
|
||||
|
||||
if (!out) {
|
||||
throw std::runtime_error("Error while writing to the " + FILE_PATH);
|
||||
}
|
||||
|
||||
out.close();
|
||||
}
|
||||
13
src/io/io.hpp
Normal file
13
src/io/io.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <string>
|
||||
|
||||
// @brief Read file from given path
|
||||
// @param FILE PATH Path to the file
|
||||
// @return File content
|
||||
// @throws std::runtime_error if any errors
|
||||
std::string read_file(const std::string &FILE_PATH);
|
||||
|
||||
/// @brief Writes the given content into a file.
|
||||
/// @param FILE_PATH Path to the file to write.
|
||||
/// @param CONTENT Content to write into the file.
|
||||
/// @throws std::runtime_error if the file cannot be opened or written.
|
||||
void write_file(const std::string &FILE_PATH, const std::string &CONTENT);
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "config.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
61
src/makefile
61
src/makefile
@@ -1,34 +1,53 @@
|
||||
CXX = g++
|
||||
CXXFLAGS = -std=c++17 -Wall
|
||||
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
|
||||
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -I .
|
||||
LIBS = -lmd4c-html
|
||||
TEST_DIR = tests
|
||||
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
|
||||
|
||||
all: blog
|
||||
BUILD_DIR = build
|
||||
|
||||
blog: main.o config.o utils.o
|
||||
$(CXX) $(CXXFLAGS) main.o config.o -o blog $(LIBS)
|
||||
SOURCES = main.cpp \
|
||||
config/config.cpp \
|
||||
format/format.cpp \
|
||||
markdown/markdown.cpp \
|
||||
io/io.cpp
|
||||
|
||||
main.o: main.cpp config.hpp
|
||||
$(CXX) $(CXXFLAGS) -c main.cpp
|
||||
OBJECTS = $(SOURCES:%.cpp=$(BUILD_DIR)/%.o)
|
||||
|
||||
config.o: config.cpp config.hpp
|
||||
$(CXX) $(CXXFLAGS) -c config.cpp
|
||||
TEST_SOURCES = tests.cpp \
|
||||
config/config.cpp \
|
||||
format/format.cpp \
|
||||
markdown/markdown.cpp \
|
||||
io/io.cpp
|
||||
|
||||
utils.o: utils.cpp utils.hpp
|
||||
$(CXX) $(CXXFLAGS) -c utils.cpp
|
||||
TEST_OBJECTS = $(TEST_SOURCES:%.cpp=$(BUILD_DIR)/%.o)
|
||||
|
||||
markdown.o: markdown.cpp markdown.hpp
|
||||
$(CXX) $(CXXFLAGS) -c markdown.cpp
|
||||
TARGET = blog
|
||||
TEST_TARGET = tests
|
||||
|
||||
tests.o: $(TEST_DIR)/tests.cpp config.hpp
|
||||
$(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp
|
||||
.PHONY: all clean test directories
|
||||
|
||||
tests: tests.o config.o utils.o markdown.o
|
||||
g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o $(TEST_DIR)/tests $(TEST_LIBS)
|
||||
all: directories $(TARGET)
|
||||
|
||||
check: tests
|
||||
$(TEST_DIR)/tests
|
||||
directories:
|
||||
@mkdir -p $(BUILD_DIR)/config
|
||||
@mkdir -p $(BUILD_DIR)/format
|
||||
@mkdir -p $(BUILD_DIR)/markdown
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
$(TEST_TARGET): $(TEST_OBJECTS)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $^ $(TEST_LIBS)
|
||||
|
||||
$(BUILD_DIR)/%.o: %.cpp
|
||||
@mkdir -p $(dir $@)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
test: directories $(TEST_TARGET)
|
||||
./$(TEST_TARGET)
|
||||
|
||||
clean:
|
||||
rm -f *.o $(TEST_DIR)/*.o blog $(TEST_DIR)/tests
|
||||
rm -rf $(BUILD_DIR)
|
||||
rm -f $(TARGET) $(TEST_TARGET)
|
||||
|
||||
rebuild: clean all
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "markdown.hpp"
|
||||
#include "utils.hpp"
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <md4c-html.h>
|
||||
@@ -9,21 +7,21 @@
|
||||
#include <sstream>
|
||||
#include <toml++/toml.hpp>
|
||||
|
||||
std::optional<Metadata> get_metadata(const std::string &FILE_PATH) {
|
||||
std::fstream file(FILE_PATH);
|
||||
std::optional<Metadata> get_metadata(const std::string &FILE_CONTENTS) {
|
||||
std::stringstream file_contents(FILE_CONTENTS);
|
||||
std::stringstream metadata_s;
|
||||
std::string buffer;
|
||||
|
||||
/* if there's no ---, then no metadata in file there is */
|
||||
if (!getline(file, buffer) || buffer != "---") {
|
||||
std::cerr << "File " << FILE_PATH << " does not contain metadata. "
|
||||
if (!getline(file_contents, buffer) || buffer != "---") {
|
||||
std::clog << "File does not contain any metadata. Is this intentional?"
|
||||
<< std::endl;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> metadata_map;
|
||||
|
||||
while (getline(file, buffer)) {
|
||||
while (getline(file_contents, buffer)) {
|
||||
if (buffer == "---") {
|
||||
break;
|
||||
}
|
||||
@@ -70,15 +68,15 @@ static void html_callback(const MD_CHAR *data, MD_SIZE size, void *userdata) {
|
||||
out->append(data, size);
|
||||
}
|
||||
|
||||
std::string get_html(const std::string &FILE_PATH) {
|
||||
std::fstream file(FILE_PATH);
|
||||
std::string get_html(const std::string &FILE_CONTENTS) {
|
||||
std::stringstream file_contents(FILE_CONTENTS);
|
||||
std::string buffer, file_string, out;
|
||||
getline(file, buffer);
|
||||
getline(file_contents, buffer);
|
||||
bool is_metadata = buffer == "---";
|
||||
|
||||
/* skip metadata */
|
||||
if (is_metadata) {
|
||||
while (getline(file, buffer)) {
|
||||
while (getline(file_contents, buffer)) {
|
||||
if (buffer == "---") {
|
||||
break;
|
||||
}
|
||||
@@ -87,7 +85,7 @@ std::string get_html(const std::string &FILE_PATH) {
|
||||
file_string += buffer + '\n';
|
||||
}
|
||||
|
||||
while (getline(file, buffer)) {
|
||||
while (getline(file_contents, buffer)) {
|
||||
file_string += buffer + '\n';
|
||||
}
|
||||
|
||||
11
src/test_files/formatter.html
Normal file
11
src/test_files/formatter.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
{{replace_me}}
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 290 KiB After Width: | Height: | Size: 290 KiB |
162
src/tests.cpp
Normal file
162
src/tests.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include "config/config.hpp"
|
||||
#include "format/format.hpp"
|
||||
#include "io/io.hpp"
|
||||
#include "markdown/markdown.hpp"
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace TestFiles {
|
||||
constexpr const char *config_toml = R"([general]
|
||||
lang = "en"
|
||||
title = "Blog"
|
||||
|
||||
[contact]
|
||||
author = "author"
|
||||
email = "email@example.com"
|
||||
signal = "signal url"
|
||||
)";
|
||||
|
||||
constexpr const char *formatter_html = R"(<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
{{replace_me}}
|
||||
</body>
|
||||
</html>)";
|
||||
|
||||
constexpr const char *no_metadata_post_md = R"(# This markdown has no metadata.
|
||||
That's bad. Don't do it. It's for tests only.)";
|
||||
|
||||
constexpr const char *post_md = R"(---
|
||||
[metadata]
|
||||
author = "joseph"
|
||||
date = 2026-01-01
|
||||
title = "Example of a blog post"
|
||||
tags = ["blog", "test", "lalilulelo"]
|
||||
---
|
||||
# This is an example post
|
||||
|
||||
In this example we will do a couple of cool markdown things.
|
||||
|
||||
## This is a h2 header
|
||||
*This text is written in italic!*
|
||||
### Look at this!
|
||||
**This text is BOLD!**
|
||||
|
||||
## Hello world!
|
||||
```cpp
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello world!" << std::endl;
|
||||
}
|
||||
```
|
||||
This is super cool!
|
||||
|
||||
## Time to link some random website!
|
||||
This [should be clickable](https://example.com)
|
||||
|
||||
## Image test
|
||||

|
||||
|
||||
## This is an ordered list
|
||||
1. one
|
||||
2. six
|
||||
3. seven
|
||||
|
||||
## This is an unordered one
|
||||
- six
|
||||
- nine
|
||||
- six
|
||||
- nine)";
|
||||
} // namespace TestFiles
|
||||
|
||||
// IO tests
|
||||
TEST_CASE("Test reading a file successful") {
|
||||
std::string result = read_file("./test_files/config.toml");
|
||||
REQUIRE(result == TestFiles::config_toml);
|
||||
}
|
||||
|
||||
TEST_CASE("Test reading a file that doesn't exist") {
|
||||
REQUIRE_THROWS(read_file("this/path/doesnt/exist"));
|
||||
}
|
||||
|
||||
TEST_CASE("Checking config file read", "[config]") {
|
||||
Config config = get_config(TestFiles::config_toml);
|
||||
|
||||
REQUIRE(config.contact.author == "author");
|
||||
REQUIRE(config.contact.email == "email@example.com");
|
||||
REQUIRE(config.contact.signal == "signal url");
|
||||
REQUIRE(config.general.lang == "en");
|
||||
REQUIRE(config.general.title == "Blog");
|
||||
}
|
||||
|
||||
TEST_CASE("get_metadata function data correctness test") {
|
||||
Metadata result = get_metadata(TestFiles::post_md).value();
|
||||
|
||||
std::string expected_author = "joseph";
|
||||
struct tm datetime = {0};
|
||||
datetime.tm_year = 2026 - 1900;
|
||||
datetime.tm_mon = 1 - 1;
|
||||
datetime.tm_mday = 1;
|
||||
datetime.tm_isdst = 0;
|
||||
|
||||
time_t expected_date = mktime(&datetime);
|
||||
std::string expected_title = "Example of a blog post";
|
||||
std::vector<std::string> expected_tags = {"blog", "test", "lalilulelo"};
|
||||
|
||||
REQUIRE(result.author == expected_author);
|
||||
REQUIRE(result.date == expected_date);
|
||||
REQUIRE(result.title == expected_title);
|
||||
REQUIRE(result.tags == expected_tags);
|
||||
}
|
||||
|
||||
TEST_CASE("get_metadata function test with a file that doesn't have metadata") {
|
||||
std::optional<Metadata> result = get_metadata(TestFiles::no_metadata_post_md);
|
||||
REQUIRE(result == std::nullopt);
|
||||
}
|
||||
|
||||
TEST_CASE("get_html function parsing test") {
|
||||
const std::string EXPECTED_OUTPUT =
|
||||
R"HTML(<h1>This is an example post</h1>
|
||||
<p>In this example we will do a couple of cool markdown things.</p>
|
||||
<h2>This is a h2 header</h2>
|
||||
<p><em>This text is written in italic!</em></p>
|
||||
<h3>Look at this!</h3>
|
||||
<p><strong>This text is BOLD!</strong></p>
|
||||
<h2>Hello world!</h2>
|
||||
<pre><code class="language-cpp">#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello world!" << std::endl;
|
||||
}
|
||||
</code></pre>
|
||||
<p>This is super cool!</p>
|
||||
<h2>Time to link some random website!</h2>
|
||||
<p>This <a href="https://example.com">should be clickable</a></p>
|
||||
<h2>Image test</h2>
|
||||
<p><img src="./image.png" alt="this should show an image"></p>
|
||||
<h2>This is an ordered list</h2>
|
||||
<ol>
|
||||
<li>one</li>
|
||||
<li>six</li>
|
||||
<li>seven</li>
|
||||
</ol>
|
||||
<h2>This is an unordered one</h2>
|
||||
<ul>
|
||||
<li>six</li>
|
||||
<li>nine</li>
|
||||
<li>six</li>
|
||||
<li>nine</li>
|
||||
</ul>
|
||||
)HTML";
|
||||
|
||||
REQUIRE(get_html(TestFiles::post_md) == EXPECTED_OUTPUT);
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
#include "../config.hpp"
|
||||
#include "../markdown.hpp"
|
||||
#include "../utils.hpp"
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Checking config file read", "[config]") {
|
||||
const std::string FILE_NAME = "tests/config.toml";
|
||||
|
||||
Config config = get_config(FILE_NAME);
|
||||
|
||||
REQUIRE(config.contact.author == "author");
|
||||
REQUIRE(config.contact.email == "email@example.com");
|
||||
REQUIRE(config.contact.signal == "signal url");
|
||||
REQUIRE(config.general.lang == "en");
|
||||
REQUIRE(config.general.title == "Blog");
|
||||
}
|
||||
|
||||
TEST_CASE("get_metadata function data correctness test") {
|
||||
const std::string FILE_NAME = "./tests/post.md";
|
||||
Metadata result = get_metadata(FILE_NAME).value();
|
||||
|
||||
std::string expected_author = "joseph";
|
||||
struct tm datetime = {0};
|
||||
datetime.tm_year = 2026 - 1900;
|
||||
datetime.tm_mon = 1 - 1;
|
||||
datetime.tm_mday = 1;
|
||||
datetime.tm_isdst = 0;
|
||||
|
||||
time_t expected_date = mktime(&datetime);
|
||||
std::string expected_title = "Example of a blog post";
|
||||
std::vector<std::string> expected_tags = {"blog", "test", "lalilulelo"};
|
||||
|
||||
REQUIRE(result.author == expected_author);
|
||||
REQUIRE(result.date == expected_date);
|
||||
REQUIRE(result.title == expected_title);
|
||||
REQUIRE(result.tags == expected_tags);
|
||||
}
|
||||
|
||||
TEST_CASE("get_metadata function test with a file that doesn't have metadata") {
|
||||
const std::string FILE_NAME = ".tests/no_metadata_post.md";
|
||||
std::optional<Metadata> result = get_metadata(FILE_NAME);
|
||||
REQUIRE(result == std::nullopt);
|
||||
}
|
||||
|
||||
TEST_CASE("get_html function parsing test") {
|
||||
const std::string INPUT = "./tests/post.md";
|
||||
const std::string EXPECTED_OUTPUT = R"HTML(<h1>This is an example post</h1>
|
||||
<p>In this example we will do a couple of cool markdown things.</p>
|
||||
<h2>This is a h2 header</h2>
|
||||
<p><em>This text is written in italic!</em></p>
|
||||
<h3>Look at this!</h3>
|
||||
<p><strong>This text is BOLD!</strong></p>
|
||||
<h2>Hello world!</h2>
|
||||
<pre><code class="language-cpp">#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello world!" << std::endl;
|
||||
}
|
||||
</code></pre>
|
||||
<p>This is super cool!</p>
|
||||
<h2>Time to link some random website!</h2>
|
||||
<p>This <a href="https://example.com">should be clickable</a></p>
|
||||
<h2>Image test</h2>
|
||||
<p><img src="./image.png" alt="this should show an image"></p>
|
||||
<h2>This is an ordered list</h2>
|
||||
<ol>
|
||||
<li>one</li>
|
||||
<li>six</li>
|
||||
<li>seven</li>
|
||||
</ol>
|
||||
<h2>This is an unordered one</h2>
|
||||
<ul>
|
||||
<li>six</li>
|
||||
<li>nine</li>
|
||||
<li>six</li>
|
||||
<li>nine</li>
|
||||
</ul>
|
||||
)HTML";
|
||||
|
||||
REQUIRE(get_html(INPUT) == EXPECTED_OUTPUT);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
void trim(std::string &str) {
|
||||
str.erase(str.find_last_not_of(' ') + 1);
|
||||
str.erase(0, str.find_first_not_of(' '));
|
||||
str.erase(str.find_last_not_of('"') + 1);
|
||||
str.erase(0, str.find_first_not_of('"'));
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#include <string>
|
||||
|
||||
// trim string in-place, removing all whitespaces and surrounding '"' symbols
|
||||
void trim(std::string &str);
|
||||
Reference in New Issue
Block a user