Code blocks seem to work differently in Discourse than does in phpbb

I’m going over a long thread I started when I was about to release Library 6/12 (Inform Library 6/12 and Inform 6.33.1 for Unix go beta) and found that Discourse doesn’t seem to like code blocks that are like this:

In english.h, you use (nop) instead of (string), in this case (only string), has it an interest?

[ nop x; x = x; ]; ! print rule to absorb unwanted return value [ SupportObj obj s1 s2; if (obj has supporter) print (string) s1; else print (string) s2; ]; [ PluralObj obj s1 s2 past; if (player.narrative_tense == PAST_TENSE) { print (string) past; return; } if (obj has pluralname) print (string) s1; else print (string) s2; ]; "(getting ", (nop) SupportObj(x1,"off","out of"), (the) x1, ")"; CSubjectCant(actor,true); " since ", (the) x1, " ", (nop) PluralObj(x1,"lead","leads","led"), "nowhere.";[ SupportObj obj s1 s2; if (obj has supporter) return s1; return s2; ]; [ PluralObj obj s1 s2 past; if (player.narrative_tense == PAST_TENSE) return past; if (obj has pluralname) return s1; return s2; ]; "(getting ", (string) SupportObj(x1,"off","out of"), (the) x1, ")"; CSubjectCant(actor,true); " since ", (the) x1, " ", (string) PluralObj(x1,"lead","leads","led"), "nowhere.";

But if I put a blank line above the opening code tag and then a newline before beginning the actual quote code, it looks okay.

In english.h, you use (nop) instead of (string), in this case (only string), has it an interest?

[ nop x; x = x; ];      ! print rule to absorb unwanted return value
[ SupportObj obj s1 s2;
    if (obj has supporter)          print (string) s1;
    else                            print (string) s2;
];
[ PluralObj obj s1 s2 past;
    if (player.narrative_tense == PAST_TENSE) {
        print (string) past;
        return;
    }
    if (obj has pluralname)         print (string) s1;
    else                            print (string) s2;
];
"(getting ", (nop) SupportObj(x1,"off","out of"), (the) x1, ")";
CSubjectCant(actor,true); " since ", (the) x1, " ", (nop) PluralObj(x1,"lead","leads","led"), "nowhere.";

This chunk is proving a bit more obstinate:

[ SupportObj obj s1 s2; if (obj has supporter) return s1; return s2; ]; [ PluralObj obj s1 s2 past; if (player.narrative_tense == PAST_TENSE) return past; if (obj has pluralname) return s1; return s2; ]; "(getting ", (string) SupportObj(x1,"off","out of"), (the) x1, ")"; CSubjectCant(actor,true); " since ", (the) x1, " ", (string) PluralObj(x1,"lead","leads","led"), "nowhere.";

[ SupportObj obj s1 s2; if (obj has supporter) return s1; return s2; ]; [ PluralObj obj s1 s2 past; if (player.narrative_tense == PAST_TENSE) return past; if (obj has pluralname) return s1; return s2; ]; "(getting ", (string) SupportObj(x1,"off","out of"), (the) x1, ")"; CSubjectCant(actor,true); " since ", (the) x1, " ", (string) PluralObj(x1,"lead","leads","led"), "nowhere.";

I got this one to work by adding a carriage return and open/close brackets on a newline at the end, now it’s a copyable code block. Then I took them out and it remained formatted correctly. The copy block seems to be looking for more than one line of text. Maybe just add a \ or a # - whichever is a nondestructive comment? - after a CR in your code example on a new line and delete it? (or leave it in as a comment)

Discourse’s handling of BBCode is a little bit different, but if you put the [code] on a line by itself, with blank lines before it and after the closing [/code], it should work fine.

But you can also use Github style Markdown, with three backticks:

```
Test
```

Produces

Test

Lastly, indenting with four spaces also does a code block.

Test

I like the triple backtick option most, but YMMV.

3 Likes
[ SupportObj obj s1 s2; if (obj has supporter) return s1; return s2; ]; [ PluralObj obj s1 s2 past; if (player.narrative_tense == PAST_TENSE) return past; if (obj has pluralname) return s1; return s2; ]; "(getting ", (string) SupportObj(x1,"off","out of"), (the) x1, ")"; CSubjectCant(actor,true); " since ", (the) x1, " ", (string) PluralObj(x1,"lead","leads","led"), "nowhere.";

Yep, just testing and Dannii’s method works. I suppose the preformat format is assuming if you’re highlighting just one word or one line you want it inline and not a full block of text.

I’ve usually been pasting in the code, highlighting, and hitting the code button–this seems to make it hardest for me to mess it up.