Fixed path separators in diagram link URL's in Windows
This commit is contained in:
@@ -200,7 +200,7 @@ inja::json generator<C, D>::element_context(const E &e) const
|
||||
std::filesystem::relative(file, ctx["git"]["toplevel"])
|
||||
.string();
|
||||
|
||||
ctx["element"]["source"]["path"] = relative_path;
|
||||
ctx["element"]["source"]["path"] = util::path_to_url(relative_path);
|
||||
ctx["element"]["source"]["full_path"] = file.string();
|
||||
ctx["element"]["source"]["name"] = file.filename().string();
|
||||
ctx["element"]["source"]["line"] = e.line();
|
||||
|
||||
@@ -303,4 +303,20 @@ std::size_t hash_seed(std::size_t seed)
|
||||
return kSeedStart + (seed << kSeedShiftFirst) + (seed >> kSeedShiftSecond);
|
||||
}
|
||||
|
||||
std::string path_to_url(const std::filesystem::path& p) {
|
||||
std::vector<std::string> path_tokens;
|
||||
auto it = p.begin();
|
||||
if(p.has_root_directory())
|
||||
it++;
|
||||
|
||||
for(; it != p.end(); it++)
|
||||
path_tokens.push_back(it->string());
|
||||
|
||||
if(p.has_root_directory())
|
||||
return fmt::format("/{}", fmt::join(path_tokens, "/"));
|
||||
else
|
||||
return fmt::format("{}", fmt::join(path_tokens, "/"));
|
||||
|
||||
}
|
||||
|
||||
} // namespace clanguml::util
|
||||
|
||||
@@ -248,4 +248,15 @@ void for_each_if(const T &collection, C &&cond, F &&func)
|
||||
|
||||
std::size_t hash_seed(std::size_t seed);
|
||||
|
||||
/**
|
||||
* @brief Convert filesystem path to url path
|
||||
*
|
||||
* The purpose of this function is to make sure that a path can
|
||||
* be used in a URL, e.g. it's separators are POSIX-style.
|
||||
*
|
||||
* @param p Path to convert
|
||||
* @return String representation of the path in URL format
|
||||
*/
|
||||
std::string path_to_url(const std::filesystem::path& p);
|
||||
|
||||
} // namespace clanguml::util
|
||||
Reference in New Issue
Block a user