Add Org mode converter output
This commit is contained in:
1 parent
432a1dc223
commit
e5cb11c659
7 files changed
+98
-3
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#include "convertorg.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
bool ConverterOrg::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 << "#+begin_quote\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 << "#+end_quote\n\n";
|
||||
output << "*** Notes\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
set_error_code (0);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef CONVERTORG_H
|
||||
#define CONVERTORG_H
|
||||
|
||||
#include "converter.h"
|
||||
|
||||
class ConverterOrg final : public Converter {
|
||||
public:
|
||||
using Converter::Converter;
|
||||
|
||||
bool save (const std::string &output_file_name) override;
|
||||
};
|
||||
|
||||
#endif // CONVERTORG_H
|
||||
@@ -7,11 +7,13 @@ CONFIG -= qt
|
||||
SOURCES += \
|
||||
convertlatex.cpp \
|
||||
convertmarkdown.cpp \
|
||||
convertorg.cpp \
|
||||
converter.cpp \
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
convertlatex.h \
|
||||
convertmarkdown.h \
|
||||
convertorg.h \
|
||||
converter.h \
|
||||
typefactory.h
|
||||
@@ -5,12 +5,13 @@
|
||||
|
||||
#include "convertlatex.h"
|
||||
#include "convertmarkdown.h"
|
||||
#include "convertorg.h"
|
||||
#include "typefactory.h"
|
||||
|
||||
using ConverterFactory = TypeFactory<std::string, Converter, std::string>;
|
||||
|
||||
static constexpr std::array<const char *, 2> kSupportedTypes = {
|
||||
"latex", "md"
|
||||
static constexpr std::array<const char *, 3> kSupportedTypes = {
|
||||
"latex", "md", "org"
|
||||
};
|
||||
|
||||
struct CliArgs {
|
||||
@@ -35,6 +36,7 @@ static ConverterFactory build_converter_factory() {
|
||||
ConverterFactory factory;
|
||||
factory.registerType<ConverterLatex> ("latex");
|
||||
factory.registerType<ConverterMarkdown> ("md");
|
||||
factory.registerType<ConverterOrg> ("org");
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,13 @@ CONFIG -= qt
|
||||
SOURCES += \
|
||||
convertlatex.cpp \
|
||||
convertmarkdown.cpp \
|
||||
convertorg.cpp \
|
||||
converter.cpp \
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
convertlatex.h \
|
||||
convertmarkdown.h \
|
||||
convertorg.h \
|
||||
converter.h \
|
||||
typefactory.h
|
||||
Reference in new issue
Block a user