stevencohn / OneMore

A OneNote add-in with simple, yet powerful and useful features
Mozilla Public License 2.0
2.55k stars 214 forks source link

The colorizer for XML and HTML breaks the lines #125

Closed 1001QAdotNET closed 3 years ago

1001QAdotNET commented 3 years ago

Describe the bug The colorizer for XML and HTML breaks the lines

To Reproduce try to apply the XML colorizer to this code

<one:OE alignment="left" quickStyleIndex="1" selected="partial">
                <one:T selected="all"><![CDATA[<span style='color:blue'>&lt;?</span><span style='color:#A31515'>xml</span> version=&quot;1.0&quot; <span style='color:red'>encoding</span><span style='color:blue'>=</span><span style='color:black'>&quot;</span><span style='color:blue'>UTF-8</span><span style='color:black'>&quot;</span><span style='color:blue'>?&gt;</span> <span style='color:blue'>&lt;</span><span style='color:#A31515'>hello</span> <span style='color:red'>xmlns</span><span style='color:blue'>=</span><span style='color:black'>&quot;</span><span style='color:blue'>urn:ietf:params:xml:ns:netconf:base:1.0</span><span style='color:black'>&quot;</span><span style='color:blue'>&gt;</span> <span style='color:blue'>&lt;</span><span style='color:#A31515'>capabilities</span><span style='color:blue'>&gt;</span> <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:base:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:base:1.1&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:writable-running:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:xpath:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:validate:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:validate:1.1&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:rollback-on-error:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:notification:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:interleave:1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:with-defaults:1.0?basic-mode=explicit<span style='color:red'>&amp;amp;</span>also-supported=report-all-tagged&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>urn:ietf:params:netconf:capability:yang-library:1.0?revision=2016-06-21<span style='color:red'>&amp;amp;</span>module-set-id=7294e20b121b24ac71a8fb609b7d3afd&lt;/<span style='color:#A31515'>capability</span>&gt; <span style='color:blue'>&lt;</span><span style='color:#A31515'>capability</span><span style='color:blue'>&gt;</span>http://tail-f.com/ns/netconf/actions/1.0&lt;/<span style='color:#A31515'>capability</span>&gt; <br>
]]></one:T>

see the picture

Expected behavior the tags <capability> should stay at the beginning of the line

Screenshots colorizer breaks the alignment

stevencohn commented 3 years ago

I can't really see it correctly, if I copy/paste the snippet you have, it's just one big line of text. If I pull it into N++ and format it as XML then copy to OneNote it works just fine. I suspect there's a newline in there but not a proper line break tag. That's one of the weird cases where OneNote takes over and OneMore doesn't necessarily have much control (remember we struggled with this same kind of issue in another ticket)

So my suggestion is to make sure there are no soft-break (Shift-Enter) and if there are then replace them with hard-breaks (Enter)

stevencohn commented 3 years ago

I'm guessing your plugin is inserting into the CDATA by your own plugin? I can't presume to replace newlines with BR tags or split them across separate OE elements because that won't always be correct. So make sure your plugin does what it can to format the input so OneNote can maintain it properly.

1001QAdotNET commented 3 years ago

No that is copy and pasted text I managed to get my plugin working with python Trying the XML next

1001QAdotNET commented 3 years ago

Try this one

<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2013/onenote" ID="{xxxxxxxxxxxxxxxx}" name="XML Colorizer" dateTime="2020-12-16T22:57:04.000Z" lastModifiedTime="2020-12-16T22:58:29.000Z" pageLevel="1" isCurrentlyViewed="true" selected="partial" lang="yo">
  <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="11.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="en-US">
    <one:OE alignment="left" quickStyleIndex="0">
      <one:T><![CDATA[XML Colorizer]]></one:T>
    </one:OE>
  </one:Title>
  <one:Outline selected="partial">
    <one:Position x="36.0" y="86.4000015258789" z="0" />
    <one:Size width="540.0" height="107.4217224121094" />
    <one:OEChildren selected="partial">
      <one:OE alignment="left" quickStyleIndex="1">
        <one:T><![CDATA[&lt;?xml version=&quot;1.0&quot;?&gt; <br>
&lt;hello xmlns=&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot;&gt; <br>
  &lt;capabilities&gt;   <br>
    &lt;capability&gt;urn:ietf:params:xml:ns:netconf:base:1.0&lt;/capability&gt;   <br>
  &lt;/capabilities&gt;   <br>
&lt;/hello&gt;]]&gt;]]&gt;]]></one:T>
      </one:OE>
      <one:OE alignment="left" quickStyleIndex="1" lang="en-US">
        <one:T><![CDATA[]]></one:T>
      </one:OE>
      <one:OE alignment="left" quickStyleIndex="1" selected="partial" lang="en-US">
        <one:T selected="all"><![CDATA[]]></one:T>
      </one:OE>
    </one:OEChildren>
  </one:Outline>
</one:Page>
stevencohn commented 3 years ago

got it. OK I'll see what I can do.

stevencohn commented 3 years ago

Good catch, thanks. Will be in the next release

1001QAdotNET commented 3 years ago

this is how close I can get image

Need I need to eliminate the line breaks and the quotes probably pygments has a switch for that as it was the case for the

that were breaking the Python plugin

1001QAdotNET commented 3 years ago

Done; I guess I won't use it after you finish the integrated one Going forward if any other language is needed I guess I can easily complement what you wrote colorizer -MYPLUGIN

stevencohn commented 3 years ago
1001QAdotNET commented 3 years ago

Works nnow, your color scheme is better , thank you