From 622ccb9a039740d6014a5348249793e131b95950 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 26 Jun 2019 19:55:05 +0200 Subject: [PATCH 1/5] AsciiDoc export: Escape '[' and ']' in URIs. --- CMakeLists.txt | 2 +- src/adoc.cpp | 13 +++++++++++-- src/adoc.hpp | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c98e8ef..85a7352 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.2 LANGUAGES CXX ) diff --git a/src/adoc.cpp b/src/adoc.cpp index 1ad99d5..cf4be20 100644 --- a/src/adoc.cpp +++ b/src/adoc.cpp @@ -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; @@ -167,6 +168,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; From be23e8e917527d084946eeeccce9020428715583 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 26 Jun 2019 20:03:28 +0200 Subject: [PATCH 2/5] CI: Remove lockfiles before running apt-get. --- .drone.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 From 47bcffec64a47b795fbf593f5a163bc16018eb97 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 6 Jul 2019 18:11:44 +0200 Subject: [PATCH 3/5] =?UTF-8?q?Replace=20',=20",=20=C2=B4,=20`,=20?= =?UTF-8?q?=E2=80=99=20and=20#=20in=20tags=20in=20AsciiDoc=20output.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/adoc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/adoc.cpp b/src/adoc.cpp index cf4be20..dce9b6c 100644 --- a/src/adoc.cpp +++ b/src/adoc.cpp @@ -147,6 +147,9 @@ const string Export::AsciiDoc::replace_in_tag(const string &text) const { "&", "-" }, { "/", "-" }, { "=", "-" }, { "^", "-" }, { "!", "-" }, { "?", "-" }, + { "'", "-" }, { "\"", "-" }, + { "´", "-" }, { "`", "-" }, + { "’", "-" }, { "#", "-" }, { "₀", "0" }, { "⁰", "0" }, { "₁", "1" }, { "¹", "1" }, { "₂", "2" }, { "²", "2" }, From ff708e9403b092acac1f4f26e4ea378acca15fe6 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 12 Jul 2019 01:49:32 +0200 Subject: [PATCH 4/5] AsciiDoc export: Disable webfonts. --- src/adoc.cpp | 6 +++--- tests/test_adoc.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/adoc.cpp b/src/adoc.cpp index dce9b6c..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; 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" From a83a2548c3d1faab210c9e959a7dc23511a1a301 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 13 Jul 2019 18:20:37 +0200 Subject: [PATCH 5/5] Remove HTML-encoded newlines in descriptions. We didn't catch newlines encoded as HTML entities before. --- CMakeLists.txt | 2 +- src/uri.cpp | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85a7352..c99330c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(remwharead - VERSION 0.4.2 + VERSION 0.4.3 LANGUAGES CXX ) 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; }