Small html cleanup
This commit is contained in:
parent
c102ebb6da
commit
31b479e9f6
27 changed files with 330 additions and 252 deletions
|
@ -22,6 +22,7 @@ list(APPEND publishing_LIB_INCLUDES
|
|||
pdf/PdfStream.cpp
|
||||
pdf/PdfXRefTable.cpp
|
||||
pdf/PdfWriter.cpp
|
||||
DocumentConverter.cpp
|
||||
)
|
||||
|
||||
add_library(publishing SHARED ${publishing_LIB_INCLUDES} ${publishing_INCLUDES} ${publishing_HEADERS})
|
||||
|
@ -31,6 +32,6 @@ target_include_directories(publishing PUBLIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/pdf"
|
||||
)
|
||||
set_target_properties( publishing PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
target_link_libraries( publishing PUBLIC core)
|
||||
target_link_libraries( publishing PUBLIC core web)
|
||||
|
||||
set_property(TARGET publishing PROPERTY FOLDER src)
|
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();
|
||||
}
|
17
src/publishing/DocumentConverter.h
Normal file
17
src/publishing/DocumentConverter.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class File;
|
||||
|
||||
class DocumentConverter
|
||||
{
|
||||
public:
|
||||
DocumentConverter();
|
||||
|
||||
void convert(File* input, File* output);
|
||||
|
||||
void convertMarkdown(File* input, File* output);
|
||||
|
||||
void markdownToHtml(File* input, File* output);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue