Skip to content

Commit

Permalink
Merge pull request quarkusio#40082 from gsmet/footnote-downstream
Browse files Browse the repository at this point in the history
Rewrite footnotes for downstream documentation
  • Loading branch information
gsmet authored Apr 16, 2024
2 parents c922e41 + 82f7b20 commit 516b0b8
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class AssembleDownstreamDocumentation {
Pattern.CASE_INSENSITIVE + Pattern.MULTILINE);
private static final String SOURCE_BLOCK_PREFIX = "[source";
private static final String SOURCE_BLOCK_DELIMITER = "--";
private static final Pattern FOOTNOTE_PATTERN = Pattern.compile("footnote:([a-z0-9_-]+)\\[(\\])?");

private static final String PROJECT_NAME_ATTRIBUTE = "{project-name}";
private static final String RED_HAT_BUILD_OF_QUARKUS = "Red Hat build of Quarkus";
Expand Down Expand Up @@ -386,7 +387,7 @@ private static void copyAsciidoc(Path sourceFile, Path targetFile, Set<String> d

if (currentBuffer.length() > 0) {
rewrittenGuide.append(
rewriteLinks(sourceFile.getFileName().toString(), currentBuffer.toString(), downstreamGuides,
rewriteContent(sourceFile.getFileName().toString(), currentBuffer.toString(), downstreamGuides,
titlesByReference, linkRewritingErrors));
currentBuffer.setLength(0);
}
Expand All @@ -399,7 +400,7 @@ private static void copyAsciidoc(Path sourceFile, Path targetFile, Set<String> d

if (currentBuffer.length() > 0) {
rewrittenGuide.append(
rewriteLinks(sourceFile.getFileName().toString(), currentBuffer.toString(), downstreamGuides,
rewriteContent(sourceFile.getFileName().toString(), currentBuffer.toString(), downstreamGuides,
titlesByReference, linkRewritingErrors));
}

Expand All @@ -413,7 +414,7 @@ private static void copyAsciidoc(Path sourceFile, Path targetFile, Set<String> d
Files.writeString(targetFile, rewrittenGuideWithoutTabs.trim());
}

private static String rewriteLinks(String fileName,
private static String rewriteContent(String fileName,
String content,
Set<String> downstreamGuides,
Map<String, String> titlesByReference,
Expand Down Expand Up @@ -454,6 +455,14 @@ private static String rewriteLinks(String fileName,
return "[[" + mr.group(1) + "]]";
});

content = FOOTNOTE_PATTERN.matcher(content).replaceAll(mr -> {
if (mr.group(2) != null) {
return "footnoteref:[" + mr.group(1) + "]";
}

return "footnoteref:[" + mr.group(1) + ", ";
});

return content;
}

Expand Down

0 comments on commit 516b0b8

Please sign in to comment.