Replace more characters for tag-anchors.

Asciidoctor doesn't like ₀-₉ and ⁰-⁹.
This commit is contained in:
tastytea 2019-05-20 10:44:27 +02:00
parent c08c6e0314
commit 344e77d8bf
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 30 additions and 7 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2) cmake_minimum_required (VERSION 3.2)
project(remwharead project(remwharead
VERSION 0.2.1 VERSION 0.2.2
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -95,7 +95,7 @@ void export_adoc(const vector<Database::entry> &entries, ostream &out)
alltags.insert({ tag, { entry } }); alltags.insert({ tag, { entry } });
} }
out << "xref:" << replace_spaces(tag) << "[" << tag << ']'; out << "xref:" << replace_in_tags(tag) << "[" << tag << ']';
if (tag != *(entry.tags.rbegin())) if (tag != *(entry.tags.rbegin()))
{ {
out << ", "; out << ", ";
@ -143,7 +143,7 @@ void export_adoc(const vector<Database::entry> &entries, ostream &out)
for (const auto &tag : sortedtags) for (const auto &tag : sortedtags)
{ {
out << "=== [[" << replace_spaces(tag.first) << "]]" out << "=== [[" << replace_in_tags(tag.first) << "]]"
<< tag.first << endl; << tag.first << endl;
for (const Database::entry &entry : tag.second) for (const Database::entry &entry : tag.second)
{ {
@ -161,7 +161,30 @@ void export_adoc(const vector<Database::entry> &entries, ostream &out)
} }
} }
const string replace_spaces(const string &text) const string replace_in_tags(string text)
{ {
return regex_replace(text, regex(" "), "-"); // TODO: Find a better solution.
const std::map<const string, const string> searchreplace =
{
{ " ", "-" },
{ "", "0" }, { "", "0" },
{ "", "1" }, { "¹", "1" },
{ "", "2" }, { "²", "2" },
{ "", "3" }, { "³", "3" },
{ "", "4" }, { "", "4" },
{ "", "5" }, { "", "5" },
{ "", "6" }, { "", "6" },
{ "", "7" }, { "", "7" },
{ "", "8" }, { "", "8" },
{ "", "9" }, { "", "9" }
};
for (const std::pair<const string, const string> &sr : searchreplace)
{
size_t pos = 0;
while ((pos = text.find(sr.first, pos)) != std::string::npos)
{
text.replace(pos, sr.first.length(), sr.second);
}
}
return text;
} }

View File

@ -30,7 +30,7 @@ void export_csv(const vector<Database::entry> &entries, ostream &out = cout);
const string quote_csv(const string &field); const string quote_csv(const string &field);
void export_adoc(const vector<Database::entry> &entries, ostream &out = cout); void export_adoc(const vector<Database::entry> &entries, ostream &out = cout);
//! Replaces spaces with -. //! Replaces characters in tags that asciidoctor doesn't like.
const string replace_spaces(const string &text); const string replace_in_tags(string text);
#endif // REMWHAREAD_EXPORT_HPP #endif // REMWHAREAD_EXPORT_HPP