JSON to describe HTML tags
I have a need to express HTML tags in a user friendly format, and then render them as actual HTML on a Web Page.
For example, imagine that a user would like this link to show up on the page:
<a href="http://stackoverflow.com">Stack Overflow</a&开发者_如何学Cgt;
My average user is not familiar with HTML, so I was thinking about letting him/her use JSON instead. Something like this:
{Link:{Title:"Stack Overflow",URL:"http://stackoverflow.com"}}
I would then use a JSON parser to render the actual HTML on the page. The same method would apply to other HTML tags (images, buttons, etc.).
Has this already been done? Are there any conventions on how to express HTML tags in JSON?
Thanks!
ExtJS's DOMHelper class provides a syntax like this:
{
id: 'my-ul',
tag: 'ul',
cls: 'my-list',
children: [
{tag: 'li', id: 'item0', html: 'List Item 0'},
{tag: 'li', id: 'item1', html: 'List Item 1'},
{tag: 'li', id: 'item2', html: 'List Item 2'}
]
}
So it seems that there is a category of languages called "lightweight markup languages" that just do that. Thanks @zerocrates for the pointers. I found more details here (including for each the implementation language or platform): http://en.wikipedia.org/wiki/Lightweight_markup_language
Also, good to know that ExtJS has a syntax for that (thanks @Pumbb80). It just won't work in my case because I am targeting end users.
精彩评论