Ejemplo n.º 1
0
        public Delta ToDelta(string projectId, XElement usxElem)
        {
            var    newDelta   = new Delta();
            int    nextNoteId = 0;
            var    nextIds    = new Dictionary <string, int>();
            string curRef     = null;
            string curChapter = null;
            string bookId     = null;

            foreach (XElement elem in usxElem.Elements())
            {
                switch (elem.Name.LocalName)
                {
                case "book":
                    bookId = (string)elem.Attribute("code");
                    break;

                case "para":
                    var  style     = (string)elem.Attribute("style");
                    bool paraStyle = IsParagraphStyle(style);
                    if (paraStyle)
                    {
                        if (curRef != null)
                        {
                            int slashIndex = curRef.IndexOf("/", StringComparison.Ordinal);
                            if (slashIndex != -1)
                            {
                                curRef = curRef.Substring(0, slashIndex);
                            }
                            curRef = GetParagraphRef(nextIds, curRef + "/" + style);
                        }
                    }
                    else
                    {
                        curRef = GetParagraphRef(nextIds, style);
                    }
                    ProcessChildNodes(projectId, bookId, newDelta, elem, curChapter, ref curRef, ref nextNoteId);
                    SegmentEnded(newDelta, curRef);
                    if (!paraStyle)
                    {
                        curRef = null;
                    }
                    newDelta.InsertPara(GetAttributes(elem));
                    break;

                case "chapter":
                    curRef     = null;
                    curChapter = (string)elem.Attribute("number");
                    newDelta.InsertChapter(curChapter, GetAttributes(elem));
                    break;

                default:
                    LogUnknownElement(projectId, bookId, elem);
                    break;
                }
            }
            newDelta.Insert("\n");
            return(newDelta);
        }
Ejemplo n.º 2
0
 public static Delta InsertChapter(this Delta delta, string number)
 {
     return(delta.InsertChapter(number, new { style = "c" }));
 }