MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / escape_backticks

Function escape_backticks

py/generate.py:99–119  ·  view source on GitHub ↗

Escape backticks in a docstring by doubling them up. This is a little tricky because RST requires a non-letter character after the closing backticks, but some CDPs docs have things like "`AxNodeId`s". If we double the backticks in that string, then it won't be valid RST. The fix is

(docstr)

Source from the content-addressed store, hash-verified

97
98
99def escape_backticks(docstr):
100 """Escape backticks in a docstring by doubling them up.
101
102 This is a little tricky because RST requires a non-letter character after
103 the closing backticks, but some CDPs docs have things like "`AxNodeId`s".
104 If we double the backticks in that string, then it won't be valid RST. The
105 fix is to insert an apostrophe if an "s" trails the backticks.
106 """
107
108 def replace_one(match):
109 if match.group(2) == "s":
110 return f"``{match.group(1)}``'s"
111 if match.group(2):
112 # This case (some trailer other than "s") doesn't currently exist
113 # in the CDP definitions, but it's here just to be safe.
114 return f"``{match.group(1)}`` {match.group(2)}"
115 return f"``{match.group(1)}``"
116
117 # Sometimes pipes are used where backticks should have been used.
118 docstr = docstr.replace("|", "`")
119 return BACKTICK_RE.sub(replace_one, docstr)
120
121
122def inline_doc(description):

Callers 2

inline_docFunction · 0.85
docstringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected