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

rafalp / Misago / 14252691788

03 Apr 2025 09:01PM UTC coverage: 97.097% (-0.08%) from 97.173%
14252691788

push

github

web-flow
Replace default parser with `markdown-it-py` (#1901)

1902 of 1969 new or added lines in 66 files covered. (96.6%)

20 existing lines in 7 files now uncovered.

68959 of 71021 relevant lines covered (97.1%)

0.97 hits per line

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

97.44
/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

42
        while pos + 4 <= maximum:
1✔
43
            if state.src[pos : pos + 4].lower() == markup_close:
1✔
44
                break
1✔
45

46
            pos += 1
1✔
47

48
        if state.src[pos : pos + 4].lower() != markup_close:
1✔
NEW
49
            return False
×
50

51
        if not silent:
1✔
52
            state.pos = start + 3
1✔
53
            state.posMax = pos
1✔
54

55
            token = state.push(name + "_bbcode_open", markup, 1)
1✔
56
            token.markup = markup_open
1✔
57

58
            state.md.inline.tokenize(state)
1✔
59

60
            token = state.push(name + "_bbcode_close", markup, -1)
1✔
61
            token.markup = markup_close
1✔
62

63
        state.pos = pos + 4
1✔
64
        state.posMax = maximum
1✔
65
        return True
1✔
66

67
    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