alxnbl / onenote-md-exporter

ConsoleApp to export OneNote notebooks to Markdown formats
GNU General Public License v3.0
919 stars 75 forks source link

OneNotes notes with folded/collapsed areas not converted #99

Closed SomeMichael closed 4 months ago

SomeMichael commented 8 months ago

Describe the bug When one uses folding/collapsing in OneNote onenote-md-exporter misses the folded/collapsed content when converting. OneNote-Example: OneNote

Results: Folded content is not included. Joplin_Folded Joplin_Unfolded

To Reproduce Convert the following OneNote file: Test_OneNote2Joplin.zip

Expected behavior Also convert content in the folded sections.

Desktop (please complete the following information):

Additional context I tried to find a way to automatically unfold these section looking here, but couldn't find anything (But I'm not an expert one these things :)) It might be possible using getonetastic? My problem is that my OneNote collection of Notes is quite big. Resulting in 7000 files (also attachments included, though) on Joplin side. So checking everything manually is some work... ;-)

Many thanks for any kind of help!

alxnbl commented 8 months ago

Hello @SomeMichael , thank you for the detailed feedback. Indeed I knew this limitation which comes from a behavior of OneNote API. I don't think I will have time to determine if and how it would be possible to unfold automatically paragraph during page export. However in your case, as you suggested, find a OneNote plugin that can do that for you seams a good approach. I don't know much theses plugins, but maybe you can find help on some OneNote community forums like https://www.reddit.com/r/OneNote/ .

SomeMichael commented 8 months ago

Thanks for your answer, @alxnbl. I think will getonetastic a try, then.

Maybe it would be a good idea to add this limitation here?

alxnbl commented 8 months ago

Indeed, I added the limitation to the readme !

SomeMichael commented 7 months ago

Just if anyone runs into the same issue and finds this thread. I came up with this Powershell script to expand all outlines in a notebook:

$OneNote = New-Object -ComObject OneNote.Application

[string]$nbid = ""
[xml]$nbh = ""

$OneNote.OpenHierarchy('FullPath2NotebookFolder', "", [ref]$nbid)
$OneNote.GetHierarchy($nbid, [Microsoft.Office.Interop.OneNote.HierarchyScope]::hsPages, [ref]$nbh)

foreach ($page in $nbh.Notebook.Section.Page ) {

    $page.ParentNode.Name + " " + $page.Name

    [xml]$pagexml = ""
    $OneNote.GetPageContent($page.ID, [ref]$pagexml)

    $write = ""
    foreach ($el in $pagexml.GetElementsByTagName("one:OE")) {

        if ($el.collapsed -eq "1") {

            Write-Host "    Outline expanded!"
            $el.removeAttribute("collapsed")
            $write = "updatepage"

        }
    }

    if ($write -ne "") {
        $OneNote.UpdatePageContent($pagexml.OuterXml.ToString())
    }
}

Replace FullPath2NotebookFolder with the full path to the folder containing the *.one files of your notebook!

Please run this script using Powershell 5.* . Powershell 6 and above have issues explained here. I couldn't figure out how to get it running in Powershell 7.*.

Please make a backup of your *.one files prior to running the script! I'm not a very experienced programmer, so expect some errors when you run the script ;-)

alxnbl commented 4 months ago

Thanks @SomeMichael , @Argimko made a Pull Request to support unfolding of paragraph 🎉. The evolution is embedded in version 1.5.0.