Replacement for [tt] tag

Started by _Jojo_, January 11, 2023, 04:32:41 AM

Previous topic - Next topic

_Jojo_

In SMF 1.1 and 2.0, [tt] was a great way for discussing inline code snippets, similar to how single backticks are used in Markdown. This tag was moved to legacy tags in SMF 2.1 and I cannot find an adequate replacement. In particular, using a font tag to change the font to Courier or whatever is simply not semantically equivalent, and I don't want people to use arbitrary fonts in their posts to begin with (so that tag is usually disabled on my forums). Is there an easy way to bring back [tt] or something equivalent in SMF 2.1? [code\] and [pre\] are really not an adequate replacement as they are not inline.

Aleksi "Lex" Kilpinen

You could perhaps use sub or sup, they do make the text a bit smaller but should differentiate from normal text body clearly enough. Or in case of php, you can use php <?php echo "Hello world!"?>
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

_Jojo_

Neither of those workarounds are acceptable unfortunately - it's not just about making the text look "a bit different", code needs to be presented in monospace fonts, and optimally using a HTML tag that is semantically useful to screenreaders for blind people (in HTML5, one would use the <samp> tag instead of the legacy <tt> tag for this particular case), and in my case the code is also never going to be PHP code, so the syntax coloring of the php tag would just be confusing.

Aleksi "Lex" Kilpinen

With those requirements in mind, you would probably be best off with a custom BBC, perhaps adapt an existing mod that adds a single BBC, or check out if something like Custom BBCodes Manager would work for you (I'm not sure if it's actually compatible with current 2.1 though, sorry.)
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Sesquipedalian

You could just go to this line in Load.php and remove 'tt' from the $context['legacy_bbc'] list.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

_Jojo_

As I don't really have any experience in SMF mods, would it be possible to write a hooks-only mod that does that, or do I have to do it the old-fashioned way with search & replace?

Steve

Wouldn't what Ses said be easier?

Quote from: Sesquipedalian on January 11, 2023, 12:09:01 PMYou could just go to this line in Load.php and remove 'tt' from the $context['legacy_bbc'] list.
DO NOT pm me for support unless asked to!

_Jojo_

Well, I wouldn't really call it a solution to apply that manually. A temporary band-aid, yes, but not something that I can reliably apply to several forums and that would survive a full forum upgrade. I was hoping for a bit more durable solution.

Sesquipedalian

You could certainly write a hooks-only mod to do that. Just hook into integrate_pre_load and edit the $context['legacy_bbc'] array.

Also, if you want to adjust the HTML output of the tt BBCode, you can do that via the integrate_bbc_codes hook.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

_Jojo_

Thanks, I got it to work. Just in case anyone else looks to restore other legacy tags in the same way, I have attached my tiny modification.

 In the long run, I think it would be really great if SMF 2.1 could still bring back this feature in one way or another. As said, right now there is no semantically correct way to do this (except for PHP code), and it's a feature supported by Markdown as well, so having bbcode support would be good to have.

stoo23

I have just upgraded a board to 2.1.4, that is specifically for Assembly Language programmers and after doing the upgrade, was Just asked this very same thing.

It might be nice to have this functionality returned in later versions & upgrades  ;)  :)

Thanks to the OP, I will try his 'Fix' and report back.
 :D

Kindred

The use of those tags is deprecated. It will not be returned to the default code
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sesquipedalian

#12
As I suggested in an earlier reply, if you want to continue using it in new posts, you can remove it from $context['legacy_bbc'] here. Your users will still need to type the BBC manually into their posts, though.

Honestly, though, you should just advise your users to use the Courier New font to mark up inline code, like I did above. That approach will require no code changes, and the editor's UI already makes it easy to do that.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

m4z

I just use the font Courier New from the drop-down (because I believe it is semantically equivalent enough to tt).
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

Antechinus

The HTML code tag is inline by default. All you would need to do is create a custom BBC code tag (ie: not set to display: block; and sans other styling) with the font specified in the CSS as whatever looks like the real deal to your users. Could be done via hooks.

Do note that both HTML tags - the HTML5-compliant code tag and the deprecated tt tag - use exactly the same font anyway unless you tell them not to. Both by default, will use whatever the browser's specified default monospace font is. There is absolutely no difference in look unless you force there to be.

Sesquipedalian

#15
Since more than one person has requested this over time, I just uploaded a new mod to restore the [tt] BBCode. It was a bit of a pain in the butt to get the new editor to play nicely with it, but it turned out well.

@stoo23, once the mod has gone through the approval process, you will be able to download it from https://custom.simplemachines.org/index.php?mod=4368. (If you go to that URL now, you won't see anything. It will only appear once it has been approved.)
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

stoo23

Thanks ever so much for that,.. I now have a few Very Happy Users,.. again.

Worked like a 'Treat'  ;D

Cheers

Sesquipedalian

I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

_Jojo_

Quote from: Antechinus on July 17, 2023, 03:15:22 PMDo note that both HTML tags - the HTML5-compliant code tag and the deprecated tt tag - use exactly the same font anyway unless you tell them not to. Both by default, will use whatever the browser's specified default monospace font is. There is absolutely no difference in look unless you force there to be.
Please note that this is not just about looks - it's about accessibility as well. Blind users need semantic HTML tags that make sense to a screen reader. A CSS style change indicating to use a monospace font is not semanticially meaningful. Plus, if at some point it is decided to replace the default font (which would even be possible today by the use of a skin), posts using a font tag won't adjust to this different font.

@Sesquipedalian Thanks for the mod! Definitely much more sophisticated than what I came up with above. :)

Antechinus

Quote from: _Jojo_ on July 23, 2023, 06:13:22 AM
Quote from: Antechinus on July 17, 2023, 03:15:22 PMDo note that both HTML tags - the HTML5-compliant code tag and the deprecated tt tag - use exactly the same font anyway unless you tell them not to. Both by default, will use whatever the browser's specified default monospace font is. There is absolutely no difference in look unless you force there to be.
Please note that this is not just about looks - it's about accessibility as well...
I know all of that already. I'm not sure what point you are trying to make. My point was simply that if you use a basic code tag it will keep your users who wants the look of the old tt tag happy, because it will look the same. It will also be fine for a11y, because it will be doing the job it was designed for.

Advertisement: