Adds wrapper to md4c code, fixes issues with previous commit
This commit is contained in:
parent
6d98202f38
commit
d19c822764
31 changed files with 175 additions and 1722 deletions
|
@ -1,18 +1,36 @@
|
|||
#include "BlogParser.h"
|
||||
|
||||
BlogParser::BlogParser()
|
||||
{
|
||||
|
||||
|
||||
|
||||
void BlogParser::saveTextToFile(const MD_CHAR* text, MD_SIZE size, void* userDataVoid)
|
||||
{
|
||||
std::string fileUrl = ((UserData*)userDataVoid)->outputFileName;
|
||||
|
||||
std::ofstream file;
|
||||
file.open(fileUrl, std::ios_base::app);
|
||||
file.write(text, size);
|
||||
file.close();
|
||||
|
||||
text = 0;
|
||||
}
|
||||
|
||||
std::string BlogParser::ParseText(std::string text)
|
||||
{
|
||||
std::string result;
|
||||
std::string currentTag;
|
||||
|
||||
// for (char c : text)
|
||||
// {
|
||||
// if (c is first)
|
||||
// }
|
||||
return "";
|
||||
int BlogParser::parse(std::string inputFileName, std::string outputFileName)
|
||||
{
|
||||
std::ifstream file(inputFileName);
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
file.close();
|
||||
|
||||
std::string text = buffer.str();
|
||||
int length = text.length();
|
||||
|
||||
UserData* userData = new UserData();
|
||||
userData->outputFileName = outputFileName;
|
||||
|
||||
void* userDataVoid = userData;
|
||||
|
||||
return md_html(text.c_str(), length, saveTextToFile, userDataVoid, 0, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Libs/md4c-html.h"
|
||||
|
||||
/*
|
||||
* Essentially just a wrapper for md4c's C code so thats its easier
|
||||
* for my squishy little brain to handle
|
||||
*/
|
||||
class BlogParser
|
||||
{
|
||||
private:
|
||||
static void saveTextToFile(const MD_CHAR* text, MD_SIZE size, void* unneeded);
|
||||
struct UserData{
|
||||
std::string outputFileName;
|
||||
};
|
||||
|
||||
public:
|
||||
BlogParser();
|
||||
std::string ParseText(std::string text);
|
||||
int parse(std::string inputFileName, std::string outputFileName);
|
||||
};
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
add_library(md4c md4c.c)
|
||||
add_library(md4c-html md4c-html.c entity.c md4c.c)
|
||||
|
||||
#add_compile_options(-fpermissive -w)
|
||||
|
|
43
Src/blog.cpp
43
Src/blog.cpp
|
@ -1,45 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Libs/md4c-html.h"
|
||||
|
||||
#define MD4C_USE_UTF8
|
||||
|
||||
void SaveTextToFile(const MD_CHAR* text, MD_SIZE size, void* unneeded)
|
||||
{
|
||||
static int timesCalled = 0;
|
||||
// printf("Times called: %i\n", timesCalled++);
|
||||
// printf("This time we were given:\n");
|
||||
// printf(text);
|
||||
// printf("\n\n\n\n");
|
||||
|
||||
std::string fileUrl = "../../outputfile.html";
|
||||
|
||||
std::ofstream file;
|
||||
file.open(fileUrl, std::ios_base::app);
|
||||
file << text;
|
||||
file.close();
|
||||
}
|
||||
#include "BlogParser.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::ifstream file;
|
||||
file.open("../../inputfile.md");
|
||||
BlogParser* parser = new BlogParser();
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
|
||||
file.close();
|
||||
|
||||
std::string text = buffer.str();
|
||||
int length = text.length();
|
||||
|
||||
int endCode = md_html(text.c_str(), length, SaveTextToFile, NULL, 0, 1);
|
||||
printf("program finished with code %i\n", endCode);
|
||||
std::string in = "../../inputfile.md";
|
||||
std::string out = "../../outputfile.html";
|
||||
parser->parse(in, out);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue