Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
with:
python-version: 3.12
- name: install python dependencies
run: pip install htmlcmp==1.0.12
run: pip install htmlcmp==1.2.1

- name: download binaries
uses: actions/download-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions cli/src/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(const int argc, char **argv) {

HtmlConfig config;
config.editable = true;
config.format_html = true;

const std::string output_tmp = output + "/tmp";
std::filesystem::create_directories(output_tmp);
Expand Down
1 change: 0 additions & 1 deletion src/odr/internal/html/common.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <odr/internal/html/common.hpp>

#include <odr/internal/abstract/file.hpp>
#include <odr/internal/common/path.hpp>
#include <odr/internal/crypto/crypto_util.hpp>
#include <odr/internal/util/stream_util.hpp>
#include <odr/internal/util/string_util.hpp>
Expand Down
7 changes: 4 additions & 3 deletions src/odr/internal/html/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,10 @@ class PageHtmlFragment final : public HtmlFragmentBase {

namespace odr::internal {

odr::HtmlService html::create_document_service(
const Document &document, const std::string & /*cache_path*/,
HtmlConfig config, std::shared_ptr<Logger> logger) {
HtmlService html::create_document_service(const Document &document,
const std::string & /*cache_path*/,
HtmlConfig config,
std::shared_ptr<Logger> logger) {
std::vector<std::shared_ptr<HtmlFragmentBase>> fragments;

if (document.document_type() == DocumentType::text) {
Expand Down
8 changes: 4 additions & 4 deletions src/odr/internal/html/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Logger;

namespace odr::internal::html {

odr::HtmlService create_document_service(const Document &document,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);
HtmlService create_document_service(const Document &document,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);

} // namespace odr::internal::html
7 changes: 4 additions & 3 deletions src/odr/internal/html/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ class HtmlServiceImpl final : public HtmlService {

namespace odr::internal {

odr::HtmlService html::create_filesystem_service(
const Filesystem &filesystem, const std::string & /*cache_path*/,
HtmlConfig config, std::shared_ptr<Logger> logger) {
HtmlService html::create_filesystem_service(const Filesystem &filesystem,
const std::string & /*cache_path*/,
HtmlConfig config,
std::shared_ptr<Logger> logger) {
return odr::HtmlService(std::make_unique<HtmlServiceImpl>(
filesystem, std::move(config), std::move(logger)));
}
Expand Down
9 changes: 4 additions & 5 deletions src/odr/internal/html/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string>

namespace odr {
enum class FileType;
struct HtmlConfig;
class HtmlService;
class Filesystem;
Expand All @@ -13,9 +12,9 @@ class Logger;

namespace odr::internal::html {

odr::HtmlService create_filesystem_service(const Filesystem &filesystem,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);
HtmlService create_filesystem_service(const Filesystem &filesystem,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);

}
4 changes: 2 additions & 2 deletions src/odr/internal/html/html_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void write_element_options(std::ostream &out,

} // namespace

HtmlElementOptions &HtmlElementOptions::set_inline(const bool _inline_element) {
inline_element = _inline_element;
HtmlElementOptions &HtmlElementOptions::set_inline(const bool is_inline) {
inline_element = is_inline;
return *this;
}

Expand Down
12 changes: 6 additions & 6 deletions src/odr/internal/html/html_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ struct HtmlElementOptions {

std::optional<HtmlWritable> extra{};

HtmlElementOptions &set_inline(bool);
HtmlElementOptions &set_close_type(HtmlCloseType);
HtmlElementOptions &set_attributes(std::optional<HtmlAttributes>);
HtmlElementOptions &set_style(std::optional<HtmlWritable>);
HtmlElementOptions &set_class(std::optional<HtmlWritable>);
HtmlElementOptions &set_extra(std::optional<HtmlWritable>);
HtmlElementOptions &set_inline(bool is_inline);
HtmlElementOptions &set_close_type(HtmlCloseType _close_type);
HtmlElementOptions &set_attributes(std::optional<HtmlAttributes> _attributes);
HtmlElementOptions &set_style(std::optional<HtmlWritable> _style);
HtmlElementOptions &set_class(std::optional<HtmlWritable> _class);
HtmlElementOptions &set_extra(std::optional<HtmlWritable> _extra);
};

class HtmlWriter {
Expand Down
8 changes: 4 additions & 4 deletions src/odr/internal/html/image_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ void html::translate_image_src(const ImageFile &image_file, std::ostream &out,
}
}

odr::HtmlService html::create_image_service(const ImageFile &image_file,
const std::string & /*cache_path*/,
HtmlConfig config,
std::shared_ptr<Logger> logger) {
HtmlService html::create_image_service(const ImageFile &image_file,
const std::string & /*cache_path*/,
HtmlConfig config,
std::shared_ptr<Logger> logger) {
return odr::HtmlService(std::make_unique<HtmlServiceImpl>(
image_file, std::move(config), std::move(logger)));
}
Expand Down
8 changes: 4 additions & 4 deletions src/odr/internal/html/image_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void translate_image_src(const File &file, std::ostream &out,
void translate_image_src(const ImageFile &image_file, std::ostream &out,
const HtmlConfig &config);

odr::HtmlService create_image_service(const ImageFile &image_file,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);
HtmlService create_image_service(const ImageFile &image_file,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);

} // namespace odr::internal::html
8 changes: 4 additions & 4 deletions src/odr/internal/html/pdf_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ class HtmlServiceImpl final : public HtmlService {

namespace odr::internal {

odr::HtmlService html::create_pdf_service(const PdfFile &pdf_file,
const std::string & /*cache_path*/,
HtmlConfig config,
std::shared_ptr<Logger> logger) {
HtmlService html::create_pdf_service(const PdfFile &pdf_file,
const std::string & /*cache_path*/,
HtmlConfig config,
std::shared_ptr<Logger> logger) {
return odr::HtmlService(std::make_unique<HtmlServiceImpl>(
pdf_file, std::move(config), std::move(logger)));
}
Expand Down
7 changes: 3 additions & 4 deletions src/odr/internal/html/pdf_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class Logger;

namespace odr::internal::html {

odr::HtmlService create_pdf_service(const PdfFile &pdf_file,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);
HtmlService create_pdf_service(const PdfFile &pdf_file,
const std::string &cache_path, HtmlConfig config,
std::shared_ptr<Logger> logger);

}
99 changes: 73 additions & 26 deletions src/odr/internal/html/text_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <odr/file.hpp>
#include <odr/html.hpp>

#include <odr/internal/common/null_stream.hpp>
#include <odr/internal/common/path.hpp>
#include <odr/internal/html/common.hpp>
#include <odr/internal/html/html_service.hpp>
#include <odr/internal/html/html_writer.hpp>
Expand Down Expand Up @@ -66,52 +68,97 @@ class HtmlServiceImpl final : public HtmlService {
HtmlResources write_text(HtmlWriter &out) const {
HtmlResources resources;

const std::unique_ptr<std::istream> in = m_text_file.stream();

out.write_begin();

out.write_header_begin();

// TODO charset
out.write_header_charset("UTF-8");
out.write_header_target("_blank");
out.write_header_title("odr");
out.write_header_viewport(
"width=device-width,initial-scale=1.0,user-scalable=yes");
out.write_header_style_begin();
out.write_raw("*{font-family:monospace;}");
out.write_raw("td{padding-left:10px;padding-right:10px;}");
out.write_header_style_end();

auto css_file = File(
AbsPath(config().resource_path).join(RelPath("text.css")).string());
odr::HtmlResource document_css_resource =
HtmlResource::create(HtmlResourceType::css, "text/css", "text.css",
"text.css", css_file, true, false, true);
HtmlResourceLocation document_css_location =
config().resource_locator(document_css_resource, config());
resources.emplace_back(std::move(document_css_resource),
document_css_location);
if (document_css_location.has_value()) {
out.write_header_style(document_css_location.value());
} else {
out.write_header_style_begin();
util::stream::pipe(*css_file.stream(), out.out());
out.write_header_style_end();
}

out.write_header_end();

out.write_body_begin();
out.write_element_begin(
"table",
HtmlElementOptions().set_attributes(HtmlAttributesVector{
{"cellpadding", "0"}, {"border", "0"}, {"cellspacing", "0"}}));

for (std::uint32_t line = 1;; ++line) {
out.write_element_begin("tr");
out.write_element_begin("div", HtmlElementOptions().set_class("odr-text"));

out.write_element_begin("td",
HtmlElementOptions().set_inline(true).set_style(
"text-align:right;user-select:none;"));
out.write_element_begin("div",
HtmlElementOptions().set_class("odr-text-nr"));
std::unique_ptr<std::istream> in = m_text_file.stream();
for (std::uint32_t line = 1; !in->eof(); ++line) {
out.write_element_begin("div", HtmlElementOptions().set_inline(true));
out.out() << line;
out.write_element_end("td");
out.write_element_end("div");

out.write_element_begin("td");
NullStream ss_out;
util::stream::pipe_line(*in, ss_out, false);
}
out.write_element_end("div");

out.write_element_begin("div",
HtmlElementOptions().set_attributes(
[&](const HtmlAttributeWriterCallback &clb) {
clb("class", "odr-text-body odr-text-wrap");
if (config().editable) {
clb("contenteditable", "true");
}
}));
in = m_text_file.stream();
while (!in->eof()) {
out.write_element_begin("div", HtmlElementOptions().set_inline(true));

std::ostringstream ss_out;
util::stream::pipe_line(*in, ss_out, false);
out.out() << escape_text(ss_out.str());

out.write_element_end("td");
out.write_element_end("tr");

if (in->eof()) {
break;
if (const std::string &line = ss_out.str(); line.empty()) {
out.write_element_begin(
"br", HtmlElementOptions().set_close_type(HtmlCloseType::trailing));
} else {
out.out() << escape_text(ss_out.str());
}

out.write_element_end("div");
}
out.write_element_end("div");

out.write_element_end("div");

auto js_file =
File(AbsPath(config().resource_path).join(RelPath("text.js")).string());
odr::HtmlResource document_js_resource =
HtmlResource::create(HtmlResourceType::js, "text/javascript", "text.js",
"text.js", js_file, true, false, true);
HtmlResourceLocation document_js_location =
config().resource_locator(document_js_resource, config());
resources.emplace_back(std::move(document_js_resource),
document_js_location);
if (document_js_location.has_value()) {
out.write_script(document_js_location.value());
} else {
out.write_script_begin();
util::stream::pipe(*js_file.stream(), out.out());
out.write_script_end();
}

out.write_element_end("table");
out.write_body_end();

out.write_end();
Expand All @@ -130,7 +177,7 @@ class HtmlServiceImpl final : public HtmlService {

namespace odr::internal {

odr::HtmlService
HtmlService
html::create_text_service(const TextFile &text_file,
[[maybe_unused]] const std::string &cache_path,
HtmlConfig config, std::shared_ptr<Logger> logger) {
Expand Down
8 changes: 4 additions & 4 deletions src/odr/internal/html/text_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Logger;

namespace odr::internal::html {

odr::HtmlService create_text_service(const TextFile &text_file,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);
HtmlService create_text_service(const TextFile &text_file,
const std::string &cache_path,
HtmlConfig config,
std::shared_ptr<Logger> logger);

}
3 changes: 1 addition & 2 deletions src/odr/internal/html/wvware_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <odr/file.hpp>
#include <odr/html.hpp>

#include <odr/internal/common/null_stream.hpp>
#include <odr/internal/html/html_service.hpp>
#include <odr/internal/html/html_writer.hpp>
#include <odr/internal/html/image_file.hpp>
Expand Down Expand Up @@ -973,7 +972,7 @@ class HtmlServiceImpl final : public HtmlService {

namespace odr::internal {

odr::HtmlService html::create_wvware_oldms_service(
HtmlService html::create_wvware_oldms_service(
const WvWareLegacyMicrosoftFile &oldms_file, const std::string &cache_path,
HtmlConfig config, std::shared_ptr<Logger> logger) {
return odr::HtmlService(std::make_unique<HtmlServiceImpl>(
Expand Down
2 changes: 1 addition & 1 deletion src/odr/internal/html/wvware_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WvWareLegacyMicrosoftFile;

namespace odr::internal::html {

odr::HtmlService
HtmlService
create_wvware_oldms_service(const WvWareLegacyMicrosoftFile &oldms_file,
const std::string &cache_path, HtmlConfig config,
std::shared_ptr<Logger> logger);
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/compare_output_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ docker run -ti \
-v $(pwd):/repo \
-p 8000:8000 \
--platform linux/amd64 \
ghcr.io/opendocument-app/odr_core_test:1.0.18 \
ghcr.io/opendocument-app/odr_core_test:1.2.1 \
compare-html-server /repo/$REF /repo/$OBS --compare --driver $DRIVER --port 8000 -vv