I do not know if this has already been adressed or if it just me, but I find the insertion of code into a post in a proper manner using the current method to be quite convoluted.

Honestly, I believe it is a malformed feature and could be made and implemented so much easier.

I dread every time I need to post code here - It seems like a hassle and half of the time it never works for me correctly.

Maybe someone can comment on this and point out the best way to go about it - At this point it seems to be a two-step process. That should not be.

Just my opinion.

Thank you,
Matthew

Recommended Answers

All 3 Replies

To paste code I usually place the cursor in a new line and then I press TAB once, for example:

/**
 * Sign Out
 * @return void
 */
public function getOut()
{
    Auth::logout();
    return Redirect::route('sign_in');
}

Usually, it does not require any other adjustment because, in my editor, I always indent the code. Otherwise you have to select the pasted code and press TAB. By pressing Shift Tab, instead, you remove one tab space. So you can adjust the code block as you like. Hope it helps, bye!

Let's try cereal's technique

def paire(x):
    return sqrt(-x**2+3*x+4), abs(x-2)

for x in (-0.5, 1, 3.7):
    print x, paire(x)

In kubuntu, I selected code in an editor with ^c, then pasted it in daniweb's editor with ^v, then selected it with a mouse and pressed TAB. It works, but I'd like a way to select several lines without the mouse. For example in the Kate editor, SHIFT+DOWN ARROW selects groups of lines.

There are three easy ways.

  1. Click the Code tool. This will open a window where you can paste your code. When you click Insert code snippet or press ALT-I, the code will be inserted into your post.

  2. Paste the code directly into your post. If you do it this way remember to leave one blank line above and below the code. You can select one or more lines and press Tab or Shift-Tab to indent or undent the selected block. Note that you don't have to select an entire line to do this. For single lines you can place the text cursor anywhere in the line and indent/undent the same way.

  3. For inline code mixed with non-code you can just select the code and click Inline Code. This will cause the selected text to be rendered in a different font and colour to distinguish it from the non-code.

This is an example x = y * 15 of inline code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.