Add language attribute to HTML output.

Bug: #16
This commit is contained in:
tastytea 2021-08-20 16:59:43 +02:00
parent 299063e02c
commit b1dcdea95e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07

View File

@ -140,8 +140,10 @@ void html_all(const std::vector<std::vector<search::match>> &matches_all,
{
std::uint64_t count{1};
cout << "<!DOCTYPE html>\n"
<< "<html><head><title>epubgrep output</title>"
cout << "<!DOCTYPE html>\n";
// Translators: Replace “en” with your language code here.
cout << format(R"(<html lang="{0:s}">)", translate("en").str());
cout << "<head><title>epubgrep output</title>"
"<style>article { margin: 1em; }</style>"
"</head><body>\n\n";
@ -182,6 +184,15 @@ void html_all(const std::vector<std::vector<search::match>> &matches_all,
for (const auto &match : matches)
{
const auto lang{[&match]
{
if (!match.language.empty())
{
return format(R"( lang="{0:s}")",
match.language);
}
return std::string{};
}()};
cout << " <tr>\n";
if (!opts.no_fn_epub)
{
@ -190,15 +201,16 @@ void html_all(const std::vector<std::vector<search::match>> &matches_all,
match.filepath_inside)
<< '\n';
}
cout << format(R"( <td headers="headline_{0:d}">{1:s}</td>)",
count, match.headline)
cout << format(
R"( <td headers="headline_{0:d}"{1:s}>{2:s}</td>)", count,
lang, match.headline)
<< '\n';
cout << format(R"( <td headers="page_{0:d}">{1:s}</td>)",
count, match.page)
<< '\n';
cout << format(R"( <td headers="match_{0:d}">{1:s})"
R"(<strong>{2:s}</strong>{3:s}</td>)",
count, match.context.first, match.text,
cout << format(R"( <td headers="match_{0:d}"{1:s}>{2:s})"
R"(<strong>{3:s}</strong>{4:s}</td>)",
count, lang, match.context.first, match.text,
match.context.second)
<< '\n';
cout << " </tr>\n";