Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Fix datastore grpc doc class generation for python and ruby #716

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/com/google/api/codegen/CommentPatterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class CommentPatterns {
Pattern.compile("\\[([^\\]]+)\\]\\((\\p{Alpha}+:[^\\)]+)\\)");
public static final Pattern CLOUD_LINK_PATTERN =
Pattern.compile("\\[([^\\]]+)\\]\\(((?!\\p{Alpha}+:)[^\\)]+)\\)");
public static final Pattern PROTO_LINK_PATTERN = Pattern.compile("\\[([^\\]]+)\\]\\[[^\\]]*\\]");
public static final Pattern PROTO_LINK_PATTERN =
Pattern.compile("\\[([^\\]]+)\\]\\[([A-Za-z_][A-Za-z_.0-9]*)*\\]");

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

public static final Pattern HEADLINE_PATTERN = Pattern.compile("^#+", Pattern.MULTILINE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ private static String jsdocifyCloudMarkdownLinks(String comment) {
}
do {
String url = "https://cloud.google.com" + m.group(2);
m.appendReplacement(sb, String.format("[%s](%s)", m.group(1), url));
// cloud markdown links may contain '$' which needs to be escaped using Matcher.quoteReplacement
m.appendReplacement(sb, Matcher.quoteReplacement(String.format("[%s](%s)", m.group(1), url)));
} while (m.find());
m.appendTail(sb);
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ private static String sphinxifyAbsoluteMarkdownLinks(String comment) {
return comment;
}
do {
m.appendReplacement(sb, String.format("`%s <%s>`_", m.group(1), m.group(2)));
// absolute markdown links may contain '$' which needs to be escaped using Matcher.quoteReplacement
m.appendReplacement(
sb, Matcher.quoteReplacement(String.format("`%s <%s>`_", m.group(1), m.group(2))));
} while (m.find());
m.appendTail(sb);
return sb.toString();
Expand All @@ -65,8 +67,11 @@ private static String sphinxifyCloudMarkdownLinks(String comment) {
return comment;
}
do {
// cloud markdown links may contain '$' which needs to be escaped using Matcher.quoteReplacement
m.appendReplacement(
sb, String.format("`%s <https://cloud.google.com%s>`_", m.group(1), m.group(2)));
sb,
Matcher.quoteReplacement(
String.format("`%s <https://cloud.google.com%s>`_", m.group(1), m.group(2))));
} while (m.find());
m.appendTail(sb);
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/** Utility class for formatting source comments to follow RDoc style. */
public class RDocCommentFixer {

/** Returns a Sphinx-formatted comment string. */
/** Returns a RDoc-formatted comment string. */
public static String rdocify(String comment) {
comment = CommentPatterns.BACK_QUOTE_PATTERN.matcher(comment).replaceAll("+");
comment = rdocifyProtoMarkdownLinks(comment);
Expand Down Expand Up @@ -67,7 +67,7 @@ private static String rdocifyProtoMarkdownLinks(String comment) {
return sb.toString();
}

/** Returns a string with all cloud markdown links formatted to Sphinx style. */
/** Returns a string with all cloud markdown links formatted to RDoc style. */
private static String rdocifyCloudMarkdownLinks(String comment) {
StringBuffer sb = new StringBuffer();
Matcher m = CommentPatterns.CLOUD_LINK_PATTERN.matcher(comment);
Expand All @@ -76,21 +76,24 @@ private static String rdocifyCloudMarkdownLinks(String comment) {
}
do {
String url = "https://cloud.google.com" + m.group(2);
m.appendReplacement(sb, String.format("{%s}[%s]", m.group(1), url));
// cloud markdown links may contain '$' which needs to be escaped using Matcher.quoteReplacement
m.appendReplacement(sb, Matcher.quoteReplacement(String.format("{%s}[%s]", m.group(1), url)));
} while (m.find());
m.appendTail(sb);
return sb.toString();
}

/** Returns a string with all cloud markdown links formatted to Sphinx style. */
/** Returns a string with all absolute markdown links formatted to RDoc style. */
private static String rdocifyAbsoluteMarkdownLinks(String comment) {
StringBuffer sb = new StringBuffer();
Matcher m = CommentPatterns.ABSOLUTE_LINK_PATTERN.matcher(comment);
if (!m.find()) {
return comment;
}
do {
m.appendReplacement(sb, String.format("{%s}[%s]", m.group(1), m.group(2)));
// absolute markdown links may contain '$' which needs to be escaped using Matcher.quoteReplacement
m.appendReplacement(
sb, Matcher.quoteReplacement(String.format("{%s}[%s]", m.group(1), m.group(2))));
} while (m.find());
m.appendTail(sb);
return sb.toString();
Expand Down