aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp4
-rw-r--r--src/markdown_translator.cpp43
2 files changed, 14 insertions, 33 deletions
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