Skip to content

Commit 084347b

Browse files
kleinesfilmroellchenIdanHo
authored andcommitted
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.
1 parent 4ef1bed commit 084347b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Meta/check-markdown.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ if [ -z "${MARKDOWN_CHECK_BINARY:-}" ] ; then
1818
MARKDOWN_CHECK_BINARY="Build/lagom/markdown-check"
1919
fi
2020

21+
if [ -z "$SERENITY_SOURCE_DIR" ] ; then
22+
SERENITY_SOURCE_DIR=$(pwd -P)
23+
export SERENITY_SOURCE_DIR
24+
fi
25+
2126
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

Userland/Utilities/markdown-check.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <LibCore/File.h>
2424
#include <LibMarkdown/Document.h>
2525
#include <LibMarkdown/Visitor.h>
26+
#include <stdlib.h>
2627

2728
static bool is_missing_file_acceptable(String const& filename)
2829
{
@@ -76,14 +77,24 @@ class MarkdownLinkage final : Markdown::Visitor {
7677
Vector<FileLink> const& file_links() const { return m_file_links; }
7778

7879
private:
79-
MarkdownLinkage() = default;
80+
MarkdownLinkage()
81+
{
82+
auto const* source_directory = getenv("SERENITY_SOURCE_DIR");
83+
if (source_directory != nullptr) {
84+
m_serenity_source_directory = source_directory;
85+
} else {
86+
warnln("The environment variable SERENITY_SOURCE_DIR was not found. Link checking inside Serenity's filesystem will fail.");
87+
}
88+
}
8089

8190
virtual RecursionDecision visit(Markdown::Heading const&) override;
8291
virtual RecursionDecision visit(Markdown::Text::LinkNode const&) override;
8392

8493
HashTable<String> m_anchors;
8594
Vector<FileLink> m_file_links;
8695
bool m_has_invalid_link { false };
96+
97+
String m_serenity_source_directory;
8798
};
8899

89100
MarkdownLinkage MarkdownLinkage::analyze(Markdown::Document const& document)
@@ -190,10 +201,10 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
190201
return RecursionDecision::Recurse;
191202
}
192203
if (url.scheme() == "file") {
193-
// TODO: Resolve relative to $SERENITY_SOURCE_DIR/Base/, though we might refer to build-only files like binaries.
194-
204+
// TODO: Check more possible links other than icons.
195205
if (url.path().starts_with("/res/icons/")) {
196-
outln("Not checking icon link {}", href);
206+
auto file = String::formatted("{}/Base{}", m_serenity_source_directory, url.path());
207+
m_file_links.append({ file, String(), StringCollector::from(*link_node.text) });
197208
return RecursionDecision::Recurse;
198209
}
199210
outln("Not checking local link {}", href);

0 commit comments

Comments
 (0)