Skip to content

Commit 5d6d2a7

Browse files
committed
Improve handling of certain html tags
1 parent c11db33 commit 5d6d2a7

File tree

2 files changed

+78
-4
lines changed

2 files changed

+78
-4
lines changed

UdonXML.cs

+29-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,21 @@ private object[] Parse(char[] input)
381381
}
382382
else
383383
{
384-
tagName += c + "";
384+
// i.e. bordered in <table>, or html in <doctype>, sometimes they don't have values
385+
if (c == ' ')
386+
{
387+
// Add tag
388+
if (tagName.Trim().Length != 0)
389+
{
390+
tagNames = AddLastToStringArray(tagNames, tagName.Trim());
391+
tagValues = AddLastToStringArray(tagValues, null);
392+
tagName = "";
393+
}
394+
}
395+
else
396+
{
397+
tagName += c + "";
398+
}
385399
}
386400
}
387401
else
@@ -444,7 +458,19 @@ private string Serialize(object[] data, string padding)
444458
var tagList = "";
445459
for (var i = 0; i != tagNames.Length; i++)
446460
{
447-
tagList += " " + tagNames[i] + "=\"" + tagValues[i] + "\"";
461+
var tagValue = (string) tagValues[i];
462+
Debug.Log(tagValue);
463+
Debug.Log((tagValue == null) + " " + (null == tagValue));
464+
Debug.Log("");
465+
if (null == tagValue)
466+
{
467+
// Tags without value, such as bordered in table, or html in doctype
468+
tagList += " " + tagNames[i];
469+
}
470+
else
471+
{
472+
tagList += " " + tagNames[i] + "=\"" + tagValues[i] + "\"";
473+
}
448474
}
449475

450476
if (nodeChildren.Length == 0)
@@ -455,7 +481,7 @@ private string Serialize(object[] data, string padding)
455481
{
456482
output += $"<{nodeName}{tagList}?>"; // ?xml has an extra ? at the end
457483
}
458-
else if (nodeName == "!DOCTYPE")
484+
else if (nodeName.ToUpper() == "!DOCTYPE")
459485
{
460486
output += $"<{nodeName}{tagList}>"; // doc types are self closing without the usual slash
461487
}

UdonXMLTest.cs

+49-1
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,57 @@ public class UdonXMLTest : UdonSharpBehaviour
595595
</w:body>
596596
</w:document>";
597597

598+
private string EXAMPLE_DATA_6 = @"<!doctype html >
599+
<html>
600+
<head>
601+
<title>Example Domain</title>
602+
603+
<meta charset=""utf-8"" />
604+
<meta http-equiv=""Content-type"" content=""text/html; charset=utf-8"" />
605+
<meta name=""viewport"" content=""width=device-width, initial-scale=1"" />
606+
<style type=""text/css"">
607+
body {
608+
background-color: #f0f0f2;
609+
margin: 0;
610+
padding: 0;
611+
font-family: -apple-system, system-ui, BlinkMacSystemFont, ""Segoe UI"", ""Open Sans"", ""Helvetica Neue"", Helvetica, Arial, sans-serif;
612+
613+
}
614+
div {
615+
width: 600px;
616+
margin: 5em auto;
617+
padding: 2em;
618+
background-color: #fdfdff;
619+
border-radius: 0.5em;
620+
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
621+
}
622+
a:link, a:visited {
623+
color: #38488f;
624+
text-decoration: none;
625+
}
626+
@media (max-width: 700px) {
627+
div {
628+
margin: 0 auto;
629+
width: auto;
630+
}
631+
}
632+
</style>
633+
</head>
634+
635+
<body>
636+
<div>
637+
<h1>Example Domain</h1>
638+
<p>This domain is for use in illustrative examples in documents. You may use this
639+
domain in literature without prior coordination or asking for permission.</p>
640+
<p><a href=""https://www.iana.org/domains/example"">More information...</a></p>
641+
</div>
642+
</body>
643+
</html>
644+
";
645+
598646
public void Start()
599647
{
600-
var root = udonXml.LoadXml(EXAMPLE_DATA_5);
648+
var root = udonXml.LoadXml(EXAMPLE_DATA_6);
601649

602650
if (root == null)
603651
{

0 commit comments

Comments
 (0)