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

earwig / mwparserfromhell / 6080564822

05 Sep 2023 05:27AM UTC coverage: 99.136%. Remained the same
6080564822

push

github

earwig
Version bump and fix docs build

2 of 2 new or added lines in 1 file covered. (100.0%)

2982 of 3008 relevant lines covered (99.14%)

9.83 hits per line

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

100.0
/src/mwparserfromhell/nodes/external_link.py
1
# Copyright (C) 2012-2020 Ben Kurtovic <ben.kurtovic@gmail.com>
2
#
3
# Permission is hereby granted, free of charge, to any person obtaining a copy
4
# of this software and associated documentation files (the "Software"), to deal
5
# in the Software without restriction, including without limitation the rights
6
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
# copies of the Software, and to permit persons to whom the Software is
8
# furnished to do so, subject to the following conditions:
9
#
10
# The above copyright notice and this permission notice shall be included in
11
# all copies or substantial portions of the Software.
12
#
13
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
# SOFTWARE.
20

21

22
from ._base import Node
10✔
23
from ..utils import parse_anything
10✔
24

25
__all__ = ["ExternalLink"]
10✔
26

27

28
class ExternalLink(Node):
10✔
29
    """Represents an external link, like ``[http://example.com/ Example]``."""
30

31
    def __init__(self, url, title=None, brackets=True, suppress_space=False):
10✔
32
        super().__init__()
10✔
33
        self.url = url
10✔
34
        self.title = title
10✔
35
        self.brackets = brackets
10✔
36
        self.suppress_space = suppress_space
10✔
37

38
    def __str__(self):
10✔
39
        if self.brackets:
10✔
40
            if self.title is not None:
10✔
41
                if self.suppress_space is True:
10✔
42
                    return "[" + str(self.url) + str(self.title) + "]"
10✔
43
                return "[" + str(self.url) + " " + str(self.title) + "]"
10✔
44
            return "[" + str(self.url) + "]"
10✔
45
        return str(self.url)
10✔
46

47
    def __children__(self):
10✔
48
        yield self.url
10✔
49
        if self.title is not None:
10✔
50
            yield self.title
10✔
51

52
    def __strip__(self, **kwargs):
10✔
53
        if self.brackets:
10✔
54
            if self.title:
10✔
55
                return self.title.strip_code(**kwargs)
10✔
56
            return None
10✔
57
        return self.url.strip_code(**kwargs)
10✔
58

59
    def __showtree__(self, write, get, mark):
10✔
60
        if self.brackets:
10✔
61
            write("[")
10✔
62
        get(self.url)
10✔
63
        if self.title is not None:
10✔
64
            get(self.title)
10✔
65
        if self.brackets:
10✔
66
            write("]")
10✔
67

68
    @property
10✔
69
    def url(self):
8✔
70
        """The URL of the link target, as a :class:`.Wikicode` object."""
71
        return self._url
10✔
72

73
    @property
10✔
74
    def title(self):
8✔
75
        """The link title (if given), as a :class:`.Wikicode` object."""
76
        return self._title
10✔
77

78
    @property
10✔
79
    def brackets(self):
8✔
80
        """Whether to enclose the URL in brackets or display it straight."""
81
        return self._brackets
10✔
82

83
    @url.setter
10✔
84
    def url(self, value):
8✔
85
        # pylint: disable=import-outside-toplevel
86
        from ..parser import contexts
10✔
87

88
        self._url = parse_anything(value, contexts.EXT_LINK_URI)
10✔
89

90
    @title.setter
10✔
91
    def title(self, value):
8✔
92
        self._title = None if value is None else parse_anything(value)
10✔
93

94
    @brackets.setter
10✔
95
    def brackets(self, value):
8✔
96
        self._brackets = bool(value)
10✔
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