MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ParseDocumentation

Function ParseDocumentation

tensorflow/java/src/gen/cc/op_specs.cc:198–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198string ParseDocumentation(const string& inp) {
199 std::stringstream javadoc_text;
200
201 // TODO(karllessard) This is a very minimalist utility method for converting
202 // markdown syntax, as found in ops descriptions, to Javadoc/html tags. Check
203 // for alternatives to increase the level of support for markups.
204 std::vector<string> markups_subexpr;
205 markups_subexpr.push_back("\n+\\*\\s+"); // lists
206 markups_subexpr.push_back("\n{2,}"); // paragraphs
207 markups_subexpr.push_back("`{3,}\\s*[^\\s\n]*\\s*\n"); // code blocks
208 markups_subexpr.push_back("`+"); // inlined code and code blocks
209 markups_subexpr.push_back("\\*{1,2}\\b"); // text emphasis
210 markups_subexpr.push_back("\\["); // hyperlinks
211 const RE2 markup_expr("(" + absl::StrJoin(markups_subexpr, "|") + ")");
212
213 bool in_list = false;
214 string input = inp;
215 while (true) {
216 string text, markup;
217 if (!FindAndCut(&input, markup_expr, &text, &markup)) {
218 javadoc_text << input;
219 break; // end of loop
220 }
221 javadoc_text << text;
222 if (absl::StartsWith(markup, "\n")) {
223 javadoc_text << "\n";
224 if (absl::StrContains(markup, "*")) {
225 // new list item
226 javadoc_text << (in_list ? "</li>\n" : "<ul>\n") << "<li>\n";
227 in_list = true;
228 } else if (in_list) {
229 // end of list
230 javadoc_text << "</li>\n</ul>\n";
231 in_list = false;
232 } else if (!absl::StartsWith(input, "```")) {
233 // new paragraph (not required if a <pre> block follows)
234 javadoc_text << "<p>\n";
235 }
236 } else if (absl::StartsWith(markup, "```")) {
237 // code blocks
238 if (FindAndCut(&input, "(```\\s*\n*)", &text)) {
239 javadoc_text << "<pre>{@code\n" << text << "}</pre>\n";
240 } else {
241 javadoc_text << markup;
242 }
243 } else if (absl::StartsWith("(" + markup + ")", "`")) {
244 // inlined code
245 if (FindAndCut(&input, markup, &text)) {
246 javadoc_text << "{@code " << text << "}";
247 } else {
248 javadoc_text << markup;
249 }
250 } else if (markup == "**") {
251 // text emphasis (strong)
252 if (FindAndCut(&input, "(\\b\\*{2})", &text)) {
253 javadoc_text << "<b>" << ParseDocumentation(text) << "</b>";
254 } else {
255 javadoc_text << markup;

Callers 4

CreateInputFunction · 0.85
CreateAttributeFunction · 0.85
CreateOutputFunction · 0.85
CreateEndpointFunction · 0.85

Calls 5

FindAndCutFunction · 0.85
StartsWithFunction · 0.85
StrContainsFunction · 0.50
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected