|
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,21 @@ 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) && |
119 |
| - (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; |
| 116 | + var seeElement = TryParseHRef (unparsedAElementValue, out Exception? ex); |
| 117 | + if (seeElement == null) { |
| 118 | + seeElement = TryParseHRef (WebUtility.HtmlDecode (unparsedAElementValue), out Exception? ex2); |
| 119 | + if (ex2 == null) |
| 120 | + Console.Error.WriteLine ($"# Unable to parse HTML element: <see href={unparsedAElementValue}</see>\n{ex?.GetType()}: {ex?.Message}"); |
| 121 | + else |
| 122 | + Console.Error.WriteLine ($"# Unable to parse decoded HTML element: <see href={unparsedAElementValue}</see>\n{ex2.GetType()}: {ex2.Message}"); |
| 123 | + } |
| 124 | + var hrefValue = seeElement?.Attribute ("href")?.Value ?? string.Empty; |
| 125 | + if (!string.IsNullOrEmpty (hrefValue) && |
| 126 | + (hrefValue.StartsWith ("http", StringComparison.OrdinalIgnoreCase) || hrefValue.StartsWith ("www", StringComparison.OrdinalIgnoreCase))) { |
| 127 | + parseNode.AstNode = seeElement; |
| 128 | + } else { |
| 129 | + // TODO: Need to convert relative paths or code references to appropriate CREF value. |
| 130 | + parseNode.AstNode = new XText (unparsedAElementValue); |
128 | 131 | }
|
129 | 132 | };
|
130 | 133 |
|
@@ -185,6 +188,18 @@ static IEnumerable<XElement> GetParagraphs (ParseTreeNodeList children)
|
185 | 188 | }
|
186 | 189 | }
|
187 | 190 |
|
| 191 | + static XElement? TryParseHRef (string unparsedAElementValue, out Exception? exception) |
| 192 | + { |
| 193 | + try { |
| 194 | + XElement result = XElement.Parse ($"<see href={unparsedAElementValue}</see>"); |
| 195 | + exception = null; |
| 196 | + return result; |
| 197 | + } catch (Exception x) { |
| 198 | + exception = x; |
| 199 | + return null; |
| 200 | + } |
| 201 | + } |
| 202 | + |
188 | 203 | public readonly NonTerminal AllHtmlTerms = new NonTerminal (nameof (AllHtmlTerms), ConcatChildNodes);
|
189 | 204 |
|
190 | 205 | public readonly NonTerminal TopLevelInlineDeclaration = new NonTerminal (nameof (TopLevelInlineDeclaration), ConcatChildNodes);
|
@@ -387,7 +402,7 @@ public override void Init (GrammarData grammarData)
|
387 | 402 | source.PreviewPosition += 1;
|
388 | 403 | int start = source.Location.Position;
|
389 | 404 | int stop = start;
|
390 |
| - while (source.Text [stop] != '>' && stop < source.Text.Length) |
| 405 | + while (stop < source.Text.Length && source.Text [stop] != '>' ) |
391 | 406 | stop++;
|
392 | 407 | if (addingRemarks) {
|
393 | 408 | Console.Error.WriteLine ($"# Unsupported HTML element: {source.Text.Substring (start, stop - start)}");
|
|
0 commit comments