Ejemplo n.º 1
0
        private async Task ConvertBasics()
        {
            Log.Debug("downloading html");
            string html = await _client.GetPageHtmlContent(_page.Id);

            File.WriteAllText(Path.Combine(_baseDir, "post.html"), html);

            Log.Debug("converting");
            var    converter = new Converter(new Html2MarkdownScheme(_page.Title));
            string markdown  = converter.Convert(html);

            //extract resources
            Log.Debug("fixing resources");
            _resourceLocalToRemoteId.Clear();
            string[] resources     = Page.ExtractResourceIds(markdown);
            int      resourceIndex = 0;

            foreach (string rid in resources)
            {
                string localName = $"{resourceIndex++.ToString().PadLeft(3, '0')}.png";
                _resourceLocalToRemoteId[localName] = rid;

                Log.Debug("{rid} => {local}", rid, localName);

                markdown = markdown.Replace(Page.MakeFullResourceId(rid), localName);
            }
            markdown = markdown.RemoveLinesContaining("000.png", StringComparison.OrdinalIgnoreCase);

            Log.Debug("resources fixed in markdown");

            File.WriteAllText(Path.Combine(_baseDir, "post.md"), markdown);
        }