|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.IO;
|
4 | 4 | using System.Linq;
|
| 5 | +using System.Net; |
| 6 | +using System.Xml; |
5 | 7 | using System.Xml.Linq;
|
6 | 8 |
|
7 | 9 | using Irony.Ast;
|
@@ -111,20 +113,17 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
|
111 | 113 | }
|
112 | 114 | }
|
113 | 115 |
|
114 |
| - XNode astNodeElement = new XText (unparsedAElementValue); |
115 |
| - try { |
116 |
| - var seeElement = XElement.Parse ($"<see href={unparsedAElementValue}</see>"); |
117 |
| - var hrefValue = seeElement.Attribute ("href")?.Value ?? string.Empty; |
118 |
| - if (!string.IsNullOrEmpty (hrefValue) && |
| 116 | + var seeElement = TryParseHRef (unparsedAElementValue); |
| 117 | + if (seeElement == null) |
| 118 | + seeElement = TryParseHRef (WebUtility.HtmlDecode (unparsedAElementValue), logError: true); |
| 119 | + |
| 120 | + var hrefValue = seeElement?.Attribute ("href")?.Value ?? string.Empty; |
| 121 | + if (!string.IsNullOrEmpty (hrefValue) && |
119 | 122 | (hrefValue.StartsWith ("http", StringComparison.OrdinalIgnoreCase) || hrefValue.StartsWith ("www", StringComparison.OrdinalIgnoreCase))) {
|
120 |
| - parseNode.AstNode = seeElement; |
121 |
| - } else { |
122 |
| - // TODO: Need to convert relative paths or code references to appropriate CREF value. |
123 |
| - parseNode.AstNode = astNodeElement; |
124 |
| - } |
125 |
| - } catch (Exception) { |
126 |
| - Console.Error.WriteLine ($"# Unable to parse HTML element: <see href={unparsedAElementValue}</see>"); |
127 |
| - parseNode.AstNode = astNodeElement; |
| 123 | + parseNode.AstNode = seeElement; |
| 124 | + } else { |
| 125 | + // TODO: Need to convert relative paths or code references to appropriate CREF value. |
| 126 | + parseNode.AstNode = new XText (unparsedAElementValue); |
128 | 127 | }
|
129 | 128 | };
|
130 | 129 |
|
@@ -185,6 +184,17 @@ static IEnumerable<XElement> GetParagraphs (ParseTreeNodeList children)
|
185 | 184 | }
|
186 | 185 | }
|
187 | 186 |
|
| 187 | + static XElement? TryParseHRef (string unparsedAElementValue, bool logError = false) |
| 188 | + { |
| 189 | + try { |
| 190 | + return XElement.Parse ($"<see href={unparsedAElementValue}</see>"); |
| 191 | + } catch (Exception x) { |
| 192 | + if (logError) |
| 193 | + Console.Error.WriteLine ($"## Unable to parse HTML element: <see href={unparsedAElementValue}</see>\n{x.GetType ()}: {x.Message}"); |
| 194 | + return null; |
| 195 | + } |
| 196 | + } |
| 197 | + |
188 | 198 | public readonly NonTerminal AllHtmlTerms = new NonTerminal (nameof (AllHtmlTerms), ConcatChildNodes);
|
189 | 199 |
|
190 | 200 | public readonly NonTerminal TopLevelInlineDeclaration = new NonTerminal (nameof (TopLevelInlineDeclaration), ConcatChildNodes);
|
@@ -387,7 +397,7 @@ public override void Init (GrammarData grammarData)
|
387 | 397 | source.PreviewPosition += 1;
|
388 | 398 | int start = source.Location.Position;
|
389 | 399 | int stop = start;
|
390 |
| - while (source.Text [stop] != '>' && stop < source.Text.Length) |
| 400 | + while (stop < source.Text.Length && source.Text [stop] != '>' ) |
391 | 401 | stop++;
|
392 | 402 | if (addingRemarks) {
|
393 | 403 | Console.Error.WriteLine ($"# Unsupported HTML element: {source.Text.Substring (start, stop - start)}");
|
|
0 commit comments