Small html cleanup
This commit is contained in:
parent
c102ebb6da
commit
31b479e9f6
27 changed files with 330 additions and 252 deletions
75
src/publishing/DocumentConverter.cpp
Normal file
75
src/publishing/DocumentConverter.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "DocumentConverter.h"
|
||||
#include "MarkdownParser.h"
|
||||
#include "HtmlWriter.h"
|
||||
#include "FileLogger.h"
|
||||
#include "File.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->open(File::AccessMode::Read);
|
||||
|
||||
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.get());
|
||||
|
||||
output->open(File::AccessMode::Write);
|
||||
*(output->getOutHandle()) << html_string;
|
||||
output->close();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue