WeblateOrg / WeblateOrg/weblate

Improve support for BBCode tags (e.g. parameters, self-closing tags)

Open
#21,176 3 comments 1 reaction 0 assignees View on GitHub
Area: Quality checks good first issue Waiting for: Demand
Dominant language
Python
Stars
6.1k
Forks
1.4k
Avg merge
9h 53m
Merged PRs (30d)
395

Description

### Describe the problem

In Godot Engine's class reference, we make great use of [BBCode](https://www.bbcode.org/reference.php) to format text. A lot of go beyond the standard `[b]`, `[i]`, `[code]` tags and require additional parameters.
For example, the `[url]` tag can optionally accept a link, formatted as `[url=https://github.com/WeblateOrg]`.
Our custom `[codeblock]` tag can also accept a language, formatted as `[codeblock lang=csharp]`.

Unfortunately, the "highlighting" and "error reporting" systems cannot detect these tags.
This can make it quite awkward to change several strings. BBCode-related changes are harder to spot, tags may be mistyped or missing in translations, shortcuts such as `CTRL + number key` to quickly insert tags do not work.

### Solution brainstorm

I believe what mostly needs to change is this regex in this repository:

https://github.com/WeblateOrg/weblate/blob/2b4eab375cd29cb0818922a62b5a9c5ca9d0c527/weblate/checks/markup.py#L76-L78

With this, I figured out that allowing characters after the tag name would do the trick. For some reason, and against any implementation of BBCode I've ever seen myself, `@` followed by any text was already allowed. Allowing white space and `=` matches the [general specifications](https://www.bbcode.org/reference.php) better, allowing `[url]`, `[color]`, `[img]`, etc. tags with their parameters to be detected.

```regex
(?P\[(?P[^]]+)([@\s=][^]]*)?\])(.*?)(?P\[\/(?P=tag)\])
```

Image

This still doesn't solve all problems, but it'd be a nice start.
That is to say, **tags that do not need a closing tag** would still not be accounted for. While that's not necessarily part of the standard, it would still be very nice (as far as Godot Engine is concerned).

Furthermore, without additional adjustments in the proposed regex, tags that begin in one line and end in another line would also not be accounted for:
```
[custom]My
String[/custom]
```

### Describe alternatives you have considered

The ability to define custom BBCode tags in a repository would've also solved this, but it'd be quite the undertaking, especially since Weblate is [well-aware that BBCode support is quite rudimentary](https://docs.weblate.org/en/weblate-5.3.1/user/checks.html#bbcode-markup).

### Screenshots

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in weblate/checks/markup.py around lines 76-78 and inspect the BBCode regex used by highlighting and error reporting. Reproduce the parameterized, self-closing, and multiline examples from the issue; done means these tags are detected correctly without regressing standard BBCode handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
localization
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.