Skip to content

Commit 5244f8a

Browse files
authored
Merge pull request #104 from alxnbl/dev-150
Version 1.5.0
2 parents b22c5ea + a7f3f80 commit 5244f8a

33 files changed

+806
-550
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
This tool is usefull to :
44
* evaluate or migrate to an alternative Knowledge Management Software like Joplin, Obsidian or other softwares based on Markdown format
55
* backup your OneNote Notebooks in an interoperable and open file format
6-
6+
7+
The tool is easy to install and use, and generally produces better results than other OneNote export methods.
8+
79
# Requirements
810

911
- Windows >=10
@@ -50,7 +52,7 @@ Command line is supported, run `OneNoteMdExporter.exe --help` for instructions.
5052
---
5153
Page content
5254
```
53-
* `PanDocMarkdownFormat` : choose the markdown syntax to use among [those supported by pandoc](https://pandoc.org/MANUAL.html#general-options). Use *Github flavor* by default.
55+
* `PanDocMarkdownFormat` : choose the markdown syntax to use among [those supported by pandoc](https://pandoc.org/MANUAL.html#general-options). Use *GitHub flavor* by default.
5456

5557
## Joplin Raw Directory
5658

@@ -61,7 +63,7 @@ Command line is supported, run `OneNoteMdExporter.exe --help` for instructions.
6163

6264
| Export format: | Markdown | Joplin |
6365
| --- | --- | --- |
64-
| Hierarchy of sections | ✅ Folder hierarchy | ✅ Notbook hierarchy |
66+
| Hierarchy of sections | ✅ Folder hierarchy | ✅ Notebook hierarchy |
6567
| Page ordering inside a section | 🔴 Ordering based on md filename | ✅ |
6668
| Page hierarchy | ✅ Page prefix or folder prefix | ✅ |
6769

@@ -71,17 +73,17 @@ ___
7173

7274
| All formats : | |
7375
| --- | --- |
74-
| Attachments | 🟠 File of certain extensions are lost (wma, wmv, mpg, svg, mp3) |
76+
| Attachments | |
7577
| Image | ✅ |
7678
| Table | ✅ |
77-
| Image nexted into table | 🔴 Known issue (#48) |
79+
| Folded paragraphs | ✅ |
80+
| Image nexted into table | 🔴 Known issue [#48](https://github.com/alxnbl/onenote-md-exporter/issues/48) |
7881
| Font color| 🔴 |
7982
| Background color | 🟠 Highlighted text |
8083
| Drawing | 🟠 Flattened as image |
8184
| Handwriting | 🔴 Lost |
8285
| Text tags (task, star...) | 🔴 Lost |
8386
| Password protected sections | 🟠 Lost unless unlocked before export |
84-
| Folded pargraphs | 🔴 Lost |
8587
| Notebook internal link | 🔴 onenote:// url |
8688

8789
# Technical characteristics
@@ -90,7 +92,8 @@ ___
9092
* Export page as DocX and translate them in Markdown using PanDoc
9193
* Offline : no call to Microsoft cloud
9294
* Based on Office Interop APIs
93-
* Apply some post-processing based on Regex to correct formatting issues
95+
* Pre-processing stage of OneNote page XML structure
96+
* Post-processing stage based on Regex to fix formatting issues
9497

9598
# Licence
9699

doc/contribute.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Add a new Export setting
22

33
- Add the setting in [AppSettings.cs](/src/OneNoteMdExporter/Infrastructure/AppSettings.cs) with a description
4-
- Add the setting in [appsettings.json](/src/OneNoteMdExporter/appsettings.json) with a description
5-
- Use your settings in ExportServiceBase.cs / JoplinExportService or MdExportService using the `_appSettings` field
4+
- Add the setting in [appSettings.json](/src/OneNoteMdExporter/appSettings.json) with a description
5+
- Use your settings in ExportServiceBase.cs / JoplinExportService or MdExportService using the `AppSettings` class
66

77
# Add a new langage to translations
88

doc/migration-to-joplin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ One of the objectives of this tool it to offer the most simple and lossless solu
2525
| Password protected sections | 🔴 Lost | 🔴 Lost |
2626
| Notebook internal link | 🔴 onenote:// url | 🔴 onenote:// url |
2727

28-
(\*1) : setting `ProcessingOfPageHierarchy = HiearchyAsFolderTree` (default)<br />
29-
(\*2) : setting `ProcessingOfPageHierarchy = HiearchyAsPageTitlePrefix`
28+
(\*1) : setting `ProcessingOfPageHierarchy = HierarchyAsFolderTree` (default)<br />
29+
(\*2) : setting `ProcessingOfPageHierarchy = HierarchyAsPageTitlePrefix`
3030

3131
# User guide
3232

doc/publish-new-release.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
1. Update `Package version` of `OneNoteMdExporter` project to the desired software version.
44
3. Ensure PanDoc archive has beed unzipped in folder `src\OneNoteMdExporter\pandoc`
55
3. From Visual Studio, use Publish profile of `OneNoteMdExporter` project to build the tool binaries
6-
4. Open output folder (`bin\Release\net5.0\win7-x86\publish`) and Zip the content of the folder and name it `OneNoteMdExporter.vX.Y.Z.zip`
6+
4. Open output folder (`bin\Release\net8.0\win-x86\publish\win-x64`) and Zip the content of the folder and name it `OneNoteMdExporter.vX.Y.Z.zip`
7+
5. Go into Releases, create a tag "vX.Y.Z" and create a release "vX.Y.Z"

sample/TestNotebook.onepkg

3.39 KB
Binary file not shown.

src/OneNoteMdExporter.IntTests/OneNoteMdExporter.IntTests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net8.0-windows</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
@@ -19,9 +19,9 @@
1919

2020
<ItemGroup>
2121
<!-- COMReference of OneNoteMdExporter not yet supported by DotNet5 -->
22-
<PackageReference Include="NUnit" Version="4.0.1" />
22+
<PackageReference Include="NUnit" Version="4.1.0" />
2323
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
24-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
24+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
2525
</ItemGroup>
2626

2727
<ItemGroup>

src/OneNoteMdExporter.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30804.86
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34723.18
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneNoteMdExporter", "OneNoteMdExporter\OneNoteMdExporter.csproj", "{3D5886DD-752E-48FB-BC28-8F37F3298948}"
77
EndProject

src/OneNoteMdExporter/Helpers/OneNoteExtensions.cs

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using Microsoft.Office.Interop.OneNote;
1+
using alxnbl.OneNoteMdExporter.Infrastructure;
22
using alxnbl.OneNoteMdExporter.Models;
3+
using Microsoft.Office.Interop.OneNote;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using System.Xml.Linq;
7-
using alxnbl.OneNoteMdExporter.Infrastructure;
88

99
namespace alxnbl.OneNoteMdExporter.Helpers
1010
{
@@ -27,7 +27,7 @@ public static IList<Notebook> GetNotebooks(this Application oneNoteApp)
2727
CreationDate = element.GetDate("lastModifiedTime"),
2828
LastModificationDate = element.GetDate("lastModifiedTime")
2929
};
30-
}).ToList();
30+
}).Where(element => element.Title != TemporaryNotebook.Title).ToList();
3131
}
3232

3333
public static DateTime GetDate(this XElement element, string attributeName)
@@ -47,37 +47,29 @@ public static Section GetSection(this XElement element, Node parentNode)
4747
OneNoteId = element.Attribute("ID")?.Value,
4848
OneNotePath = element.Attribute("path")?.Value,
4949
CreationDate = element.GetDate("lastModifiedTime"),
50-
LastModificationDate = element.GetDate("lastModifiedTime")
50+
LastModificationDate = element.GetDate("lastModifiedTime"),
51+
IsSectionGroup = element.Name.LocalName switch
52+
{
53+
"SectionGroup" => true,
54+
"Section" => false,
55+
_ => throw new NotImplementedException(),
56+
}
5157
};
52-
53-
switch (element.Name.LocalName)
54-
{
55-
case "SectionGroup":
56-
section.IsSectionGroup = true;
57-
break;
58-
case "Section":
59-
section.IsSectionGroup = false;
60-
break;
61-
default:
62-
throw new NotImplementedException();
63-
64-
}
65-
6658
return section;
6759
}
6860

69-
public static Page GetPage(this XElement element, Section parentSection, AppSettings appSettings)
61+
public static Page GetPage(this XElement element, Section parentSection)
7062
{
7163
var pageId = element.Attribute("ID")?.Value;
7264

73-
DateTime.TryParse(element.Attribute("dateTime").Value, out var creationDate);
74-
DateTime.TryParse(element.Attribute("lastModifiedTime").Value, out var lastModificationDate);
75-
int.TryParse(element.Attribute("pageLevel").Value, out var pageLevel);
65+
_ = DateTime.TryParse(element.Attribute("dateTime").Value, out var creationDate);
66+
_ = DateTime.TryParse(element.Attribute("lastModifiedTime").Value, out var lastModificationDate);
67+
_ = int.TryParse(element.Attribute("pageLevel").Value, out var pageLevel);
7668

7769
var title = element.Attribute("name").Value;
7870

79-
// Limit title max size, especilay for notes with no title where the 1st paragraphe is returned as a title
80-
if (title.Length > appSettings.PageTitleMaxLength)
71+
// Limit title max size, especially for notes with no title where the 1st paragraph is returned as a title
72+
if (title.Length > AppSettings.PageTitleMaxLength)
8173
title = new string(title.Take(50).ToArray()) + "...";
8274

8375
var page = new Page(parentSection)
@@ -133,7 +125,7 @@ private static void FillNodebookSections(Node node, XElement xmlNode)
133125
/// </summary>
134126
/// <param name="section"></param>
135127
/// <returns>List of pages</returns>
136-
public static IList<Page> FillSectionPages(this Application oneNoteApp, Section section, AppSettings appSettings)
128+
public static IList<Page> FillSectionPages(this Application oneNoteApp, Section section)
137129
{
138130
oneNoteApp.GetHierarchy(section.OneNoteId, HierarchyScope.hsPages, out var xmlStr);
139131
var xmlSection = XDocument.Parse(xmlStr).Root;
@@ -142,7 +134,7 @@ public static IList<Page> FillSectionPages(this Application oneNoteApp, Section
142134
var xmlPages = xmlSection.Descendants(ns + "Page")
143135
.Where(e => e.Attribute("isRecycleBin") == null && e.Attribute("isDeletedPages") == null);
144136

145-
var childPages = xmlPages.Select(xmlP => xmlP.GetPage(section, appSettings)).ToList();
137+
var childPages = xmlPages.Select(xmlP => xmlP.GetPage(section)).ToList();
146138

147139
Page pageL1Cursor = null;
148140
Page pageL2Cursor = null;
@@ -167,47 +159,10 @@ public static IList<Page> FillSectionPages(this Application oneNoteApp, Section
167159
page.SetParentPage(pageL2Cursor ?? pageL1Cursor); // If page level 3 under a page level 1
168160
}
169161

170-
oneNoteApp.GetPageContent(page.OneNoteId, out var xmlPageContentStr, PageInfo.piAll);
171-
172-
173-
// Alternative : return page content without binaries
174-
//oneNoteApp.GetHierarchy(page.OneNoteId, HierarchyScope.hsChildren, out var xmlAttach);
175-
176-
var xmlPageContent = XDocument.Parse(xmlPageContentStr).Root;
177-
178-
var ns2 = xmlPageContent.Name.Namespace;
179-
var pageTitleOE = xmlPageContent.Descendants(ns + "Title")?.FirstOrDefault()?.Descendants(ns + "OE")?.FirstOrDefault();
180-
if (pageTitleOE != null)
181-
{
182-
page.Author = pageTitleOE.Attribute("author")?.Value ?? "unknown";
183-
}
184-
185162
section.Childs.Add(page);
186-
187-
ProcessPageAttachments(ns, page, xmlPageContent);
188163
}
189164

190-
191165
return childPages;
192166
}
193-
194-
private static void ProcessPageAttachments(XNamespace ns, Page page, XElement xmlPageContent)
195-
{
196-
foreach (var xmlInsertedFile in xmlPageContent.Descendants(ns + "InsertedFile"))
197-
{
198-
var fileAttachment = new Attachement(page)
199-
{
200-
ActualSourceFilePath = xmlInsertedFile.Attribute("pathCache")?.Value,
201-
OriginalUserFilePath = xmlInsertedFile.Attribute("pathSource")?.Value,
202-
OneNotePreferredFileName = xmlInsertedFile.Attribute("preferredName")?.Value,
203-
Type = AttachementType.File
204-
};
205-
206-
if (fileAttachment.ActualSourceFilePath != null)
207-
{
208-
page.Attachements.Add(fileAttachment);
209-
}
210-
}
211-
}
212167
}
213168
}

src/OneNoteMdExporter/Helpers/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static string RemoveMdReferenceInvalidChars(this string reference)
2424
=> reference?.Replace(" ", "_");
2525

2626
public static string Left(this String input, int length)
27-
=> (input.Length < length) ? input : input.Substring(0, length);
27+
=> (input.Length < length) ? input : input[..length];
2828

2929
}
3030
}

0 commit comments

Comments
 (0)