Forum Discussion

alex-franco's avatar
alex-franco
Copper Contributor
Jun 22, 2021

OneNote - Inserting Code Blocks

Are there any plans for a way to format code blocks in OneNote without inserting a 1 column/row table or an ugly print out? The most relevant Google search brings up a post from 2018 where the top answer says its been requested on UserVoice and directs OP there, but 3 years later, still no code block formatting options and Microsoft isn't using UserVoice anymore so I don't where else I can submit feature requests besides this discussion board. 

 

Thanks! 

  • marcvanbreemen's avatar
    marcvanbreemen
    Copper Contributor
    For now you can do this:

    Paste your code in Visual Code. Be sure that the language is supported and/or install support for it first (extension). Your code will be color coded.

    Then copy/paste ("with format" option) that in OneNote.
  • nclinch's avatar
    nclinch
    Iron Contributor
    Makes me sad. I would like to have a OneNote for all of our IT documents/Notes and most of the time there is code involved.
    I can insert Code into Teams... why not OneNote
    • WOS-MAnthony's avatar
      WOS-MAnthony
      Copper Contributor

      nclinch, check this out:

       

      Mac:  Format > Styles > Code
      Windows:  Ribbon > Styles > Code

       

      It's not perfect but it does seemingly remove unnecessary formatting and allow you to paste in and format code blocks.

      • JediSQL47's avatar
        JediSQL47
        Copper Contributor
        Thank you. That does work for a quick and dirty. We'll still need to do the via-Word method if we want to retain the syntax color highlighting. Also, Styles > Code is a paragraph style, so you can't style just a few words within a sentence. I tried via-Word for inline code, and it doesn't work well either.
  • THaha2050's avatar
    THaha2050
    Copper Contributor

    alex-franco when I google the exactly the same question, microsoft community hub is the first one in the google search results, the answer provided is 2 years old and absolutely useless....

  • JediSQL47's avatar
    JediSQL47
    Copper Contributor

    Just copy/paste the code to MS Word first. The re-copy the code from Word and paste it to OneNote with "keep source formatting." I have been using this in SharePoint wikis also.

      • JediSQL47's avatar
        JediSQL47
        Copper Contributor

        Charlotte18241 ,

        Thank you for the update. I can confirm the Loop component in the web version and that they cannot be added via the desktop version. When I add via web, and then view the page with the desktop app, I get this:

  • Dantoys's avatar
    Dantoys
    Copper Contributor

    alex-franco The Loop Components feature seems very poorly executed, why does it need to spend 20 seconds online to access the note, another MS attempt to steal our information?

     

    I really like the way this works in cherrytree, I wish it was the same in microsoft. as for installing another program like visual studio, no thank-you. I don't need that beast. I'm not a developer, just need to keep notes on the coding I can do inside some software. If MS ever reads this, please look at other software, and try to make your software more friendly. It was a mission in Microsoft in the early years to make thinks easy to use, now a days it seems they want to make things more difficult. I'm unfortunately stuck with whats available, due to security in my organization. if I get desperate, I can maybe email it to myself, and code fomat/style it on my home computer, and email it back to myself. Why should anyone have to do this? computers are ment to make my job easier not harder, and yet, it just keeps getting harder.. Why M$, Why ??

Resources