Closed 1001QAdotNET closed 3 years ago
I admit I don't know much about Python so only put in basic syntax like keywords, comments, and strings.
Do you know regular expressions? The definition file should be in C:\Program Files (x86)\River\OneMoreAddIn\Colorizer\Language but I'll take a look too
Actually I just realized that I can't recognize multi-line comments, for any language. I'll have to think about it.
I know there are a ton of discrepancies in the colorizer across all the languages. I didn't try to cover all use cases. OneMore isn't a programming environment and I imagine most will only want to make things "prettier" than they are so this should get you most of the way there.
I'm hoping others will help contribute languages and help fix the ones I have
OK I wrote a plugin myself for colorizing Python I am using a library called Pygments and it can colorize everything under the sun
I am able to get the selected elements in the XML file and replace the content with colorized text, line by line (working with one:T elements only)
I am getting an error from the runner, here is what the error is saying
`..plugin process exited
25572:20] ..error updating page content
25572:20] ..EXCEPTION - System.Runtime.InteropServices.COMException
Message...: Exception from HRESULT: 0x80042009
StackTrace: at Microsoft.Office.Interop.OneNote.IApplication.UpdatePageContent(String bstrPageChangesXmlIn, DateTime dateExpectedLastModified, XMLSchema xsSchema, Boolean force)
at River.OneMoreAddIn.OneNote.Update(XElement element)
TargetSite: [River.OneMoreAddIn] Microsoft.Office.Interop.OneNote.IApplication::UpdatePageContent()
25572:20] ..<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2013/onenote" ID="{xxxxxx}" name="Lorem Ipsum" dateTime="2020-12-11T21:03:42.000Z" lastModifiedTime="2020-12-13T15:54:43.000Z" pageLevel="1" isCurrentlyViewed="true" selected="partial" lang="en-US">
<one:QuickStyleDef index="0" name="PageTitle" fontColor="automatic" highlightColor="automatic" font="Calibri Light" fontSize="20.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:QuickStyleDef index="1" name="p" fontColor="automatic" highlightColor="automatic" font="Calibri" fontSize="10.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:PageSettings RTL="false" color="automatic">
<one:PageSize>
<one:Automatic />
</one:PageSize>
<one:RuleLines visible="false" />
</one:PageSettings>
<one:Title lang="yo">
<one:OE author="Microsoft account" authorInitials="Ma" authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedBy="Microsoft account" lastModifiedByInitials="Ma" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T06:26:59.000Z" lastModifiedTime="2020-12-13T06:26:59.000Z" alignment="left" quickStyleIndex="0">
<one:T><![CDATA[Lorem Ipsum (2)]]></one:T>
</one:OE>
</one:Title>
<one:Outline selected="partial" author="Microsoft account" authorInitials="Ma" lastModifiedBy="Microsoft account" lastModifiedByInitials="Ma" lastModifiedTime="2020-12-13T15:40:02.000Z">
<one:Position x="36.0" y="86.4000015258789" z="0" />
<one:Size width="156.5809478759765" height="48.82802963256836" />
<one:OEChildren selected="partial">
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight"><pre><span></span><span class="c1"># Python 3 code to find sum </span>
</pre></div>
]]></one:T>
</one:OE>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight"><pre><span></span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">arr</span><span class="p">:</span>
</pre></div>
]]></one:T>
</one:OE>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight"><pre><span></span> <span class="nb">sum</span> <span class="o">=</span> <span class="nb">sum</span> <span class="o">+</span> <span class="n">i</span>
</pre></div>
]]></one:T>
</one:OE>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight"><pre><span></span> <span class="k">return</span><span class="p">(</span><span class="nb">sum</span><span class="p">)</span>
</pre></div>
]]></one:T>
</one:OE>
</one:OEChildren>
</one:Outline>
<one:Outline author="Microsoft account" authorInitials="Ma" lastModifiedBy="Microsoft account" lastModifiedByInitials="Ma" lastModifiedTime="2020-12-13T15:51:43.000Z">
<one:Position x="468.0" y="104.400001525879" z="1" />
<one:Size width="72.0" height="12.20701217651367" />
<one:OEChildren>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T15:51:43.000Z" lastModifiedTime="2020-12-13T15:51:43.000Z" alignment="left" quickStyleIndex="1">
<one:T><![CDATA[]]></one:T>
</one:OE>
</one:OEChildren>
</one:Outline>
</one:Page>
if this plugin turns out to work it could colorize practically all these languages https://pygments.org/languages/
You should be able to find something similar in C/C++ (a library that does most of the job for you) If not then I can persist in getting this done and submit my first PR However this will get us back to the registering plugin/plugin args under some menu items In this case the menu item will have the name of the language the user wishes to colorize
I think I know where the problem is, I might need to generate inline styles , trying to find out how if it is quick I will do it today if not I will try to do it these days, running out of time here
OK I was able to generate inline styles but no luck with creating a new page I am still getting an error Here is the complete log, maybe you can find the issue
25572:1] Running command RunPluginCommand
25572:1] ..plugin working file is C:\Users\1001QA\AppData\Local\Temp\20962178020110490164320036476241.xml
25572:27] ..running E:\VSCode\pyonemore\.venv\Scripts\python.exe E:\VSCode\pyonemore\pyonemore\onenote_test.py "C:\Users\1001QA\AppData\Local\Temp\20962178020110490164320036476241.xml"
25572:27] ..plugin process started PID:13900
25572:15] ..| Copying C:\Users\1001QA\AppData\Local\Temp\20962178020110490164320036476241.xml
25572:15] ..| Passed text # Python 3 code to find sum
25572:15] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #408080; font-style: italic"># Python 3 code to find sum </span>
25572:15] ..| </pre></div>
25572:15] ..|
25572:15] ..| Passed text for i in arr:
25572:15] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> arr:
25572:15] ..| </pre></div>
25572:15] ..|
25572:15] ..| Passed text sum = sum + i
25572:15] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000">sum</span> <span style="color: #666666">=</span> <span style="color: #008000">sum</span> <span style="color: #666666">+</span> i
25572:15] ..| </pre></div>
25572:15] ..|
25572:15] ..| Passed text return(sum)
25572:23] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000; font-weight: bold">return</span>(<span style="color: #008000">sum</span>)
25572:23] ..| </pre></div>
25572:23] ..|
25572:23] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #408080; font-style: italic"># Python 3 code to find sum </span>
25572:23] ..| </pre></div>
25572:23] ..|
25572:23] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> arr:
25572:23] ..| </pre></div>
25572:23] ..|
25572:23] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000">sum</span> <span style="color: #666666">=</span> <span style="color: #008000">sum</span> <span style="color: #666666">+</span> i
25572:23] ..| </pre></div>
25572:23] ..|
25572:23] ..| <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000; font-weight: bold">return</span>(<span style="color: #008000">sum</span>)
25572:23] ..| </pre></div>
25572:23] ..|
25572:23] ..| True
25572:23] ..| Done
25572:23] ..|
25572:23] ..|
25572:24] ..!
25572:17] ..plugin process exited
25572:1] ..error updating page content
25572:1] ..EXCEPTION - System.Runtime.InteropServices.COMException
Message...: Exception from HRESULT: 0x80042009
StackTrace: at Microsoft.Office.Interop.OneNote.IApplication.UpdatePageContent(String bstrPageChangesXmlIn, DateTime dateExpectedLastModified, XMLSchema xsSchema, Boolean force)
at River.OneMoreAddIn.OneNote.Update(XElement element)
TargetSite: [River.OneMoreAddIn] Microsoft.Office.Interop.OneNote.IApplication::UpdatePageContent()
25572:1] ..<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2013/onenote" ID="{xxxxxx}" name="Lorem Ipsum" dateTime="2020-12-11T21:03:42.000Z" lastModifiedTime="2020-12-13T16:07:12.000Z" pageLevel="1" isCurrentlyViewed="true" selected="partial" lang="en-US">
<one:QuickStyleDef index="0" name="PageTitle" fontColor="automatic" highlightColor="automatic" font="Calibri Light" fontSize="20.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:QuickStyleDef index="1" name="p" fontColor="automatic" highlightColor="automatic" font="Calibri" fontSize="10.0" spaceBefore="0.0" spaceAfter="0.0" />
<one:PageSettings RTL="false" color="automatic">
<one:PageSize>
<one:Automatic />
</one:PageSize>
<one:RuleLines visible="false" />
</one:PageSettings>
<one:Title lang="yo">
<one:OE author="Microsoft account" authorInitials="Ma" authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedBy="Microsoft account" lastModifiedByInitials="Ma" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T06:26:59.000Z" lastModifiedTime="2020-12-13T06:26:59.000Z" alignment="left" quickStyleIndex="0">
<one:T><![CDATA[Lorem Ipsum (2)]]></one:T>
</one:OE>
</one:Title>
<one:Outline selected="partial" author="Microsoft account" authorInitials="Ma" lastModifiedBy="Microsoft account" lastModifiedByInitials="Ma" lastModifiedTime="2020-12-13T15:40:02.000Z">
<one:Position x="36.0" y="86.4000015258789" z="0" />
<one:Size width="156.5809478759765" height="48.82802963256836" />
<one:OEChildren selected="partial">
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #408080; font-style: italic"># Python 3 code to find sum </span>
</pre></div>
]]></one:T>
</one:OE>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> arr:
</pre></div>
]]></one:T>
</one:OE>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000">sum</span> <span style="color: #666666">=</span> <span style="color: #008000">sum</span> <span style="color: #666666">+</span> i
</pre></div>
]]></one:T>
</one:OE>
<one:OE authorResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" lastModifiedByResolutionID="<resolutionId provider="Windows Live" hash="sbFZHWO7HYEIJrCF4+h9og=="><localId cid="a0f36009f81fb3af"/></resolutionId>" creationTime="2020-12-13T13:14:29.000Z" lastModifiedTime="2020-12-13T13:14:29.000Z" alignment="left" quickStyleIndex="1" selected="partial">
<one:T selected="all"><![CDATA[<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span> <span style="color: #008000; font-weight: bold">return</span>(<span style="color: #008000">sum</span>)
</pre></div>
]]></one:T>
</one:OE>
</one:OEChildren>
</one:Outline>
</one:Page>
Thanks for all this and I'm impressed by your perseverance.
Remember I do this as a hobby, mostly to challenge myself with little programming problems. I'm not really interested in incorporating other people's. Also, OneNote is not a programming environment and having syntax highlighting is a first-world problem so I'll keep tweaking my implementation but I'm not trying to replace "real" editors.
I'm sure I can fix the multi-line comments but need a couple of days.
The languages are all extensible, so we can make them as complex as you want - if you want to contribute updates to their definition files.
The 0x80042009 error means that it cannot insert HTML content. OneNote doesn't accept HTML natively. You have DIV tags inside the CDATA. You can only use SPAN
Either generate OneNote schema-compatible XML or try the
OK I am now realizing that I should remove the <div>
tags from that code I an generating
It is interesting because I validated the content and the validation function returned True
Two more questions:
1) Could you please give me an example ( a small XML doc) of what the use of that tag (one:HTMLContent) looks like?
If I pack my html in that tag will your script be able to import it ?
I guess it is something like
<one:HTMLContent><![CDATA[ HTML code here ]] </one:HTMLContent>
2)Is there a doc where I can see all the error codes for OneNote ? Trying to be more self reliant when troubleshooting and not to waste your time :-) I should have looked up the error code but even now I can't find much about it
<one:HTMLBLock>
<one:Data>
<![CDATA[ ... ]]>
</one:Data>
</one:HTMLBlock>
OneNote error codes (and the rest of the API: https://docs.microsoft.com/en-us/office/client-developer/onenote/error-codes-onenote?redirectedfrom=MSDN
Multi-line comments fixed in this release https://github.com/stevencohn/OneMore/releases/tag/3.10.1
Can't test it is not installing properly for me It shows up in addins as enabled but is it not showing on the ribbon bar Enabling and disabling the addon is not solving the issue
I am on Win10x64, OneNote 2013 x86
18120:1] Starting dllhost 18120, en-US/en-US, v3.10.1, OneNote 15.0, Office 15.0 18120:1] ..OnConnection(ConnectionMode:ext_cm_Startup,1) 18120:1] ..OneAddInsUpdate(custom[]:0) 18120:3] ..OnStartupComplete(custom[]:0) 18120:3] ..OneNote backup folder:: C:\Users\1001QA\AppData\Local\Microsoft\OneNote\15.0\Backup 18120:3] ..OneNote default folder: C:\Users\1001QA\Documents\OneNote Notebooks 18120:3] ..OneNote unfiled folder: C:\Users\1001QA\Documents\OneNote Notebooks\My Notebook\Quick Notes.one 18120:3] OnBeginShutdown(0) 18120:3] ..shutting down UI 18120:3] ..OnDisconnection(RemoveMode:ext_dm_HostShutdown,0) 18120:3] ..closing log
27516:1] Starting dllhost 27516, en-US/en-US, v3.10.1, OneNote 15.0, Office 15.0 27516:1] ..OnConnection(ConnectionMode:ext_cm_Startup,1) 27516:1] ..OneAddInsUpdate(custom[]:0) 27516:3] ..OnStartupComplete(custom[]:0) 27516:3] ..OneNote backup folder:: C:\Users\1001QA\AppData\Local\Microsoft\OneNote\15.0\Backup 27516:3] ..OneNote default folder: C:\Users\1001QA\Documents\OneNote Notebooks 27516:3] ..OneNote unfiled folder: C:\Users\1001QA\Documents\OneNote Notebooks\My Notebook\Quick Notes.one
Closing this one because I think it's fixed. If there are other issues, please open new tickets
Describe the bug The Python syntax colorizer does not do it properly with triples
To Reproduce Paste this code and watch what what is happening with the triple quoted script
Expected behavior the entire script should be colorized but it is not