startgitStatic page generator for git repositories |
git clone git://git.dimitrijedobrota.com/startgit.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
commit | 7291b93a9bf785883cb4e0e5c372f7b488dfaba9 |
parent | fe50b5aad2d23362849307ca081f588e9758bb21 |
author | Dimitrije Dobrota < mail@dimitrijedobrota.com > |
date | Fri, 2 May 2025 21:02:33 +0200 |
Fix 'span white-space: pre' error
M | source/document.cpp | | | ++++ - |
M | source/startgit.cpp | | | +++++++++++++++++++++++++++++++++++++ --------------------------------- |
M | source/utils.cpp | | | + -------------- |
3 files changed, 42 insertions(+), 48 deletions(-)
diff --git a/ source/document.cpp b/ source/document.cpp
@@ -125,7 +125,10 @@
void document::render(std::ostream& ost, const content_t& content) const
" color: var(--theme_green);"
"} .del {"
" color: var(--theme_red);"
"}"},
"} .inline {"
" white-space: pre;"
"}"
},
},
},
};
diff --git a/ source/startgit.cpp b/ source/startgit.cpp
@@ -275,32 +275,34 @@
element diff_hunk(const hunk& hunk)
hunk->new_lines
),
xmlencode(header.substr(header.rfind('@') + 2)),
span {
{{"style", "white-space: pre"}},
transform(
hunk.get_lines(),
[](const auto& line) -> element
{
using hemplate::html::div;
if (line.is_add()) {
return div {
{{"class", "add"}},
xmlencode(line.get_content()),
};
}
if (line.is_del()) {
return div {
{{"class", "del"}},
xmlencode(line.get_content()),
};
}
return element(xmlencode(line.get_content()));
}
),
},
},
span {
transform(
hunk.get_lines(),
[](const auto& line) -> element
{
using hemplate::html::div;
if (line.is_add()) {
return div {
{{"class", "inline add"}},
xmlencode(line.get_content()),
};
}
if (line.is_del()) {
return div {
{{"class", "inline del"}},
xmlencode(line.get_content()),
};
}
return div {
{{"class", "inline"}},
xmlencode(line.get_content()),
};
}
),
},
};
}
@@ -377,7 +379,7 @@
element commit_diff(const commit& commit)
},
br {},
p {
{{"style", "white-space: pre;"}},
{{"class", "inline"}},
xmlencode(commit.get_message()),
},
file_changes(commit.get_diff()),
@@ -418,16 +420,18 @@
element write_file_content(const file& file)
int count = 0;
return span {
{{"style", "white-space: pre;"}},
transform(
lines,
[&](const auto& line)
{
return std::format(
R"(<a id="{0}" href="#{0}">{0:5}</a> {1})",
count++,
xmlencode(line)
);
return hemplate::html::div {
{{"class", "inline"}},
std::format(
R"(<a id="{0}" href="#{0}">{0:5}</a> {1})",
count++,
xmlencode(line)
)
};
}
),
};
diff --git a/ source/utils.cpp b/ source/utils.cpp
@@ -34,20 +34,6 @@
std::string time_long(const git2wrap::time& time)
// NOLINTBEGIN
// clang-format off
void xmlencode(std::ostream& ost, const std::string& str)
{
for (const char c: str) {
switch(c) {
case '<': ost << "<"; continue;
case '>': ost << ">"; continue;
case '\'': ost << "'"; continue;
case '&': ost << "&"; continue;
case '"': ost << """; continue;
}
ost << c;
}
}
std::string xmlencode(const std::string& str)
{
std::string res;
@@ -60,6 +46,7 @@
std::string xmlencode(const std::string& str)
case '\'': res += "'"; continue;
case '&': res += "&"; continue;
case '"': res += """; continue;
case '\n': res += "<br>"; continue;
}
res += c;
}