Ejemplo n.º 1
0
        public XmlNode GetEnexXmlNode(XmlDocument xmlDocument)
        {
            var strings   = Text.Split("\n");
            var textStart = 2;

            for (var i = 0; i < strings.Length; i++)
            {
                strings[i] = strings[i].Replace("\n", string.Empty).Replace("\r", string.Empty);
                if (strings[i].StartsWith("="))
                {
                    textStart = i + 1;
                }
            }

            var note  = xmlDocument.CreateElement("note");
            var title = xmlDocument.CreateElement("title");

            title.InnerText = strings[0];
            note.AppendChild(title);
            var noteDoc = new XmlDocument();

            noteDoc.AppendChild(noteDoc.CreateXmlDeclaration("1.0", "UTF-8", "no"));
            noteDoc.AppendChild(noteDoc.CreateDocumentType("en-note", null,
                                                           "http://xml.evernote.com/pub/enml2.dtd", null));
            var enNote = noteDoc.CreateElement("en-note");
            var text   = string.Join("\n", strings, textStart, strings.Length - textStart);

            text = ClearDtd(text);
            var paragraphExtension = new EnexParagraphExtension(_noteFolder);
            var markdownPipeline   = new MarkdownPipelineBuilder().Use(paragraphExtension).Build();
            var html = Markdown.ToHtml(text, markdownPipeline);

            enNote.InnerXml = html;
            noteDoc.AppendChild(enNote);
            var content = xmlDocument.CreateElement("content");
            var cdata   = xmlDocument.CreateCDataSection(noteDoc.OuterXml);

            content.AppendChild(cdata);
            note.AppendChild(content);
            var created = xmlDocument.CreateElement("created");

            created.InnerText = Enex.GetTimeString(File.GetCreationTime(_path));
            note.AppendChild(created);
            var updated = xmlDocument.CreateElement("updated");

            updated.InnerText = Enex.GetTimeString(File.GetLastWriteTime(_path));
            note.AppendChild(updated);
            ParseResources(xmlDocument, paragraphExtension, note);
            return(note);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            var enex = Enex.Create(args[0]);

            File.WriteAllText(args[1], enex.OuterXml);
        }