Tidy up some xml structures.
This commit is contained in:
parent
875cdc84ff
commit
8771b721d1
31 changed files with 885 additions and 563 deletions
76
src/web/DocumentConverter.cpp
Normal file
76
src/web/DocumentConverter.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "DocumentConverter.h"
|
||||
#include "MarkdownParser.h"
|
||||
#include "HtmlWriter.h"
|
||||
#include "FileLogger.h"
|
||||
#include <fstream>
|
||||
|
||||
DocumentConverter::DocumentConverter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DocumentConverter::Convert(File* input, File* output)
|
||||
{
|
||||
if(!input || !output)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto input_format = input->InferFormat();
|
||||
switch (input_format)
|
||||
{
|
||||
case FileFormat::Format::Markdown:
|
||||
{
|
||||
ConvertMarkdown(input, output);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentConverter::ConvertMarkdown(File* input, File* output)
|
||||
{
|
||||
const auto output_format = output->InferFormat();
|
||||
switch (output_format)
|
||||
{
|
||||
case FileFormat::Format::Html:
|
||||
{
|
||||
MarkdownToHtml(input, output);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentConverter::MarkdownToHtml(File* input, File* output)
|
||||
{
|
||||
MLOG_INFO("Converting Markdown to Html");
|
||||
input->SetAccessMode(File::AccessMode::Read);
|
||||
input->Open();
|
||||
|
||||
MarkdownParser parser;
|
||||
|
||||
auto handle = input->GetInHandle();
|
||||
while(handle->good())
|
||||
{
|
||||
std::string line;
|
||||
std::getline(*handle, line);
|
||||
parser.ProcessLine(line);
|
||||
};
|
||||
input->Close();
|
||||
|
||||
auto html_document = parser.GetHtml();
|
||||
HtmlWriter writer;
|
||||
std::string html_string = writer.ToString(html_document);
|
||||
|
||||
output->SetAccessMode(File::AccessMode::Write);
|
||||
output->Open();
|
||||
*(output->GetOutHandle()) << html_string;
|
||||
output->Close();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue