Formatting Code Blocks in this Forum

Following @ipsors post:

http://forums.sqlteam.com/t/stored-proc-with-select-statement-sometimes-returns-the-value/3083/10

I thought it might be helpful to pool any knowledge about how to format posts

Amen to that. I absolutely hate the MarkDown used in this forum. It frequently screws up my post - e.g. completely hiding a whole block of code, or accidentally formatting something I didn't intend to, or leaving a character out.

I would much prefer a mark-up syntax where I am in complete control of the formatting. For example, I have found absolutely no way of highlighting a snippet in a code block, and I see others, too, resorting to "--<<< HERE" comments in the code to try to indicate where they have made a one word / one letter change. The fact that so little first-time-post questions include any code-block markers suggests to me that 99% of the world don't "get" this mark-down stuff (even though it is defacto on StackOverflow - maybe everything is neatly formatted there because of the huge number of Code Tsars who spend their life editing other people's posts to "fix them" ...)

Send me your unformatted code, I'll format it for you, because I have nothing better to do!! (Also fits in nicely with "Doing it Kristen's way" :smiley: )

Amen!

Here's what little I have found

    ```
    Start / End of a code block. Parsers auto-detects the language
    Sometime screws up royally ... it can help to have a blank line before and/or after the ''' lines

    '''text
    Start of a Text block (end with regular ''', do not end with '''text, cannot use '''TEXT )

    '''xxx
    Other languages - such as "sql" and "C" (that one does work in uppercase)
    Sometimes necessary to use ```sql where parser does not auto-detect correctly
    Note that the Preview is Javascript whereas the actual render is something-else, so sometimes they do different things
    [code]
    [/code]
    Sort of works. All blank lines within the code block are suppressed, which screws up the formatting

Then there is the 4-leading-spaces thing, which is what you get if you highlight a block and press the [</>] button. And is also what you get on PART of someone's code that is indented with spaces

    SELECT [Foo] = ThisIsAVeryLongColumnName

What happened to the colour formatting there then?

THere's another example (except I can't find it just now ...) where the first ' was not recognised as a String, so everything after that was wrongly formatted. I couldn't find any way to fix that, so I had to post it as text rather than sql :frowning:

I haven't found a way to boldface something in the middle of a word? like this aaaBccc

And so on ...

1 Like

So how does this work ? We just post our unformatted code and then just mention @Kristen in the post, and with a flash you will format it ? :grin:

1 Like

lol :grinning: :grinning: :grinning:

Not sure about that bit !!!!

Found the one where the quotes did not balance:

-- Tried formatting with both ``` and '''sql <<< SEE NEXT POST!!

EXEC sp_ExecuteSQL 
   'SELECT Col1, Col2, ...
    FROM MyTabl
    WHERE Col3 = @Col3Value'
    , '@Col3Value varchar(10)'
    , @Col3Value = 'ABC123'
AS

I can get it to work if I add a comment, at Line 1, of -- ''' xxx ''' - but of course the quotes in a comment should not influence the presentation at all ...

its eaten two of my single quotes in

(-- Tried formatting with both ''' and '''sql )

No, that escaping didn't work either, whereas I have been able to use a backslash-escape in other places. I have no idea how to put a triple-single-quote within the regular text flow ... but backslash-escaping works in other instances, like this:

This is \*not\* italic

gives:
This is *not* italic

which means, of course, that "" can be unexpectedly swallowed, in particular where people post code without suitable markings to indicate a code-block.

Hang the markup coders!

==8-)