diff --git a/.drone.yml b/.drone.yml index e018c9b..f848e03 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,7 +26,7 @@ steps: CXXFLAGS: -pipe -O2 commands: - rm /etc/apt/apt.conf.d/docker-clean - - rm /var/cache/apt/archives/lock + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list - apt-get update -q @@ -51,7 +51,7 @@ steps: CXXFLAGS: -pipe -O2 commands: - rm /etc/apt/apt.conf.d/docker-clean - - rm /var/cache/apt/archives/lock + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list @@ -79,7 +79,7 @@ steps: CXXFLAGS: -pipe -O2 commands: - rm /etc/apt/apt.conf.d/docker-clean - - rm /var/cache/apt/archives/lock + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - apt-get update -q - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list @@ -107,7 +107,7 @@ steps: CXXFLAGS: -pipe -O2 commands: - rm /etc/apt/apt.conf.d/docker-clean - - rm /var/cache/apt/archives/lock + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list - apt-get update -q @@ -129,7 +129,7 @@ steps: CXXFLAGS: -pipe -O2 commands: - rm /etc/apt/apt.conf.d/docker-clean - - rm /var/cache/apt/archives/lock + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list - echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list @@ -190,7 +190,7 @@ steps: CXXFLAGS: -pipe -O2 commands: - rm /etc/apt/apt.conf.d/docker-clean - - rm /var/cache/apt/archives/lock + - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release - echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list - apt-get update -q diff --git a/CMakeLists.txt b/CMakeLists.txt index c98e8ef..c99330c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(remwharead - VERSION 0.4.1 + VERSION 0.4.3 LANGUAGES CXX ) diff --git a/src/adoc.cpp b/src/adoc.cpp index 1ad99d5..dc79fbb 100644 --- a/src/adoc.cpp +++ b/src/adoc.cpp @@ -40,9 +40,9 @@ void Export::AsciiDoc::print() const << ":Author: remwharead " << global::version << endl << ":Date: " << timepoint_to_string(system_clock::now()) << endl - << ":TOC: right" << endl - << ":TOCLevels: 2" << endl - << endl; + << ":TOC: right\n" + << ":TOCLevels: 2\n" + << ":!webfonts:\n\n"; tagmap alltags; string day; @@ -57,7 +57,7 @@ void Export::AsciiDoc::print() const } _out << "[[dt_" << timepoint_to_string(entry.datetime) << "]]\n"; - _out << "* link:" << entry.uri; + _out << "* link:" << replace_in_uri(entry.uri); if (!entry.title.empty()) { _out << '[' << replace_in_title(entry.title) << ']'; @@ -71,7 +71,8 @@ void Export::AsciiDoc::print() const _out << '_' << get_time(entry).substr(0, 5) << '_'; if (!entry.archive_uri.empty()) { - _out << " (link:" << entry.archive_uri << "[archived version])"; + _out << " (link:" << replace_in_uri(entry.archive_uri) + << "[archived version])"; } bool separator = false; @@ -146,6 +147,9 @@ const string Export::AsciiDoc::replace_in_tag(const string &text) const { "&", "-" }, { "/", "-" }, { "=", "-" }, { "^", "-" }, { "!", "-" }, { "?", "-" }, + { "'", "-" }, { "\"", "-" }, + { "´", "-" }, { "`", "-" }, + { "’", "-" }, { "#", "-" }, { "₀", "0" }, { "⁰", "0" }, { "₁", "1" }, { "¹", "1" }, { "₂", "2" }, { "²", "2" }, @@ -167,6 +171,14 @@ const string Export::AsciiDoc::replace_in_title(const string &text) const return replace(text, {{ "]", "\\]" }}); } +const string Export::AsciiDoc::replace_in_uri(const string &text) const +{ + return replace(text, + { + { "[", "%5B" }, { "]", "%5D" } + }); +} + void Export::AsciiDoc::print_tags(const tagmap &tags) const { _out << "== Tags\n\n"; diff --git a/src/adoc.hpp b/src/adoc.hpp index c15c1a3..f94dff8 100644 --- a/src/adoc.hpp +++ b/src/adoc.hpp @@ -43,6 +43,8 @@ namespace Export const string replace_in_tag(const string &text) const; //! Replaces characters in title that asciidoctor doesn't like. const string replace_in_title(const string &text) const; + //! Replaces characters in URI that asciidoctor doesn't like. + const string replace_in_uri(const string &text) const; void print_tags(const tagmap &tags) const; const string get_day(const Database::entry &entry) const; const string get_time(const Database::entry &entry) const; diff --git a/src/uri.cpp b/src/uri.cpp index 802c369..2dd9646 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -64,7 +64,7 @@ const html_extract URI::get() return { extract_title(answer), - strip_html(extract_description(answer)), + extract_description(answer), strip_html(answer) }; } @@ -106,7 +106,7 @@ const string URI::extract_description(const string &html) smatch match; const regex re("description\"[^>]+content=\"([^\"]+)", icase); regex_search(html, match, re); - return remove_newlines(match[1].str()); + return remove_newlines(strip_html(match[1].str())); } return ""; @@ -509,11 +509,18 @@ const string URI::archive() const string URI::remove_newlines(string text) { - size_t pos = 0; - while ((pos = text.find("\n", pos)) != std::string::npos) + size_t posn = 0; + while ((posn = text.find('\n', posn)) != std::string::npos) { - text.replace(pos, 1, " "); - ++pos; + text.replace(posn, 1, " "); + + size_t posr = posn - 1; + if (text[posr] == '\r') + { + text.replace(posr, 1, " "); + } + ++posn; } + return text; } diff --git a/tests/test_adoc.cpp b/tests/test_adoc.cpp index 6d213a8..586f0cc 100644 --- a/tests/test_adoc.cpp +++ b/tests/test_adoc.cpp @@ -55,7 +55,8 @@ SCENARIO ("The AsciiDoc export works correctly") ":Author: +remwharead \\d+\\.\\d+\\.\\d+\n" ":Date: +\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\n" ":TOC: +right\n" - ":TOCLevels: +2\n\n"); + ":TOCLevels: +2\n" + ":!webfonts:\n\n"); const regex re_dates ("== 1970-01-01\n\n" "\\[\\[dt_1970-01-01T\\d{2}:\\d{2}:\\d{2}\\]\\]\n"