Add AsciiDoc converter output
This commit is contained in:
1 parent
e5cb11c659
commit
804876656d
7 files changed
+99
-3
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#include "convertasciidoc.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
bool ConverterAsciiDoc::save (const std::string &output_file_name) {
|
||||
if (!parse())
|
||||
return false;
|
||||
|
||||
std::ofstream output (output_file_name, std::ios::trunc);
|
||||
if (!output.is_open()) {
|
||||
std::cerr << "Failed to open output file: "
|
||||
<< output_file_name
|
||||
<< " (" << std::strerror (errno) << ")\n";
|
||||
set_error_code (3);
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &book_titles = titles();
|
||||
for (const auto &title : book_titles) {
|
||||
output << "== " << title << "\n\n";
|
||||
|
||||
for (std::size_t quote_index = 0;
|
||||
quote_index < quote_count (title);
|
||||
++quote_index) {
|
||||
output << "=== " << quote_meta (title, quote_index) << "\n\n";
|
||||
output << "[quote]\n____\n";
|
||||
|
||||
const auto &text_lines = quote_text_lines (title, quote_index);
|
||||
std::size_t line_index = 0;
|
||||
if (!text_lines.empty() && text_lines.front().empty())
|
||||
line_index = 1;
|
||||
|
||||
for (; line_index < text_lines.size(); ++line_index)
|
||||
output << text_lines[line_index] << '\n';
|
||||
|
||||
output << "____\n\n";
|
||||
output << "==== Notes\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
set_error_code (0);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef CONVERTASCIIDOC_H
|
||||
#define CONVERTASCIIDOC_H
|
||||
|
||||
#include "converter.h"
|
||||
|
||||
class ConverterAsciiDoc final : public Converter {
|
||||
public:
|
||||
using Converter::Converter;
|
||||
|
||||
bool save (const std::string &output_file_name) override;
|
||||
};
|
||||
|
||||
#endif // CONVERTASCIIDOC_H
|
||||
@@ -5,6 +5,7 @@ CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += \
|
||||
convertasciidoc.cpp \
|
||||
convertlatex.cpp \
|
||||
convertmarkdown.cpp \
|
||||
convertorg.cpp \
|
||||
@@ -12,6 +13,7 @@ SOURCES += \
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
convertasciidoc.h \
|
||||
convertlatex.h \
|
||||
convertmarkdown.h \
|
||||
convertorg.h \
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "convertasciidoc.h"
|
||||
#include "convertlatex.h"
|
||||
#include "convertmarkdown.h"
|
||||
#include "convertorg.h"
|
||||
@@ -10,8 +11,8 @@
|
||||
|
||||
using ConverterFactory = TypeFactory<std::string, Converter, std::string>;
|
||||
|
||||
static constexpr std::array<const char *, 3> kSupportedTypes = {
|
||||
"latex", "md", "org"
|
||||
static constexpr std::array<const char *, 4> kSupportedTypes = {
|
||||
"latex", "md", "org", "adoc"
|
||||
};
|
||||
|
||||
struct CliArgs {
|
||||
@@ -34,6 +35,7 @@ static void print_supported_types() {
|
||||
|
||||
static ConverterFactory build_converter_factory() {
|
||||
ConverterFactory factory;
|
||||
factory.registerType<ConverterAsciiDoc> ("adoc");
|
||||
factory.registerType<ConverterLatex> ("latex");
|
||||
factory.registerType<ConverterMarkdown> ("md");
|
||||
factory.registerType<ConverterOrg> ("org");
|
||||
|
||||
@@ -5,6 +5,7 @@ CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += \
|
||||
convertasciidoc.cpp \
|
||||
convertlatex.cpp \
|
||||
convertmarkdown.cpp \
|
||||
convertorg.cpp \
|
||||
@@ -12,6 +13,7 @@ SOURCES += \
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
convertasciidoc.h \
|
||||
convertlatex.h \
|
||||
convertmarkdown.h \
|
||||
convertorg.h \
|
||||
|
||||
Reference in new issue
Block a user