.NET library for Zen to HTML/XML conversion

32 views
Skip to first unread message

Pradeep Shanmugham

unread,
Aug 9, 2011, 9:28:22 PM8/9/11
to zen-c...@googlegroups.com
Hi All,

Nice to see the number of people who have gotten on board with creating plugins for IDEs for Zen Code.

I was wondering though if there was a class library that would have the ability to parse and convert Zen to HTML/XML and vice versa.
I am guessing the code is out there - which is why we have plugins!

Would be nice to have it in such a way that it could be a bit more extensible in its use.

I write server controls - hence I have to use code to generate markup.
I am trying to find out if I can write less code to generate the markup.

Before:
HtmlTextWriter writer = new HtmlTextWriter();
writer.Write(@"<div>");
writer.Write(@"<p>Some Text</p>");
writer.Write(@"</div>");


After:
HtmlTextWriter writer = new HtmlTextWriter();
writer.Write(Zen.toHtml(@"div>p{Some Text}"));

I was going to write my own but thought it might make sense to find out if there is one out there instead of re-inventing the wheel :)


Cheers

Pradeep

Sergey Chikuyonok

unread,
Aug 10, 2011, 5:08:50 AM8/10/11
to zen-c...@googlegroups.com
I don’t know about such library. But if you want to create it, you need to implement zen_parser:

It’s a standalone module which accepts string abbreviation and produces some kind of elements tree which represents actual structure of output data.
Note that repeating elements (e.g. li*4) are represented as a single element with 'count' attribute.

To implement proper result formatting, you can use 'format' filter:

___________________________________________
Сергей Чикуёнок
http://chikuyonok.ru
serg...@gmail.com

Pradeep Shanmugham

unread,
Aug 15, 2011, 11:51:00 PM8/15/11
to zen-c...@googlegroups.com
Hi Sergey,

Thanks for getting back to me.

I had a look at the link you sent me.
Since I was working with c#, the code did not translate exactly - which was fine.

I now have an implementation that is approached the same way - parses into a tree and then has a toHtml function that does the markup generation from that tree.

The only thing I did not implement was the $ operand.
The reason for this was I preferred to extend the library to have it bind with a collection of objects.
Assumption here is that the toString function of the underlying type would take care of any internal markup.

Ex:
public static class Zen
{
      public static string toHtml(string zenStatement, IEnumerable[] collections)
      {..}
}
public class program{
       public static void main()
       {
              ...
              List<Entity1> _list1 = new List<Entity1>();
              List<Entity2> _list2 = new List<Entity2>();
       
              IEnumerable [] collections = {_list1,_list2};
       
              //code to get your lists populated
              // _list1.Count = 4 and _list2.Count = 2
              ...
       
              Console.WriteLine(Zen.toHtml("div>p*4+(div>p*2)",collections);
       }
}

----

I am now focusing on testing and ensuring that this library works correctly and also test from a performance point of view.
Have you in course of development now generated a set of test expressions and expected output that I could perhaps have a look at?


Cheers

Pradeep

Sergey Chikuyonok

unread,
Aug 16, 2011, 3:33:04 AM8/16/11
to zen-c...@googlegroups.com
Yes, I have some unit test:

It tests more than just abbreviation parser so you may skip some of them, like "test tag hit"

___________________________________________
Сергей Чикуёнок
http://chikuyonok.ru
serg...@gmail.com
Reply all
Reply to author
Forward
0 new messages