private static string closeOpenStyle(Word.WdListType listType, bool isOpening) { if (listType == Word.WdListType.wdListBullet) { if (isOpening) { return("<ul>\n"); } else { return("</ul>\n"); } } else { if (isOpening) { return("<ol>\n"); } else { return("</ol>\n"); } } }
private static List <string> createList(List <Tuple <string, Word.WdListType, int> > items) { int currentIndex = 1; List <string> listStrings = new List <string>(); StringBuilder str = new StringBuilder(); Word.WdListType currentType = items[0].Item2; str.Append(closeOpenStyle(items[0].Item2, true)); foreach (Tuple <string, Word.WdListType, int> item in items) { //check if the list type has changed. Append the close tag and the open tag if (currentType != item.Item2) { str.Append(closeOpenStyle(currentType, false)); listStrings.Add(str.ToString()); str.Clear(); str.Append(closeOpenStyle(item.Item2, true)); currentType = item.Item2; } //check the level if (item.Item3 > currentIndex) { str.Append(closeOpenStyle(currentType, true)); currentIndex = item.Item3; } else if (item.Item3 < currentIndex) { str.Append(closeOpenStyle(currentType, false)); currentIndex = item.Item3; } //append the list item str.Append("<li>" + item.Item1.Replace("\r", "") + "</li>\n"); } str.Append(closeOpenStyle(currentType, false)); listStrings.Add(str.ToString()); return(listStrings); }