Skip to content

Commit

Permalink
Merge pull request #25 from mauricedb/master
Browse files Browse the repository at this point in the history
Added support for additional implicit tag names
  • Loading branch information
madskristensen committed Dec 20, 2013
2 parents 0e93588 + 2df51a4 commit cb1b4d5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
52 changes: 51 additions & 1 deletion ZenCoding.Test/Html/ImplicitTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,56 @@ public void SortedListsAndListItemsComplex()
"</div>";

Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
}
}

[TestMethod]
public void EmphasizedAndSpan()
{
string result = _parser.Parse("em>.class-name", ZenType.HTML);
string expected = "<em>" +
"<span class=\"class-name\">" +
"</span>" +
"</em>";

Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
}

[TestMethod]
public void TableAndRow()
{
string result = _parser.Parse("table>.class-name", ZenType.HTML);
string expected = "<table>" +
"<tr class=\"class-name\">" +
"</tr>" +
"</table>";

Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
}

[TestMethod]
public void RowAndData()
{
string result = _parser.Parse("tr>.class-name", ZenType.HTML);
string expected = "<tr>" +
"<td class=\"class-name\">" +
"</td>" +
"</tr>";

Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
}

[TestMethod]
public void TableAndRowAndData()
{
string result = _parser.Parse("table>.row-class-name>.data-class-name", ZenType.HTML);
string expected = "<table>" +
"<tr class=\"row-class-name\">" +
"<td class=\"data-class-name\">" +
"</td>" +
"</tr>" +
"</table>";

Assert.AreEqual(expected, result.Replace(Environment.NewLine, string.Empty));
}
}
}
6 changes: 6 additions & 0 deletions ZenCoding/Html/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ private static void AdjustImplicitTagNames(List<string> parts)
{
if (i != 0 && (parts[i - 1] == "ol" || parts[i - 1] == "ul") && parts[i][0] == '>')
currentDefault = "li";
else if (i != 0 && parts[i - 1] == "em" && parts[i][0] == '>')
currentDefault = "span";
else if (i != 0 && parts[i - 1] == "table" && parts[i][0] == '>')
currentDefault = "tr";
else if (i != 0 && (parts[i - 1] == "tr" || parts[i - 1].StartsWith(">tr")) && parts[i][0] == '>')
currentDefault = "td";
else if (currentDefault != "div" && parts[i][0] == '^')
currentDefault = "div";

Expand Down

0 comments on commit cb1b4d5

Please sign in to comment.