mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
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.
This commit is contained in:
parent
4ef1bedc38
commit
084347becc
Notes:
sideshowbarker
2024-07-17 18:12:19 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/084347becc Pull-request: https://github.com/SerenityOS/serenity/pull/12759 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/TobyAsE ✅
2 changed files with 20 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <LibCore/File.h>
|
||||
#include <LibMarkdown/Document.h>
|
||||
#include <LibMarkdown/Visitor.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static bool is_missing_file_acceptable(String const& filename)
|
||||
{
|
||||
|
@ -76,7 +77,15 @@ public:
|
|||
Vector<FileLink> 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<String> m_anchors;
|
||||
Vector<FileLink> 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);
|
||||
|
|
Loading…
Reference in a new issue