/// <summary> /// Process a paragraph /// </summary> /// <param name="paragraphNode"></param> /// <param name="prevNode"></param> /// <param name="nextNode"></param> private void ProcessParagraph(XmlNode paragraphNode, XmlNode prevNode, XmlNode nextNode, bool inTable, bool drawNewLine) { // list settings of the current paragraph int? currentNumId = GetInt(paragraphNode, "./w:pPr/w:numPr/w:numId/@w:val"); int? currentLevel = GetInt(paragraphNode, "./w:pPr/w:numPr/w:ilvl/@w:val"); bool isList = currentNumId.HasValue && currentLevel.HasValue; ListTypeEnum currentType = _numberingFn.GetNumberingStyle(currentNumId, currentLevel); int? prevNumId = null; int? prevLevel = null; ListTypeEnum prevType = ListTypeEnum.None; int? nextNumId = null; int? nextLevel = null; ListTypeEnum nextType = ListTypeEnum.None; // process list data if we are in a list if (isList) { // list settings of the previous paragraph prevNumId = GetInt(prevNode, "./w:pPr/w:numPr/w:numId/@w:val"); prevLevel = GetInt(prevNode, "./w:pPr/w:numPr/w:ilvl/@w:val"); prevType = _numberingFn.GetNumberingStyle(prevNumId, prevLevel); // list settings of the next paragraph nextNumId = GetInt(nextNode, "./w:pPr/w:numPr/w:numId/@w:val"); nextLevel = GetInt(nextNode, "./w:pPr/w:numPr/w:ilvl/@w:val"); nextType = _numberingFn.GetNumberingStyle(nextNumId, nextLevel); } // if it is a list if (isList) { ListControl listBegin = _numberingFn.ProcessBeforeListItem(currentNumId.Value, currentLevel.Value, currentType, prevNumId, prevLevel, nextNumId, nextLevel); // some numbered if (listBegin.ListType == ListTypeEnum.Numbered) { switch (listBegin.NumberedCounterType) { // simple numbered begins case NumberedCounterTypeEnum.None: _tex.AddStartTag(TagEnum.Enumerate); _tex.AddNL(); break; // a new numbered begins case NumberedCounterTypeEnum.NewCounter: if (Config.Instance.LaTeXTags.AllowContinuousLists.Value) { _tex.AddTextNL(@"\newcounter{numberedCnt" + listBegin.Numbering + "}"); } _tex.AddStartTag(TagEnum.Enumerate); _tex.AddNL(); break; // a numbered loaded case NumberedCounterTypeEnum.LoadCounter: _tex.AddStartTag(TagEnum.Enumerate); _tex.AddNL(); if (Config.Instance.LaTeXTags.AllowContinuousLists.Value) { _tex.AddTextNL(@"\setcounter{enumi}{\thenumberedCnt" + listBegin.Numbering + "}"); } break; } } else if (listBegin.ListType == ListTypeEnum.Bulleted) { // bulleted list begins _tex.AddStartTag(TagEnum.Itemize); _tex.AddNL(); } //list item _tex.AddText(@"\item "); } // this will process the real content of the paragraph ProcessParagraphContent(paragraphNode, prevNode, nextNode, drawNewLine & true, inTable | false, isList); // in case of list if (isList) { List <ListControl> listEnd = _numberingFn.ProcessAfterListItem(currentNumId.Value, currentLevel.Value, currentType, prevNumId, prevLevel, nextNumId, nextLevel); // rollback the ended lists foreach (var token in listEnd) { // if a numbered list found if (token.ListType == ListTypeEnum.Numbered) { // save counter of next use if (token.NumberedCounterType == NumberedCounterTypeEnum.SaveCounter) { if (Config.Instance.LaTeXTags.AllowContinuousLists.Value) { _tex.AddTextNL("\\setcounter{numberedCnt" + token.Numbering + "}{\\theenumi}"); } } _tex.AddEndTag(TagEnum.Enumerate); _tex.AddNL(); } else if (token.ListType == ListTypeEnum.Bulleted) { // bulleted ended _tex.AddEndTag(TagEnum.Itemize); _tex.AddNL(); } } } }
public List <ListControl> ProcessAfterListItem(int currentNumId, int currentLevel, ListTypeEnum currentType, int?previousNumId, int?previousLevel, int?nextNumId, int?nextLevel) { //if this is the last list element if (!nextNumId.HasValue || !nextLevel.HasValue) { ListControl suffix = new ListControl(ListTypeEnum.None, NumberedCounterTypeEnum.None, null); if (_listStyle.Count > 0) { ListInfo listInfo = _listStyle[0]; if (listInfo.Style == ListTypeEnum.Numbered && listInfo.Level == 0) { if (_visitedFirstLevelNumberings.ContainsKey(listInfo.HashCode)) { suffix.NumberedCounterType = NumberedCounterTypeEnum.SaveCounter; suffix.Numbering = UniqueString(listInfo.NumId); } } } List <ListControl> ends = GetReverseListTilIndex(0); if (ends.Count > 0) { var first = ends[0]; first.NumberedCounterType = suffix.NumberedCounterType; first.Numbering = suffix.Numbering; ends.RemoveAt(0); ends.Insert(0, first); } _listStyle.Clear(); return(ends); } else //a list { // the same list continues if (currentNumId == nextNumId.Value && currentLevel == nextLevel.Value) { //nothing to do } else // other list encountered { int indexOfNext = FindListElement(nextNumId.Value, nextLevel.Value); //if the next list element cannot find, then a unknown new list will start if (indexOfNext == -1) { //nothing to do } else // else end of list { //remove listStyles and sign ends List <ListControl> ends = GetReverseListTilIndex(indexOfNext + 1); _listStyle.RemoveRange(indexOfNext + 1, _listStyle.Count - indexOfNext - 1); return(ends); } } } return(new List <ListControl>()); }