protected ParseCode LineParseParagraph(ref string line, ref int unitContentCount, ref Unit curUnit) { if (curUnit == null || line == null || unitContentCount < 0) { return(ParseCode.ERROR); } Paragraph curContent = new Paragraph(unitContentCount++, ""); List <BiblioRef> refs = LineParseBiblioRef(ref line, ref unitContentCount); for (int iLink = 0; iLink < refs.Count; iLink++) { refs[iLink].SetContentId(curContent.GetId()); curUnit.AddContent(refs[iLink]); } List <Attachment> attachments = LineParseAttachment(ref line, ref unitContentCount); for (int iLink = 0; iLink < attachments.Count; iLink++) { attachments[iLink].SetContentId(curContent.GetId()); curUnit.AddContent(attachments[iLink]); } Content lastUnitContent = curUnit.GetLastContent(); if (lastUnitContent != null && lastUnitContent.GetType() == typeof(Paragraph) && lastUnitContent.GetContent().EndsWith("//")) { ((Paragraph)lastUnitContent).AddText(line, false); } else { curContent.SetContent(line); curUnit.AddContent(curContent); } return(ParseCode.PARSED); }
protected ParseCode LineParseItemList(ref string line, ref int unitContentCount, ref Unit curUnit) { if (curUnit == null || line == null || unitContentCount < 0) { return(ParseCode.ERROR); } ItemList curContent = new ItemList(unitContentCount++, ""); if (line.StartsWith(m_Tags.ListOrd)) { curContent.SetOrdered(true); } line = line.Substring(1, line.Length - 1); line = line.Trim(); curContent.AddItem(line); curUnit.AddContent(curContent); return(ParseCode.PARSED); }
protected ParseCode LineParseImage(ref string line, ref int unitContentCount, ref Unit curUnit) { if (curUnit == null || line == null || unitContentCount < 0) { return(ParseCode.ERROR); } // an image cannot be inside text or other element if (!(line.StartsWith(m_Tags.Image) && line.EndsWith("]"))) { return(ParseCode.NO_PARSE); } line = line.Replace(m_Tags.Image, ""); line = line.Replace("]", ""); string relPath = line; relPath = relPath.Trim(); string imgPath = Utils.NormalizePath(string.Format("{0}{1}{2}", Directory.GetParent(m_FileInPath), Path.DirectorySeparatorChar, relPath)); if (!File.Exists(imgPath)) { return(ParseCode.ERROR); } Image origImg = Image.FromFile(imgPath); if (origImg == null) { return(ParseCode.ERROR); } Image scaledImg = Utils.ScaleImage(origImg, 500); string b64Img = Utils.ImageToBase64String(scaledImg, ImageFormat.Jpeg); curUnit.AddContent(new MetaImage(unitContentCount++, b64Img)); return(ParseCode.PARSED); }
protected ParseCode LineParseQuote(ref string line, ref int unitContentCount, ref Unit curUnit) { if (curUnit == null || line == null || unitContentCount < 0) { return(ParseCode.ERROR); } line = line.Replace(m_Tags.Quote, ""); Content lastUnitContent = curUnit.GetLastContent(); if (lastUnitContent != null && lastUnitContent.GetType() == typeof(Quote)) { // quote already open ((Quote)lastUnitContent).AddText(line, false); } else { Quote curContent = new Quote(unitContentCount++, ""); curContent.AddText(line); curUnit.AddContent(curContent); } return(ParseCode.PARSED); }