2

Recently I posted an answer including source code with a method I regularly used here and on web pages:

Corruptions within Calendar: duplicates. How to analyse their cause and fix?

My (stackexchange) source (of this source code) is:

    <pre>
    $ cat <<'eof' >duplicate.pl
    #!/usr/bin/perl
    </pre>

and the result obtained, is:

    $ cat duplicate.pl
    #!/usr/bin/perl

Which is wrong in term of displayed text and in term of working answer, since the shell script is not working. I'm not able to present the problem here through the use of <pre> and used a lot of return and spaces to achieve a presentable explanation.


What is the easiest way to insert source code with just one enclosing markup?

What did I do wrong to not being able to get a correct behaviour of a basic <pre> markup?

1

Let me try :-)

$ cat <<'eof' >duplicate.pl
#!/usr/bin/perl

Ok so far? Or is there any special meaning of using <pre> tags?

The easiest way to format larger blocks of code is to just paste the code into the edit window, select the whole code block and the click on the code formatter ({}) at the top of the edit window.

See also the help pages on supported markdown formatting (especially the second screenshot below) and this question on the main meta site:

enter image description here

enter image description here

  • "Is there any special meaning of using <pre> tags?" Yes. It's pretty simple and standard. For me I nearly type it automatically when including code. Hence I never imagined I would need any button to perform such a basic markup.(missing return) To give you an example in another field which is boring me to great deepths, I would never look for a button which would permit me to put a [return] :). – dan Sep 28 '15 at 14:14
  • You don't need to use the button, you can just prepend 4 space characters on every line. But for long blocks of code, using the button may be easier, especially if you paste whole scripts into the edit window. – nohillside Sep 28 '15 at 14:26
  • I don't like the prepend trick: too slow, and too error prone. Honestly I don't find anything simpler than a plain <pre></pre> :(. – dan Sep 28 '15 at 14:31
  • Let me try to formulate my thoughts it in a way to make something useful: would it be possible, easy, to make standard <pre></pre> or <code>...</code> work? – dan Sep 28 '15 at 14:35
  • I'm not a developer here :-) To make a feature request, you can always ask a new meta question, describe the functionality you are missing and add the feature-request tag. Might take a few days till somebody from the SE team answers. – nohillside Sep 28 '15 at 14:41
  • 1
    For this one I would also search meta.stackexchange and meta.stackoverflow You won't have been the first to see this – user151019 Sep 28 '15 at 17:17
0

Am I missing something, or is

enter image description here

not just the same as selecting the block & hitting Cmd ⌘ K ?

Prior to discovering that I used to add extra indents in a text editor & paste it over, which was a tad irritating...


Unformatted

$ cat <<'eof' >duplicate.pl

!/usr/bin/perl

Using <pre> </pre>

$ cat duplicate.pl
#!/usr/bin/perl

Using Cmd ⌘ K

$ cat <<'eof' >duplicate.pl
#!/usr/bin/perl

Using {}

$ cat <<'eof' >duplicate.pl
#!/usr/bin/perl

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .