I thought this would be a simple task after I learn how to traverse the structure of a OneNote page.
A simple page will have an outline (that is the quivalent of a div html tag) and this outline will contain paragraphs (the p tag). Now the interesting part is coming, OneNote can indent paragraphs, this way the indented paragraph gets added to the collection of subparagraphs its predecessor has. This is easier said than done
The APIs are here.
Basically paragraph.paragraphs.items is the collection of paragraphs that are children of a paragraph. Each paragraph object has a property called parentParagraph which I can't figure out how to use.
So the idea would be to take an existing paragraph and move it as
ParagraphL1
ParagraphL2
ParagraphL3
should turn into
ParagraphL1
ParagraphL2
ParagraphL3
For the above to happen I guess paragraph2.items[0]=paragraph3
. I am not sure what is happening with the reference that paragraph1 has for paragraph3 as being one of its children
The other thing that I can't figure out is how to update the text of a paragraph with a new text. It seems that with the current APIs there no other way to do it other than adding a sibling of the existing one and deleting the existing one
Update
I have tried to move 'test' under Level11 (see the bottom of the picture for structure and IDs, see the console output, last three lines
So adding the test paragraph to Level11.items succeeded but it did not have the effect I expected; as you can see in the Watch window Level11 indicates it has child with test's ID but test does not indicate Level11 as its parent (see the IDs at the bottom and in the watch window
Summary
In one sentence: I need to be able to indent/outdent any arbitrary paragraph in a OneNote document using JavaScript APIs. Start from this code if you wish.