• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rafalp / Misago / 15367574579

31 May 2025 09:11PM UTC coverage: 97.171% (-0.02%) from 97.191%
15367574579

Pull #1935

github

web-flow
Merge 4c4863ade into b4b2850ad
Pull Request #1935: Update formatting bbcode to respect escaping

22 of 24 new or added lines in 4 files covered. (91.67%)

32 existing lines in 7 files now uncovered.

71605 of 73690 relevant lines covered (97.17%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.87
/misago/parser/plugins/formattingbbcode.py
1
from markdown_it import MarkdownIt
1✔
2
from markdown_it.rules_inline.state_inline import StateInline
1✔
3

4
FORMATTING_BBCODE = {
1✔
5
    "bold": "b",
6
    "italic": "i",
7
    "underline": "u",
8
    "strikethrough": "del",
9
}
10

11

12
def formatting_bbcode_plugin(md: MarkdownIt):
1✔
13
    for name, markup in FORMATTING_BBCODE.items():
1✔
14
        md.inline.ruler.push(
1✔
15
            name + "bbcode",
16
            get_formatting_bbcode_rule(name, markup),
17
        )
18

19

20
def get_formatting_bbcode_rule(name: str, markup: str):
1✔
21
    def formatting_bbcode_rule(state: StateInline, silent: bool):
1✔
22
        markup_open = f"[{name[0]}]"
1✔
23
        markup_close = f"[/{name[0]}]"
1✔
24

25
        start = state.pos
1✔
26
        maximum = state.posMax
1✔
27

28
        if maximum - start < 7:
1✔
29
            return False
1✔
30

31
        marker = state.src[start : start + 3]
1✔
32

33
        if silent:
1✔
34
            return False
1✔
35

36
        if marker.lower() != markup_open:
1✔
37
            return False
1✔
38

39
        pos = start + 3
1✔
40
        maximum = state.posMax
1✔
41
        nesting = 1
1✔
42

43
        while pos <= maximum:
1✔
44
            if state.src[pos] == "\\":
1✔
45
                pos += 2
1✔
46
                continue
1✔
47

48
            if state.src[pos : pos + 3].lower() == markup_open:
1✔
49
                nesting += 1
1✔
50

51
            if state.src[pos : pos + 4].lower() == markup_close:
1✔
52
                nesting -= 1
1✔
53
                if nesting == 0:
1✔
54
                    break
1✔
55

56
            pos += 1
1✔
57

58
        if state.src[pos : pos + 4].lower() != markup_close:
1✔
UNCOV
59
            return False
×
60

61
        if not silent:
1✔
62
            state.pos = start + 3
1✔
63
            state.posMax = pos
1✔
64

65
            token = state.push(name + "_bbcode_open", markup, 1)
1✔
66
            token.markup = markup_open
1✔
67
            state.md.inline.tokenize(state)
1✔
68

69
            token = state.push(name + "_bbcode_close", markup, -1)
1✔
70
            token.markup = markup_close
1✔
71

72
        state.pos = pos + 4
1✔
73
        state.posMax = maximum
1✔
74
        return True
1✔
75

76
    return formatting_bbcode_rule
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc