elharo commented on code in PR #1737: URL: https://github.com/apache/maven-site/pull/1737#discussion_r4383602317
########## src/test/java/org/apache/maven/site/MarkdownDocsTest.java: ########## @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.site; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import com.vladsch.flexmark.ext.wikilink.WikiLink; +import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension; +import com.vladsch.flexmark.parser.Parser; +import com.vladsch.flexmark.util.ast.Node; +import com.vladsch.flexmark.util.ast.NodeVisitor; +import com.vladsch.flexmark.util.ast.VisitHandler; +import com.vladsch.flexmark.util.data.MutableDataSet; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class MarkdownDocsTest { + private static final Pattern PARENTHESIZED_DESTINATION = Pattern.compile("^\\([^)\\s]+\\)"); + + private static final Parser MARKDOWN_PARSER = Parser.builder( + new MutableDataSet().set(Parser.EXTENSIONS, List.of(WikiLinkExtension.create()))) + .build(); + + @Test + void markdownDocsHaveWellFormedLinks() throws IOException { + Path contentDirectory = Paths.get("content/markdown"); + List<String> violations = new ArrayList<>(); + + try (Stream<Path> files = Files.walk(contentDirectory)) { + List<Path> markdownFiles = + files.filter(MarkdownDocsTest::isMarkdownSource).sorted().toList(); + for (Path file : markdownFiles) { + collectViolations(contentDirectory, file, violations); + } + } + + assertTrue( + violations.isEmpty(), + () -> "Markdown link labels must escape square brackets. " + + "Otherwise the generated link target is the label instead of the URL. " + + "For example: [\\[MNG-1\\]](https://issues.apache.org/jira/browse/MNG-1).\n" Review Comment: This is too much. The first sentence is all you need. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
