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

rafalp / Misago / 14272451294

04 Apr 2025 07:09PM UTC coverage: 97.11% (+0.01%) from 97.097%
14272451294

push

github

web-flow
User mentions (#1904)

83 of 84 new or added lines in 8 files covered. (98.81%)

20 existing lines in 4 files now uncovered.

69061 of 71116 relevant lines covered (97.11%)

0.97 hits per line

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

97.73
/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
    "italics": "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 + 4 <= maximum:
1✔
44
            if state.src[pos : pos + 3].lower() == markup_open:
1✔
45
                nesting += 1
1✔
46

47
            if state.src[pos : pos + 4].lower() == markup_close:
1✔
48
                nesting -= 1
1✔
49
                if nesting == 0:
1✔
50
                    break
1✔
51

52
            pos += 1
1✔
53

54
        if state.src[pos : pos + 4].lower() != markup_close:
1✔
UNCOV
55
            return False
×
56

57
        if not silent:
1✔
58
            state.pos = start + 3
1✔
59
            state.posMax = pos
1✔
60

61
            token = state.push(name + "_bbcode_open", markup, 1)
1✔
62
            token.markup = markup_open
1✔
63

64
            state.md.inline.tokenize(state)
1✔
65

66
            token = state.push(name + "_bbcode_close", markup, -1)
1✔
67
            token.markup = markup_close
1✔
68

69
        state.pos = pos + 4
1✔
70
        state.posMax = maximum
1✔
71
        return True
1✔
72

73
    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

© 2025 Coveralls, Inc