Skip to content

Commit 64bcf45

Browse files
muhammad-othmanphilasmar
authored andcommitted
Update CleanupDocumentation to replace tags that might contain additional attributes
1 parent 1733c38 commit 64bcf45

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

generator/ServiceClientGeneratorLib/Generators/BaseGenerator.tt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<#@ import namespace="System.Text" #>
66
<#@ import namespace="System.Collections.Generic" #>
77
<#@ import namespace="ServiceClientGenerator.DefaultConfiguration" #>
8-
8+
<#@ import namespace="System.Text.RegularExpressions" #>
99

1010
<#+
1111
// An object that contains all the information about a service
@@ -314,6 +314,15 @@
314314
}
315315
}
316316

317+
// Even though these tags will be replaced, there might be occurrences with extra attributes (for example, "<p class='title'>") in the service documentation.
318+
// We'll replace them as well by using a regular expression:
319+
// - "[^>]" matches any character other than ">" (so it captures additional attributes in the HTML definition)
320+
// - "*" matches the previous token 0 or more times (in case there are multiple additional attributes)
321+
// As a result, "[^>]*" will return any extra characters included between the start and end of the element ("<p" and ">") and remove them.
322+
323+
static Regex pTagRegex = new Regex("<p [^>]*>", RegexOptions.Compiled);
324+
static Regex tagsRegex = new Regex(String.Join("|", "<fullname [^>]*>", "<function [^>]*>", "<br [^>]*>"), RegexOptions.Compiled);
325+
317326
// Removes unneccesary tags from the documentation and formats paragraph tags correctly
318327
public string CleanupDocumentation(string documentation)
319328
{
@@ -330,7 +339,9 @@
330339
.Replace("<p/>","")
331340
.Trim();
332341

333-
342+
documentation = pTagRegex.Replace(documentation, "\n<para>\n");
343+
documentation = tagsRegex.Replace(documentation, "");
344+
334345
// Remove examples because these will be wire protocol examples
335346
documentation = RemoveSnippets(documentation, "<examples>", "</examples>");
336347

0 commit comments

Comments
 (0)