mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-10-27 19:20:41 +01:00
added get_html() function
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "markdown.hpp"
|
#include "markdown.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -41,3 +42,33 @@ std::optional<Metadata> get_metadata(const std::string &FILE_PATH) {
|
|||||||
metadata_map["title"],
|
metadata_map["title"],
|
||||||
convert_string_to_set(metadata_map["tags"])});
|
convert_string_to_set(metadata_map["tags"])});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void html_callback(const MD_CHAR *data, MD_SIZE size, void *userdata) {
|
||||||
|
std::string *out = static_cast<std::string *>(userdata);
|
||||||
|
out->append(data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_html(const std::string &FILE_PATH) {
|
||||||
|
std::fstream file(FILE_PATH);
|
||||||
|
std::string buffer, file_string, out;
|
||||||
|
getline(file, buffer);
|
||||||
|
bool is_metadata = buffer == "---";
|
||||||
|
|
||||||
|
/* skip metadata */
|
||||||
|
if (is_metadata) {
|
||||||
|
while (getline(file, buffer)) {
|
||||||
|
if (buffer == "---") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
file_string += buffer + '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
while (getline(file, buffer)) {
|
||||||
|
file_string += buffer + '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
md_html(file_string.c_str(), file_string.size(), html_callback, &out, 0, 0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user