Skip to content

Commit

Permalink
DYN-6569 Extended Characters Md2HTML Code Review
Browse files Browse the repository at this point in the history
I've added a unit test that validates that the extended characters are processed correctly by the Md2Html.exe tool.
Also I've modified some methods in the Md2Html.cs file to be static
  • Loading branch information
RobertGlobant20 committed Jul 9, 2024
1 parent 33430d9 commit 1d7cd8d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DynamoUtilities/Md2Html.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal string ParseMd2Html(string mdString, string mdPath)
return GetData(processCommunicationTimeoutms);
}

private void EncodeMDContent(ref string mdContent)
internal static void EncodeMDContent(ref string mdContent)
{
//Encode to base64 due that the Tools / Md2Html console app is using a different encoding and special characters are lost when sending info to Stdio

Expand All @@ -95,7 +95,7 @@ private void EncodeMDContent(ref string mdContent)
/// </summary>
/// <param name="mdContent">MD file content read usually from the fallback_docs folder</param>
/// <param name="regEx">Regular Expression that will be applied over the md content</param>
private void EncodeBase64(ref string mdContent, string regEx)
internal static void EncodeBase64(ref string mdContent, string regEx)
{
Regex rxExp = new Regex(regEx, RegexOptions.Singleline);
MatchCollection matches = rxExp.Matches(mdContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -994,6 +995,50 @@ public void CheckThatEmbeddedMdContentDoesNotSanitize(string resource)
}
}

[Test]
[TestCase("en-US")]
[TestCase("cs-CZ")]
[TestCase("ko-KR")]
public void CheckThatExtendedCharactersAreCorrectlyInHTML(string language)
{
string mdFile = "Autodesk.DesignScript.Geometry.Curve.SweepAsSurface.md";
string resource = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), language, "fallback_docs", mdFile);

Assert.True(File.Exists(resource), "The resource provided {0} doesn't exist in the path {1}", mdFile, resource);

// Arrange
var content = File.ReadAllText(resource, Encoding.UTF8);

using (var converter = new Md2Html())
{
// Act
var html = converter.ParseMd2Html(content, ExecutingDirectory);
var output = converter.SanitizeHtml(html);

// Assert
Assert.IsTrue(string.IsNullOrEmpty(output));

Regex rxExp = new Regex(@"#+\s[^\n]*\n(.*?)(?=\n##?\s|$)", RegexOptions.Singleline);

//Apply RegEx expression to the md file to getting the content without headers
MatchCollection matches = rxExp.Matches(content);
foreach (Match match in matches)
{
if (match.Groups.Count == 0) continue;

var UTF8Content = match.Groups[1].Value.Trim();

//Discard the image due that inside the html is converted to <img .......
if(!UTF8Content.StartsWith("!["))
{
// Assert
//Validates that the content of the md file is exactly the same that the one in the html file
Assert.That(html.Contains(UTF8Content), "Part of the MD file content was not found in the HTML File");
}
}
}
}

#region Helpers
private static string[] htmlResources()
{
Expand Down

0 comments on commit 1d7cd8d

Please sign in to comment.