aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-10-28 01:59:24 -0700
committerPinapelz <yukais@pinapelz.com>2025-10-28 01:59:24 -0700
commit29a0ab1f2b04a9b9a45282b6c9026136b1ed1f6d (patch)
tree8b457773e85f161322b30f86f3ee7c51f7630dea
parent9c00965a149b2f9697f5c07a390cf2b0bc675d4d (diff)
set CSS theme as a member variable
-rw-r--r--include/markdown_translator.hpp18
-rw-r--r--src/main.cpp4
-rw-r--r--src/markdown_translator.cpp43
3 files changed, 30 insertions, 35 deletions
diff --git a/include/markdown_translator.hpp b/include/markdown_translator.hpp
index 6eb32f8..8bf6c84 100644
--- a/include/markdown_translator.hpp
+++ b/include/markdown_translator.hpp
@@ -13,9 +13,13 @@ public:
// Destructor
~MarkdownTranslator();
// Main translation function - takes markdown content and returns HTML
- std::string translate(const std::string& markdownContent, const std::string& cssPath = "styles/carbon.css");
+ std::string translate(const std::string& markdownContent);
std::string processLine(const std::string& line);
+ enum Theme {
+ carbon
+ };
+
private:
// Regex for various tags
const std::string headerRegexStr{"^(#{1,6})\\s+(.*)$"};
@@ -48,7 +52,7 @@ private:
}
// HTML builders
- std::string buildHTMLHeader(const std::string& title, const std::string& cssPath){
+ std::string buildHTMLHeader(const std::string& title){
return R"(<!DOCTYPE html>
<html lang="en">
<head>
@@ -72,8 +76,18 @@ private:
)";
}
+ void setTheme(const Theme& theme){
+ switch(theme){
+ case Theme::carbon:
+ cssPath = "styles/carbon.css";
+ default:
+ cssPath = "styles/carbon.css";
+ }
+ }
+
// Member variables
std::string title;
+ std::string cssPath{"styles/carbon.css"};
};
#endif // MARKDOWN_TRANSLATOR_H
diff --git a/src/main.cpp b/src/main.cpp
index 82f16c2..e926df7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -64,12 +64,12 @@ int main(int argc, char* argv[]) {
MarkdownTranslator translator;
// Get CSS path from parameters or use default
- std::string cssPath = "styles/ffxiv-style.css";
+ std::string cssPath = "";
if (params.find("-css") != params.end()) {
cssPath = params["-css"];
}
- std::string htmlOutput = translator.translate(markdownContent, cssPath);
+ std::string htmlOutput = translator.translate(markdownContent);
// Write to output file
std::string outputFile = params["-o"];
diff --git a/src/markdown_translator.cpp b/src/markdown_translator.cpp
index 3c97874..5bd1cc4 100644
--- a/src/markdown_translator.cpp
+++ b/src/markdown_translator.cpp
@@ -3,7 +3,7 @@
#include <iostream>
#include <algorithm>
-MarkdownTranslator::MarkdownTranslator() : title("Carbon") {
+MarkdownTranslator::MarkdownTranslator() : title("WikiMD2HTML") {
}
@@ -25,50 +25,31 @@ void MarkdownTranslator::processMetadata(const std::vector<std::string>& lines){
}
}
-std::string MarkdownTranslator::translate(const std::string& markdownContent, const std::string& cssPath) {
+std::string MarkdownTranslator::translate(const std::string& markdownContent) {
std::stringstream htmlOutput;
std::stringstream markdownStream(markdownContent);
std::string line;
std::vector<std::string> headers;
-
std::string currentLine;
+ // Parse metadata section if it exists
bool metadataExists{false};
std::vector<std::string> metadataLines;
- while (std::getline(markdownStream, currentLine)) {
- if(currentLine == "---"){
- if(metadataExists){
+ if (std::getline(markdownStream, currentLine) && currentLine == "---") {
+ metadataExists = true;
+ while (std::getline(markdownStream, currentLine)) {
+ if (currentLine == "---") {
break;
- } else {
- metadataExists = true;
- continue;
}
+ metadataLines.push_back(currentLine);
}
- if(!metadataExists){
- break;
- }
- metadataLines.push_back(currentLine);
}
- processMetadata(metadataLines);
- while (std::getline(markdownStream, currentLine)) {
- std::regex headerRegex("^(#{1,3})\\s+(.*)$");
- std::smatch matches;
- if (std::regex_match(currentLine, matches, headerRegex)) {
- int level = matches[1].length();
- std::string content = matches[2];
- if (level <= 3) {
- headers.push_back(std::to_string(level) + ":" + content);
- }
- }
- }
- markdownStream.clear();
- markdownStream.str(markdownContent);
-
- htmlOutput << buildHTMLHeader(title, cssPath);
- // Add navigation sidebar
+ // Process and apply metadata to curr object
+ if(metadataExists)
+ processMetadata(metadataLines);
+ htmlOutput << buildHTMLHeader(title);
generateSideBar(htmlOutput, headers);
-
// Main content container
htmlOutput << " <div class=\"main-content\">\n";
htmlOutput << " <div class=\"container\">\n";
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage