Skip to content

Commit

Permalink
Merge pull request #76 from alxnbl/dev-130
Browse files Browse the repository at this point in the history
Version 1.3.0

Enhancements
- Avoid corrupted pages to bloc the export of the rest of the notebook (#75 #53 #42)
- Add an execution report that display a warning if the export ended with error (#74)
- Upgrade project Framework to DotNet 6 (#73)
- Update Pandoc version to 2.19.2
- Better handling of errors on startup (#65)
- Add a setting to to configure the max length of a page title before truncation (#72)

Bug fixes
- Option ProcessingOfPageHierarchy = HiearchyAsFolderTree do not work (#63)
  • Loading branch information
alxnbl authored Oct 26, 2022
2 parents 731882f + 2ffac97 commit d2cd409
Show file tree
Hide file tree
Showing 22 changed files with 5,278 additions and 1,438 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Join the "logs.txt" log file located in the directory of the tool.
⚠️ Ensure that the log file do not contain any personal data ⚠️

**Desktop (please complete the following information):**
- OneNodeMdExporter version : XXXX
- Windows version : XXXX 32/64 bits
- Office Version : XXXX 32/64 bits

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ This tool is usefull to :
# Requirements

- Windows >=10
- OneNote >= 2016, OneNote for Windows (from the Windows store) is not supported
- Word >= 2016
- OneNote >= 2013, OneNote for Windows (from the Windows store) is not supported
- Word >= 2013

# Getting started

1. Download the last release of OneNoteMdExporter from the [Releases page](https://github.com/alxnbl/onenote-md-exporter/releases)
2. Extract the content of the Zip archive
3. Launch OneNote and be sure that notebooks to export are opened
3. Launch OneNote and be sure that notebooks to export are loaded
4. Export your notebooks :
* Start `OneNoteMdExporter.exe`
* Select the Notebook to export
Expand Down Expand Up @@ -83,7 +83,7 @@ ___

# Technical characteristics

* DotNet 5 self-contained console application
* DotNet 6 self-contained console application
* Export page as DocX and translate them in Markdown using PanDoc
* Offline : no call to Microsoft cloud
* Based on Office Interop APIs
Expand All @@ -108,7 +108,7 @@ Pandoc is released under the following licence terms, full licence details can b

# Build sources

* Install DotNet 5 : https://dotnet.microsoft.com/download/dotnet/5.0
* Install DotNet 6 : https://dotnet.microsoft.com/download/dotnet/6.0
* Clone this repository
* Extract `pandoc.exe` from `pandoc-<Version>-windows-x86_64.zip` from `/src/OneNoteMdExporter/pandoc/` folder
* Build using Visual Studio 2019 or MSBUILD.exe (`dotnet build` do not currently support COMReference : https://aka.ms/msbuild/MSB4803)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Binary file not shown.
11 changes: 6 additions & 5 deletions src/OneNoteMdExporter/Helpers/OneNoteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using alxnbl.OneNoteMdExporter.Infrastructure;

namespace alxnbl.OneNoteMdExporter.Helpers
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public static Section GetSection(this XElement element, Node parentNode)
return section;
}

public static Page GetPage(this XElement element, Section parentSection)
public static Page GetPage(this XElement element, Section parentSection, AppSettings appSettings)
{
var pageId = element.Attribute("ID")?.Value;

Expand All @@ -75,8 +76,8 @@ public static Page GetPage(this XElement element, Section parentSection)

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

// Limit title max size, especilay for notes with not title where the 1st paragraphe is returned as a title
if (title.Length > 50)
// Limit title max size, especilay for notes with no title where the 1st paragraphe is returned as a title
if (title.Length > appSettings.PageTitleMaxLength)
title = new string(title.Take(50).ToArray()) + "...";

var page = new Page(parentSection)
Expand Down Expand Up @@ -132,7 +133,7 @@ private static void FillNodebookSections(Node node, XElement xmlNode)
/// </summary>
/// <param name="section"></param>
/// <returns>List of pages</returns>
public static IList<Page> FillSectionPages(this Application oneNoteApp, Section section)
public static IList<Page> FillSectionPages(this Application oneNoteApp, Section section, AppSettings appSettings)
{
oneNoteApp.GetHierarchy(section.OneNoteId, HierarchyScope.hsPages, out var xmlStr);
var xmlSection = XDocument.Parse(xmlStr).Root;
Expand All @@ -141,7 +142,7 @@ public static IList<Page> FillSectionPages(this Application oneNoteApp, Section
var xmlPages = xmlSection.Descendants(ns + "Page")
.Where(e => e.Attribute("isRecycleBin") == null && e.Attribute("isDeletedPages") == null);

var childPages = xmlPages.Select(xmlP => xmlP.GetPage(section)).ToList();
var childPages = xmlPages.Select(xmlP => xmlP.GetPage(section, appSettings)).ToList();

Page pageL1Cursor = null;
Page pageL2Cursor = null;
Expand Down
7 changes: 7 additions & 0 deletions src/OneNoteMdExporter/Infrastructure/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class AppSettings
* Export general settings
* */

/// <summary>
/// Maximum number of characters of a page title. Among this limit, title is contracted.
/// </summary>
public int PageTitleMaxLength { get; set; } = 50;

/// <summary>
/// Add at the begining of each page a YAML header that include Page metadata (cf https://assemble.io/docs/YAML-front-matter.html)
/// </summary>
Expand Down Expand Up @@ -54,6 +59,8 @@ public class AppSettings
/// </summary>
public string ResourceFolderName { get; set; } = "_resources";



/*
* Markdown rendering Settings
* */
Expand Down
26 changes: 26 additions & 0 deletions src/OneNoteMdExporter/Models/NotebookExportResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace alxnbl.OneNoteMdExporter.Models
{
public class NotebookExportResult
{
/// <summary>
/// Contains the errorCode of the error that cause a crash during the export. Null if export ended correctly.
/// </summary>
public string NoteBookExportErrorCode { get; set; }

/// <summary>
/// Contains the error message the an error that cause a crash during the export. Null if export ended correctly.
/// </summary>
public string NoteBookExportErrorMessage { get; set; }

/// <summary>
/// Number of pages that fail to be exported
/// </summary>
public int PagesOnError { get; set; } = 0;
}
}
2 changes: 1 addition & 1 deletion src/OneNoteMdExporter/Models/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Page : Node

private Page _parentPage { get; set; }

public Page ParentPage { get; }
public Page ParentPage { get => _parentPage; }

public void SetParentPage(Page parentPage)
{
Expand Down
16 changes: 16 additions & 0 deletions src/OneNoteMdExporter/Models/SectionExportResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace alxnbl.OneNoteMdExporter.Models
{
public class SectionExportResult
{
/// <summary>
/// Number of pages that fail to be exported
/// </summary>
public int PagesOnError { get; set; } = 0;
}
}
6 changes: 3 additions & 3 deletions src/OneNoteMdExporter/OneNoteMdExporter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<TargetFramework>net6.0</TargetFramework>
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<PackageId>OneNoteMdExporter</PackageId>
<Authors>alxnbl</Authors>
<Company />
Expand Down
57 changes: 50 additions & 7 deletions src/OneNoteMdExporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace alxnbl.OneNoteMdExporter
{
public class Program
{
private const string loggerFilename = "logs.txt";

public class Options
{
[Option('n', "notebook", Required = false, HelpText = "The name of the notebook to export")]
Expand Down Expand Up @@ -53,13 +55,28 @@ public static void Main(params string[] args)
});
}

private static OneNote.Application OneNoteApp;
public static OneNote.Application OneNoteApp;

private static void RunOptions(Options opts)
{
InitLogger();

OneNoteApp = new OneNote.Application();
try
{
OneNoteApp = new OneNote.Application();
}
catch (Exception)
{
Log.Error("ErrorPreventToCommunicateWithOneNote");

if (!opts.NoInput)
{
Log.Information(Localizer.GetString("PressEnter"));
Console.ReadLine();
}

throw;
}

WelcomeScreen(opts);

Expand Down Expand Up @@ -106,11 +123,37 @@ private static void RunOptions(Options opts)
Log.Information(Localizer.GetString("StartExportingNotebook"), notebook.Title);
Log.Information("***************************************");

exportService.ExportNotebook(notebook, opts.SectionName, opts.PageName);
var result = exportService.ExportNotebook(notebook, opts.SectionName, opts.PageName);

Log.Information("");
Log.Information(Localizer.GetString("ExportSuccessful"), Path.GetFullPath(notebook.ExportFolder));
Log.Information("");
if(!string.IsNullOrEmpty(result.NoteBookExportErrorMessage))
{
// Unable to finalize notebook export
Log.Error(result.NoteBookExportErrorMessage);

if (!opts.NoInput)
{
Log.Information(Localizer.GetString("PressEnter"));
Console.ReadLine();
}
}
else if (result.PagesOnError > 0)
{
Log.Information("");
Log.Warning(Localizer.GetString("ExportEndedWithErrors"), Path.GetFullPath(notebook.ExportFolder), result.PagesOnError, loggerFilename);
Log.Information("");

if (!opts.NoInput)
{
Log.Information(Localizer.GetString("PressEnter"));
Console.ReadLine();
}
}
else
{
Log.Information("");
Log.Information(Localizer.GetString("ExportSuccessful"), Path.GetFullPath(notebook.ExportFolder));
Log.Information("");
}
}

if (!opts.NoInput)
Expand Down Expand Up @@ -231,7 +274,7 @@ private static IList<Notebook> NotebookSelectionForm()
private static void InitLogger()
{
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs.txt", outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File(loggerFilename, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Console(Serilog.Events.LogEventLevel.Information, "{Message:lj}{NewLine}")
.CreateLogger();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net5.0\win-x86\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
7 changes: 6 additions & 1 deletion src/OneNoteMdExporter/Resources/trad.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"StartExportingNotebook": "Start exporting notebook: {0}",
"ExportSuccessful": "--> Notebook export successful\nExport folder : '{0}'",
"ErrorDuringPageProcessing": "Error during processing of page {0} [{1}]. Page ignored. Error message : {2}",
"ErrorDuringPageProcessingIsOneNoteRunning": "Error during processing of page {0} [{1}], page ignored. The page can be corrupted, or OneNote is not running. Error message : {2}",
"ErrorDuringPageProcessingRetryInProgress": "Error during processing of page {0} [{1}], unable to communicate with OneNote. Waiting {3}s before retry.",
"SuccessPageExportAfterRetry": "Page export successful after one retry.",
"ErrorDuringSectionProcessing": "Error during processing of section {0} [{1}]. Error message : {2}",
"ErrorDuringNotebookProcessingNbTree": "Error during processing of notebook {0} [{1}]. Can't browse notebook tree. Error message : {2}",
"EndOfExport": "\nPress any key to exit...",
Expand All @@ -26,5 +29,7 @@
"FoundXSections": "--> Found {0} sections\n",
"FoundXSectionsAndSecGrp": "--> Found {0} sections and sections groups\n",
"StartProcessingSectionX": "Start processing section",
"Page": "Page"
"Page": "Page",
"ExportEndedWithErrors": "--> WARNING: export of your notebook has ended with {1} page(s) on error.\\You can find more details in the log file '{2}'.\\nExport folder : '{0}'",
"ErrorPreventToCommunicateWithOneNote": "An error occurs while trying to communicate with OneNote. Your Office installation may be corrupted. You can try to fix this by running the Office repair utility. Please refer to : https://support.microsoft.com/en-us/office/repair-an-office-application-7821d4b6-7c1d-4205-aa0e-a6b40c5bb88b ."
}
7 changes: 6 additions & 1 deletion src/OneNoteMdExporter/Resources/trad.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"StartExportingNotebook": "Début de l'export du bloc-note : {0}",
"ExportSuccessful": "--> Export du bloc-note terminé\nDossier de l'export : '{0}'",
"ErrorDuringPageProcessing": "Erreur durant le traitement de la page [{1}]. Page ignorée. Message d'erreur : {2}",
"ErrorDuringPageProcessingIsOneNoteRunning": "Erreur durant le traitement de la page [{1}], page ignorée. La page est peut-être corrompue ou OneNote n'est pas démarré. Message d'erreur : {2}",
"ErrorDuringPageProcessingRetryInProgress": "Erreur durant le traitement de la page [{1}], impossible de communiquer avec OneNote. Attente de {3}s avant nouvel essai.",
"SuccessPageExportAfterRetry": "Export de la page réussi.",
"ErrorDuringSectionProcessing": "Erreur durant le traitement de la section {0} [{1}]. Message d'erreur : {2}",
"ErrorDuringNotebookProcessingNbTree": "Erreur durant le traitement du bloc-note {0} [{1}]. Impossible de charger l'arborescence. Message d'erreur : {2}",
"EndOfExport": "\nAppuyez sur une touche pour quitter...",
Expand All @@ -25,5 +28,7 @@
"FoundXSections": "--> {0} sections trouvées\n",
"FoundXSectionsAndSecGrp": "--> {0} sections et groupes de section trouvés\n",
"StartProcessingSectionX": "Début du traitement de la section",
"Page": "Page"
"Page": "Page",
"ExportEndedWithErrors": "--> ATTENTION: l'export du bloc-note s'est terminé avec {1} page(s) en erreur.\nVous pouvez consulter le détail des logs dans le fichier '{2}'.\nDossier de l'export : '{0}'",
"ErrorPreventToCommunicateWithOneNote": "Une erreur s'est produit lors de la communication avec OneNote. Votre installation d'Office est peut être corrompue. Vous pouvez tenter de la réparer en exécutant l'utilitaire de réparation Office. Pour cela consulter la page suivante : https://support.microsoft.com/fr-fr/office/r%C3%A9parer-une-application-office-7821d4b6-7c1d-4205-aa0e-a6b40c5bb88b ."
}
Loading

0 comments on commit d2cd409

Please sign in to comment.