|
23 | 23 | #include <LibCore/File.h>
|
24 | 24 | #include <LibMarkdown/Document.h>
|
25 | 25 | #include <LibMarkdown/Visitor.h>
|
| 26 | +#include <stdlib.h> |
26 | 27 |
|
27 | 28 | static bool is_missing_file_acceptable(String const& filename)
|
28 | 29 | {
|
@@ -76,14 +77,24 @@ class MarkdownLinkage final : Markdown::Visitor {
|
76 | 77 | Vector<FileLink> const& file_links() const { return m_file_links; }
|
77 | 78 |
|
78 | 79 | 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 | + } |
80 | 89 |
|
81 | 90 | virtual RecursionDecision visit(Markdown::Heading const&) override;
|
82 | 91 | virtual RecursionDecision visit(Markdown::Text::LinkNode const&) override;
|
83 | 92 |
|
84 | 93 | HashTable<String> m_anchors;
|
85 | 94 | Vector<FileLink> m_file_links;
|
86 | 95 | bool m_has_invalid_link { false };
|
| 96 | + |
| 97 | + String m_serenity_source_directory; |
87 | 98 | };
|
88 | 99 |
|
89 | 100 | MarkdownLinkage MarkdownLinkage::analyze(Markdown::Document const& document)
|
@@ -190,10 +201,10 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
|
190 | 201 | return RecursionDecision::Recurse;
|
191 | 202 | }
|
192 | 203 | 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. |
195 | 205 | 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) }); |
197 | 208 | return RecursionDecision::Recurse;
|
198 | 209 | }
|
199 | 210 | outln("Not checking local link {}", href);
|
|
0 commit comments