Backtickify code snippets on Stack Exchange Your goal is to input any arbitrary text, such as:

This is some text


And output that text formatted as code for posts (SE-flavored Markdown) and comments (mini-Markdown) on Stack Exchange, such as:

`This is some text`
`This is some text`


However, it gets trickier. Consider the input:

Perl has a variable called $`


The output must be

`` Perl has a variable called $` ``
`Perl has a varaible called $\``


The full rules for the formatting are:


Full posts (full SE Markdown)


Step 1: count the least number for which there are not exactly that many consecutive backticks in the string. Let's call this n. (For example, for the string potato, n is 1, for this is a backtick: `, n is 2, and for ` `` ``` ````` ``````, n is 4.)
Step 2: wrap the string in n backticks. If the string starts or ends with a backtick, you must wrap with spaces as well. (For example, potato becomes `potato`, this is a backtick: ` becomes `` this is a backtick: ` ``, and ` `` ``` ````` `````` becomes ```` ` `` ``` ````` `````` ````.

Comments (mini-Markdown)


Wrap in ` and escape all `'s with \`. (For example, potato becomes `potato`, this is a backtick: ` becomes this is a backtick: \`, and ` `` ``` ````` `````` becomes \` \`\` \`\`\` \`\`\`\`\` \`\`\`\`\`\`.



This is code-golf; the shortest answer in byte count wins.
APL (90)

(Yes, the APL charset does fit in a byte, here's IBM's codepage 907.)

{⎕ML←3⋄(,/m,m,⍨{⍵=m:'\`'⋄⍵}¨⍵),⊂(⌽g),⍵,g←(''↑⍨∨/t[1,⍴t]),m/⍨0⍳⍨z∊⍨⍳⌈/0,z←,⊃⍴¨⍵⊂⍨t←⍵=m←'`'}


This is a function that takes a string, and returns an array of two strings, where the first string is the comment representation and the second string is the full post representation.

Tests:

      backtickify←{⎕ML←3⋄(,/m,m,⍨{⍵=m:'\`'⋄⍵}¨⍵),⊂(⌽g),⍵,g←(''↑⍨∨/t[1,⍴t]),m/⍨0⍳⍨z∊⍨⍳⌈/0,z←,⊃⍴¨⍵⊂⍨t←⍵=m←'`'}
      ↑backtickify 'potato'
`potato`
`potato`

      ↑backtickify 'this is a backtick: `'
`this is a backtick: \``   
`` this is a backtick: ` ``

      ↑backtickify '` `` ``` ````` ``````'
`\` \`\` \`\`\` \`\`\`\`\` \`\`\`\`\`\``
```` ` `` ``` ````` `````` ````  

      ⍝ testcase for not wrapping with spaces
      ↑backtickify 'no`spaces``at````the`edges'
`no\`spaces\`\`at\`\`\`\`the\`edges`
```no`spaces``at````the`edges``` 


Note: I gave the function a name for readability's sake, this is not strictly necessary to use it (you can just put the argument next to the anonymous function) so I didn't count it.