Forum Discussion

alex-franco's avatar
alex-franco
Brass 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! 

27 Replies

  • 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.
  • 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.

  • 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....

  • gkbrenne's avatar
    gkbrenne
    Copper Contributor
    I just tried "OneMore" by Steven Cohn and I'm impressed: https://onemoreaddin.com/get-started/Welcome%20to%20OneMore.htm. This works with OneNote 365 v2306 build 16529.20182

    You might also try NoteHightlights 2016 by Elvir Brkić at https://github.com/elvirbrk/NoteHighlight2016
  • 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.
    • hifeinstein's avatar
      hifeinstein
      Copper Contributor

      If you want the code to visually look like an isolated code block in-line with other notes in the same text box, select the pasted code and insert a 1x1 table.  Clunky, yes but it’s a decent workaround for isolating code blocks similar to how other note taking apps do it.  Add shading and it really pops. 

      • bbetnar's avatar
        bbetnar
        Copper Contributor

        The 1x1 table is actually a genius workaround. Extremely quick and simple. Clever thinking. Thanks!