Danbooru

DText [code] tag misidentifying whether it is supposed to be inline or block

Posted under Bugs & Features

DText's [code] tag can be used in two ways. Inline code looks like this. It is translated to the <code> tag in HTML, and as such, it ignores both linebreaks and duplicated spaces. Quote this post to see how I typed it up.
(Interestingly, DText doesn't ignore
linebreaks in text outside [code] tags, although it does ignore duplicated spaces.)

Block looks like this, and  translates to HTML's <pre> tag,         preserving 
all      whitespace.

Apparently, a [code] tag is considered inline iff it is immediately preceded on its line by another inline-type element. This includes unformatted text,

but not things like

quote blocks,
opening tags of quote blocks,
or other
code blocks.

However,

the [code] tag seems to include the PREVIOUS line as part of its own
for
the
purpose
of
determining
whether
it
should
be
inline
or
block.

If the previous line ends with an inline-type element, the [code] block displays inline even if it is the only thing on its line. That does not seem like intended behavior. If not, consider this a bug report; if in fact so, consider this a tweak request: please let code tags be treated as inline only if they have inline elements on their own lines. The current behavior is highly counterintuitive, and I must have spent thirty minutes figuring out what the heck was wrong with the markup in another OP I was writing before I figured it out and felt compelled to drop what I was doing and make this thread instead.

It would also be nice

if it were possible to start a line with an inline quote without exploiting the above-described behavior, but that seems less important because it doesn't seem like quite as much of a gotcha.

Lefkadios said:

...

1. It's not Dtext that is removing duplicate spaces and linebreaks, it's HTML.

If you look at the HTML, you'll see:

<code>
Inline code looks like this. It is translated to the &lt;code&gt; tag in HTML, and as such, it ignores both
linebreaks and               duplicated spaces.
                 Quote     this             
                  post     to                                                                                             see  
        how    I                                                                                       typed         
 it
                                                                                                                                               
up.
<​/code>

When formatted inline, it uses <code> elements which do not preserve whitespace, and when formatted as a block it uses <pre> elements which do. Additionally, when in [code] inline mode, the Dtext transpiler does not convert linebreaks into <br> elements, so they get treated like any other HTML linebreak, namely they get squashed into the rest of the whitespace.

2. It's considered bad formatting to have anything other than a DText block tag on it's own line.

In fact, I frequently use extra linebreaks around my block tags just to be sure. Anything else is really not supported, including unintended effects from not following this. This'll be covered more in #4 below.

3. Quote blocks are stripped out when quoting another forum post and on comments.

To get the original they'll have to check out the JSON.

https://danbooru.donmai.us/forum_posts/182687.json

The linebreaks are encoded in this format though.

4. It would be very difficult to make [code] blocks that begin on a line be inline.

Because they can be both inline and block tags. As such, the only way the transpiler can really tell the difference between the two is when the transpiler is still in inline mode (making it an inline tag) versus in the main mode (making it a block tag). As such, it always takes two consecutive linebreaks to break the transpiler out of inline mode and put in in main mode, which is why anything on the preceding line will make it still be treated as inline.

So yes, it may be a little "hacky" or whatever, but one would need to put spaces or something on the previous line to get a [code] tag to act like an inline tag. If that causes one too much heartburn, then they can always start a line with a zero-width space, which will cause the same effect.

2. It's considered bad formatting to have anything other than a DText block tag on it's own line.

This is news to me! Is that written down somewhere?

As such, it always takes two consecutive linebreaks to break the transpiler out of inline mode and put in in main mode

Ah, I see—a single DText linebreak translates to an HTML linebreak, but a double linebreak ends the paragraph. That makes sense, but it's also news to me.

I guess the only problem here is with the documentation (or with the accessibility of the documentation).

1