Marking code blocks
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:
- Some keyboards do not support backticks directly, since users complaint about the difficulty to get the backtick.
- Backticks seem to lead to syntax highlighting, the question is how to get to work. Apparently, it is currently not working.
- The alternative would be easier to support for everybody, since every keyboard supports spaces
- 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.
- Problems are with sections when the four spaces are not used, yet. Don't believe that everyone will add the four spaces over blocks.
- 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.
- 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.
- It works fine and I use it all the time:
//I'm a c++ code! if(foo) std::cout<< "bar";
#I'm a python code! if foo print "bar"
- 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.
- 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).
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.
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.
```after the block.
will result in
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.
@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.