From 763a9410424fb43e29384255459fd9cdc70ef314 Mon Sep 17 00:00:00 2001 From: Szymon P Date: Thu, 8 Jan 2026 11:36:05 +0100 Subject: [PATCH] created formatter --- src/formatter.cpp | 31 +++++++++++++++++++++++++++++++ src/formatter.hpp | 0 2 files changed, 31 insertions(+) create mode 100644 src/formatter.cpp create mode 100644 src/formatter.hpp diff --git a/src/formatter.cpp b/src/formatter.cpp new file mode 100644 index 0000000..a96845e --- /dev/null +++ b/src/formatter.cpp @@ -0,0 +1,31 @@ +#include "markdown.hpp" +#include +#include +#include + +bool replace(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; +} + +// 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) { + std::string result; + std::ifstream file(FILE_NAME); + if (!file.is_open()) { + return ""; + } + std::ostringstream ss; + ss << file.rdbuf(); + result = ss.str(); + if (replace(result, TEMPLATE, HTML)) { + return result; + } + return ""; +} diff --git a/src/formatter.hpp b/src/formatter.hpp new file mode 100644 index 0000000..e69de29