From 084347becc9292bae3a38c21b897487a1cc48d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sat, 26 Feb 2022 16:51:24 +0100 Subject: [PATCH] Utilities+Meta: Check icons in markdown-check We use the environment variable SERENITY_SOURCE_DIR to resolve and check icon links. This is a bit inconvenient as SERENITY_SOURCE_DIR needs to be set correctly before invoking the markdown checker, but as we use it through the check-markdown script anyways, I think it's not a problem. --- Meta/check-markdown.sh | 5 +++++ Userland/Utilities/markdown-check.cpp | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Meta/check-markdown.sh b/Meta/check-markdown.sh index 0eeba1b7452..cbbafbb1da3 100755 --- a/Meta/check-markdown.sh +++ b/Meta/check-markdown.sh @@ -18,4 +18,9 @@ if [ -z "${MARKDOWN_CHECK_BINARY:-}" ] ; then MARKDOWN_CHECK_BINARY="Build/lagom/markdown-check" fi +if [ -z "$SERENITY_SOURCE_DIR" ] ; then + SERENITY_SOURCE_DIR=$(pwd -P) + export SERENITY_SOURCE_DIR +fi + find AK Base Documentation Kernel Meta Ports Tests Userland -path 'Ports/*/*' -prune -o -type f -name '*.md' -print0 | xargs -0 "${MARKDOWN_CHECK_BINARY}" README.md diff --git a/Userland/Utilities/markdown-check.cpp b/Userland/Utilities/markdown-check.cpp index 6a4fb589683..e9ec81b1e79 100644 --- a/Userland/Utilities/markdown-check.cpp +++ b/Userland/Utilities/markdown-check.cpp @@ -23,6 +23,7 @@ #include #include #include +#include static bool is_missing_file_acceptable(String const& filename) { @@ -76,7 +77,15 @@ public: Vector const& file_links() const { return m_file_links; } private: - MarkdownLinkage() = default; + MarkdownLinkage() + { + auto const* source_directory = getenv("SERENITY_SOURCE_DIR"); + if (source_directory != nullptr) { + m_serenity_source_directory = source_directory; + } else { + warnln("The environment variable SERENITY_SOURCE_DIR was not found. Link checking inside Serenity's filesystem will fail."); + } + } virtual RecursionDecision visit(Markdown::Heading const&) override; virtual RecursionDecision visit(Markdown::Text::LinkNode const&) override; @@ -84,6 +93,8 @@ private: HashTable m_anchors; Vector m_file_links; bool m_has_invalid_link { false }; + + String m_serenity_source_directory; }; MarkdownLinkage MarkdownLinkage::analyze(Markdown::Document const& document) @@ -190,10 +201,10 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no return RecursionDecision::Recurse; } if (url.scheme() == "file") { - // TODO: Resolve relative to $SERENITY_SOURCE_DIR/Base/, though we might refer to build-only files like binaries. - + // TODO: Check more possible links other than icons. if (url.path().starts_with("/res/icons/")) { - outln("Not checking icon link {}", href); + auto file = String::formatted("{}/Base{}", m_serenity_source_directory, url.path()); + m_file_links.append({ file, String(), StringCollector::from(*link_node.text) }); return RecursionDecision::Recurse; } outln("Not checking local link {}", href);