From 11ef9fc9886fbaeb1b8b4b7bdec6f5a511e415d1 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Wed, 5 Aug 2015 14:23:54 +0300 Subject: [PATCH] PY-9795 Split line by colon considering possible Sphinx reference for the type --- .../documentation/GoogleCodeStyleDocString.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/documentation/GoogleCodeStyleDocString.java b/python/src/com/jetbrains/python/documentation/GoogleCodeStyleDocString.java index 0647ffd0d165..b98ee7d51a6a 100644 --- a/python/src/com/jetbrains/python/documentation/GoogleCodeStyleDocString.java +++ b/python/src/com/jetbrains/python/documentation/GoogleCodeStyleDocString.java @@ -30,6 +30,7 @@ import java.util.regex.Pattern; public class GoogleCodeStyleDocString extends SectionBasedDocString { private static final Pattern SECTION_HEADER_RE = Pattern.compile("^\\s*(.+?):\\s*$"); private static final Pattern FIELD_NAME_AND_TYPE_RE = Pattern.compile("\\s*(.+?)\\s*\\(\\s*(.+?)\\s*\\)\\s*"); + private static final Pattern SPHINX_REFERENCE_RE = Pattern.compile("(:\\w+:\\S+:`.+?`|:\\S+:`.+?`|`.+?`)"); public GoogleCodeStyleDocString(@NotNull String text) { super(text); @@ -62,7 +63,7 @@ public class GoogleCodeStyleDocString extends SectionBasedDocString { @NotNull private Pair parseField(int lineNum, int sectionIndent, boolean typeBeforeColon) { Substring name = null, type = null, description; - final List parts = getLine(lineNum).split(":", 1); + final List parts = splitFieldStartLineByColon(getLine(lineNum)); assert parts.size() <= 2; if (parts.size() < 2) { return Pair.create(null, lineNum); @@ -94,6 +95,19 @@ public class GoogleCodeStyleDocString extends SectionBasedDocString { return Pair.create(new SectionField(name, type, description), pair.getSecond()); } + /** + * Partitions line by colon if it contains type references, e.g. + * + *

+   *   runtime (:class:`Runtime`): Use it to access the environment.
+   * 
+ */ + @NotNull + private List splitFieldStartLineByColon(@NotNull Substring line) { + return line.split(":", 1); + } + + @NotNull @Override protected Pair parseSectionHeader(int lineNum) {