• 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

88.64
/misago/parser/plugins/quotebbcode.py
1
import re
1✔
2

3
from markdown_it import MarkdownIt
1✔
4
from markdown_it.rules_block.state_block import StateBlock
1✔
5

6
from ..bbcode import BBCodeBlockRule, bbcode_block_end_rule, bbcode_block_start_rule
1✔
7

8

9
def quote_bbcode_plugin(md: MarkdownIt):
1✔
10
    md.block.ruler.before(
1✔
11
        "paragraph",
12
        "quote_bbcode",
13
        QuoteBBCodeBlockRule(
14
            name="quote_bbcode",
15
            element="misago-quote",
16
            start=quote_bbcode_start,
17
            end=quote_bbcode_end,
18
        ),
19
        {"alt": ["paragraph"]},
20
    )
21

22

23
class QuoteBBCodeBlockRule(BBCodeBlockRule):
1✔
24
    def get_meta(self, attrs: dict) -> dict | None:
1✔
25
        if attrs.get("post"):
1✔
26
            return {"post": attrs["post"]}
1✔
27

28
        return None
1✔
29

30

31
def quote_bbcode_start(
1✔
32
    state: StateBlock, line: int
33
) -> tuple[str, dict | None, int, int] | None:
34
    start = bbcode_block_start_rule("quote", state, line, args=True)
1✔
35
    if not start:
1✔
36
        return None
1✔
37

38
    markup, args_str, start, end = start
1✔
39

40
    if args_str:
1✔
41
        args = quote_bbcode_parse_args(args_str)
1✔
42
    else:
43
        args = None
1✔
44

45
    return markup, args, start, end
1✔
46

47

48
def quote_bbcode_parse_args(args_str: str) -> dict | None:
1✔
49
    if not args_str:
1✔
NEW
50
        return None
×
51

52
    if args := parse_user_post_args(args_str):
1✔
53
        return args
1✔
54

55
    return {"info": args_str}
1✔
56

57

58
USER_POST = re.compile(r"^(?P<user>[a-zA-Z0-9]+) *[;,] *post: *(?P<post>[0-9]+) *$")
1✔
59

60

61
def parse_user_post_args(args: str) -> dict | None:
1✔
62
    match = USER_POST.match(args)
1✔
63
    if not match:
1✔
64
        return None
1✔
65

66
    user = match.group("user")
1✔
67
    post = match.group("post")
1✔
68

69
    try:
1✔
70
        post = int(post)
1✔
71
        if post < 1:
1✔
NEW
72
            return None
×
NEW
73
    except (TypeError, ValueError):
×
NEW
74
        return None
×
75

76
    if user and post:
1✔
77
        return {"user": user, "post": post}
1✔
78

NEW
79
    return None
×
80

81

82
def quote_bbcode_end(state: StateBlock, line: int) -> tuple[str, int, int] | None:
1✔
83
    return bbcode_block_end_rule("quote", state, line)
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