From 622ccb9a039740d6014a5348249793e131b95950 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 26 Jun 2019 19:55:05 +0200 Subject: [PATCH] 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;