Skip to content

Commit 4644956

Browse files
committed
fix importing code sections
closes #35
1 parent e28d701 commit 4644956

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

evernote2onenote/src/MainFrm.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public partial class MainFrm : Form
5959
private readonly string _cmdNoteBook = "";
6060
private DateTime _cmdDate = new DateTime(0);
6161

62-
private readonly Regex _rxStyle = new Regex("(?<text>\\<(?:div|span|li|ul).)style=\\\"[^\\\"]*\\\"", RegexOptions.IgnoreCase);
62+
private readonly Regex _rxStyle = new Regex("(?<text>\\<(?:div|span|li|ul).)\\s*style=\\\"[^\\\"]*\\\"", RegexOptions.IgnoreCase);
6363
private readonly Regex _rxFontFamily = new Regex(@"font-family: \""[^\""]*\""", RegexOptions.IgnoreCase);
6464
private readonly Regex _rxCdata = new Regex(@"<!\[CDATA\[<\?xml version=[""']1.0[""'][^?]*\?>", RegexOptions.IgnoreCase);
6565
private readonly Regex _rxCdata2 = new Regex(@"<!\[CDATA\[<!DOCTYPE en-note \w+ ""https?://xml.evernote.com/pub/enml2.dtd"">", RegexOptions.IgnoreCase);
@@ -416,7 +416,7 @@ private void ImportNotesToOnenote(List<Note> notesEvernote, string exportFile)
416416
{
417417
node = contentElements[0];
418418
}
419-
note.Content = HttpUtility.HtmlDecode(node.InnerXml);
419+
note.Content = node.InnerXml;//HttpUtility.HtmlDecode(node.InnerXml);
420420
if (note.Content.StartsWith("=?"))
421421
note.Content = Rfc2047Decoder.Parse(note.Content);
422422

@@ -552,7 +552,14 @@ private void ImportNotesToOnenote(List<Note> notesEvernote, string exportFile)
552552
note.Attachments.Clear();
553553

554554
htmlBody = _rxFontFamily.Replace(htmlBody, string.Empty);
555-
htmlBody = _rxStyle.Replace(htmlBody, "${text}");
555+
htmlBody = _rxStyle.Replace(htmlBody, delegate (Match m)
556+
{
557+
if (m.Value.Contains("--en-codeblock:true;"))
558+
return m.Result("<br><br>${text}") + "style=\"background-color:#B0B0B0; font-family: Consolas, Courier New, monospace; font-size: 15px;\"";
559+
return m.Result("${text}");
560+
});
561+
htmlBody = htmlBody.Replace("<pre>", "<br><br><pre style=\"font-family: Consolas, Courier New, monospace; font-size: 15px; background-color:#B0B0B0;\">");
562+
htmlBody = htmlBody.Replace("</pre>", "</pre><br><br>");
556563
htmlBody = _rxComment.Replace(htmlBody, string.Empty);
557564
htmlBody = _rxEmptyCdata.Replace(htmlBody, string.Empty);
558565
htmlBody = _rxEmptyCdata2.Replace(htmlBody, string.Empty);
@@ -568,7 +575,7 @@ private void ImportNotesToOnenote(List<Note> notesEvernote, string exportFile)
568575

569576
// Evernote does not escape < and > chars in <pre> sections!
570577
// do that here so we don't get malformed xml
571-
var rxPre = new Regex(@"<pre\b[^>]*?>(.+)</pre>", RegexOptions.IgnoreCase|RegexOptions.Singleline);
578+
var rxPre = new Regex(@"<pre\b[^>]*?>(.+)</pre>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
572579
foreach (Match match in rxPre.Matches(htmlBody))
573580
{
574581
var fullPreSection = match.ToString();

0 commit comments

Comments
 (0)