What I got:
I got a textual representation which my program converts to a much more readable format, especcially for forums, websites and so on.
Why do I need such templage engine
As there are many different forums and blogs, the syntax of each one might be different. Instead of hard-coding the different syntax I would like to generate one class for each of those syntax (preferable extandable with easy modified xml-files) to format my output with the desired syntax.
What I did imagine
For example I need something like
class xyz {
private string start_bold = "[B]";
private string end_bold = "[/B]";
public string bold(string s) {
return start_bold + s + end_bold;
}
}
How can I do that the most elegant way? Feel free to edit this question as I'm not entirely sure it's a template engine I need. Just don't got a better word for it now.
Thanks for any help.
Some additional information: Andrew's answer was a great hint, but I don't understand how I could several different styles with this method. Currently I do it the hard way:
string s = String.Format("Output of [B]{0}[b] with number [i]{1}[/i]",
Data.Type,
Data.Number);
For this example, I want the output to be designed for a forum. In future I would like to do it like this:
Layout l = new Layout("html");
string s = String.Format("Output of {0} with number {1},
l.bold(Data.Type),
l.italic(Data.Number);
//desired output if style "html" is chosen: "Output of <b>Name</b> with number <i>5</i>" //desired output if style "phpbb" is chosen: "Output of [b]Name[/b] with number [i]5[/i]"
I just don't know how this can be done in the most elegant way.
About the XML: Only the styling conventions should be derived by a xml-document, i.e. adding custom styles without using code.