Skip to content

Commit

Permalink
Rewrite footnotes for downstream documentation
Browse files Browse the repository at this point in the history
The modern version of footnotes is not supported in the downstream
tooling and we can't use the older version in our doc as it triggers
warnings.
Thus we rewrite the new format to the old format specifically for
downstream doc.

(cherry picked from commit 82f7b20)
  • Loading branch information
gsmet committed Apr 16, 2024
1 parent 96a2cad commit 9057428
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 9057428

Please sign in to comment.