Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Behind the Scenes
  3. Qt.io webservices
  4. Marking code blocks

Marking code blocks

Scheduled Pinned Locked Moved Qt.io webservices
markdown tagscode blocks
7 Posts 5 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    @SGaist @sierdzio
    As of the discussion here

    i was not aware that there is an alternative for code blocks
    Blocks of code are either fenced by lines with three back-ticks ```, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.

    This has a couple of aspects:

    1. Some keyboards do not support backticks directly, since users complaint about the difficulty to get the backtick.
    2. Backticks seem to lead to syntax highlighting, the question is how to get to work. Apparently, it is currently not working.
    3. The alternative would be easier to support for everybody, since every keyboard supports spaces
    4. The four spaces are really a pain when copy and pasting code sections into the forum. However, assuming a general indation of 4 spaces might be used by many, that may not be to bad.
    5. Problems are with sections when the four spaces are not used, yet. Don't believe that everyone will add the four spaces over blocks.
    6. Well, moderators not add four spaces, because this takes more time than simply adding backticks.

    In my opinion a single way should be proposed and used.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2
      1. Even if you don't have a backtick key directly on your keyboard you can still use the alt codes (hold left ALT key and enter 96 on the numeric keyboard block). Yup, you can do that with pretty much any character too.
      2. It works fine and I use it all the time:

      Using ```cpp

      //I'm a c++ code!
      if(foo)
         std::cout<< "bar";
      

      using ```python

      #I'm a python code!
      if foo
         print "bar"
      
      1. Spaces are bad idea in my opinion. People use different number of them, It's not easy to paste code from somewhere where they were not used. It's not easy to apply them to multiple lines at once. They are terrible for stuff like forum migration. They are not intuitive at all.
      2. Agree.
      3. Also it makes the code copy-pastable as a block. You don't have to edit these spaces every time you paste it somewhere. In general it's a better solution to surround code with something than to edit every single line of it.

      I would stick with surrounding code with backticks or use some other character, more widely present.
      The best, I think, would be if there was simply a button on the posting toolbar that would do that for you i.e. you write some code, select it and hit the button. This would also make this more accessible to people without backticks on their keyboards and to people that don't know the syntax (or are to lazy to read the big fat help text).

      K 1 Reply Last reply
      2
      • Chris KawaC Chris Kawa
        1. Even if you don't have a backtick key directly on your keyboard you can still use the alt codes (hold left ALT key and enter 96 on the numeric keyboard block). Yup, you can do that with pretty much any character too.
        2. It works fine and I use it all the time:

        Using ```cpp

        //I'm a c++ code!
        if(foo)
           std::cout<< "bar";
        

        using ```python

        #I'm a python code!
        if foo
           print "bar"
        
        1. Spaces are bad idea in my opinion. People use different number of them, It's not easy to paste code from somewhere where they were not used. It's not easy to apply them to multiple lines at once. They are terrible for stuff like forum migration. They are not intuitive at all.
        2. Agree.
        3. Also it makes the code copy-pastable as a block. You don't have to edit these spaces every time you paste it somewhere. In general it's a better solution to surround code with something than to edit every single line of it.

        I would stick with surrounding code with backticks or use some other character, more widely present.
        The best, I think, would be if there was simply a button on the posting toolbar that would do that for you i.e. you write some code, select it and hit the button. This would also make this more accessible to people without backticks on their keyboards and to people that don't know the syntax (or are to lazy to read the big fat help text).

        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @Chris-Kawa
        Basically you do not have to use the alt codes which is for some also a bit cumbersome.
        Since the markdown tags and especially the backticks are given at the end of the thread section (not sure if this is true for new posts), you can simply mark them and use copy and paste to introduce them where required.

        @Chris-Kawa said:

        Using ```cpp

        I have tried, but it did not show a difference. Anyway I will keep in mind.

        AFAIK the button solution is not easy to implement, but it would be certainly preferrable.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Use ```cpp before and ``` after the block.
          Eg.
          ```cpp
          if(foo) bar();
          ```
          will result in

          if(foo) bar();
          
          M 1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            I concur with @Chris-Kawa on all points.

            For me a formatting button is clearly missing, however I don't know what it would take to add it.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              I concur with @Chris-Kawa on all points.

              For me a formatting button is clearly missing, however I don't know what it would take to add it.

              A Offline
              A Offline
              Asperamanca
              wrote on last edited by Asperamanca
              #6

              @SGaist said:

              Hi,

              I concur with @Chris-Kawa on all points.

              For me a formatting button is clearly missing, however I don't know what it would take to add it.

              I agree. In a forum discussing aspects of programming, inserting a block of code should be as simple as possible.

              1 Reply Last reply
              1
              • Chris KawaC Chris Kawa

                Use ```cpp before and ``` after the block.
                Eg.
                ```cpp
                if(foo) bar();
                ```
                will result in

                if(foo) bar();
                
                M Offline
                M Offline
                mikag
                wrote on last edited by
                #7

                @Chris-Kawa Sadly the cpp syntax highlighting is obviously broken on qt.io
                Looking at the C++ sample at highlightjs.org we see it's not close to working here. What we urgently need is a default Qt code customized highlight mode for these forums. Like they have over at qtcentre.org reading Qt code is so much easier over there.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved