Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: _Jojo_ on January 11, 2023, 04:32:41 AM

Title: Replacement for [tt] tag
Post by: _Jojo_ on January 11, 2023, 04:32:41 AM
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.
Title: Re: Replacement for [tt] tag
Post by: Aleksi "Lex" Kilpinen on January 11, 2023, 10:41:14 AM
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!"; ?>
Title: Re: Replacement for [tt] tag
Post by: _Jojo_ on January 11, 2023, 11:49:32 AM
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.
Title: Re: Replacement for [tt] tag
Post by: Aleksi "Lex" Kilpinen on January 11, 2023, 11:55:39 AM
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 (https://custom.simplemachines.org/index.php?mod=3699) would work for you (I'm not sure if it's actually compatible with current 2.1 though, sorry.)
Title: Re: Replacement for [tt] tag
Post by: Sesquipedalian on January 11, 2023, 12:09:01 PM
You could just go to this line in Load.php (https://github.com/SimpleMachines/SMF/blob/release-2.1/Sources/Load.php#L506) and remove 'tt' from the $context['legacy_bbc'] list.
Title: Re: Replacement for [tt] tag
Post by: _Jojo_ on January 11, 2023, 12:10:17 PM
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?
Title: Re: Replacement for [tt] tag
Post by: Steve on January 11, 2023, 03:31:48 PM
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 (https://github.com/SimpleMachines/SMF/blob/release-2.1/Sources/Load.php#L506) and remove 'tt' from the $context['legacy_bbc'] list.
Title: Re: Replacement for [tt] tag
Post by: _Jojo_ on January 11, 2023, 03:35:25 PM
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.
Title: Re: Replacement for [tt] tag
Post by: Sesquipedalian on January 11, 2023, 03:59:41 PM
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.
Title: Re: Replacement for [tt] tag
Post by: _Jojo_ on January 11, 2023, 04:20:09 PM
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.
Title: Re: Replacement for [tt] tag
Post by: stoo23 on July 16, 2023, 11:17:22 PM
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
Title: Re: Replacement for [tt] tag
Post by: Kindred on July 17, 2023, 12:48:40 AM
The use of those tags is deprecated. It will not be returned to the default code
Title: Re: Replacement for [tt] tag
Post by: Sesquipedalian on July 17, 2023, 01:28:10 AM
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 (https://github.com/SimpleMachines/SMF/blob/release-2.1/Sources/Load.php). 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.
Title: Re: Replacement for [tt] tag
Post by: m4z on July 17, 2023, 12:48:40 PM
I just use the font Courier New from the drop-down (because I believe it is semantically equivalent enough to tt).
Title: Re: Replacement for [tt] tag
Post by: Antechinus on July 17, 2023, 03:15:22 PM
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.
Title: Re: Replacement for [tt] tag
Post by: Sesquipedalian on July 18, 2023, 06:32:48 PM
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.)
Title: Re: Replacement for [tt] tag
Post by: stoo23 on July 19, 2023, 05:42:54 AM
Thanks ever so much for that,.. I now have a few Very Happy Users,.. again.

Worked like a 'Treat'  ;D

Cheers
Title: Re: Replacement for [tt] tag
Post by: Sesquipedalian on July 19, 2023, 11:17:49 AM
Excellent. :)
Title: Re: Replacement for [tt] tag
Post by: _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. 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. :)
Title: Re: Replacement for [tt] tag
Post by: Antechinus on July 23, 2023, 07:01:30 AM
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.