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

JuliaLang / julia / #37527

pending completion
#37527

push

local

web-flow
make `IRShow.method_name` inferrable (#49607)

18 of 18 new or added lines in 3 files covered. (100.0%)

68710 of 81829 relevant lines covered (83.97%)

33068903.12 hits per line

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

85.71
/stdlib/Markdown/src/Common/inline.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
# ––––––––
4
# Emphasis
5
# ––––––––
6

7
mutable struct Italic
8
    text
47✔
9
end
10

11
@trigger '*' ->
×
12
function asterisk_italic(stream::IO, md::MD)
28✔
13
    result = parse_inline_wrapper(stream, "*")
28✔
14
    return result === nothing ? nothing : Italic(parseinline(result, md))
28✔
15
end
16

17
@trigger '_' ->
×
18
function underscore_italic(stream::IO, md::MD)
1✔
19
    result = parse_inline_wrapper(stream, "_")
1✔
20
    return result === nothing ? nothing : Italic(parseinline(result, md))
1✔
21
end
22

23
mutable struct Bold
24
    text
22✔
25
end
26

27
@trigger '*' ->
×
28
function asterisk_bold(stream::IO, md::MD)
35✔
29
    result = parse_inline_wrapper(stream, "**")
35✔
30
    return result === nothing ? nothing : Bold(parseinline(result, md))
35✔
31
end
32

33
@trigger '_' ->
×
34
function underscore_bold(stream::IO, md::MD)
2✔
35
    result = parse_inline_wrapper(stream, "__")
2✔
36
    return result === nothing ? nothing : Bold(parseinline(result, md))
2✔
37
end
38

39
# ––––
40
# Code
41
# ––––
42

43
@trigger '`' ->
×
44
function inline_code(stream::IO, md::MD)
36✔
45
    withstream(stream) do
36✔
46
        ticks = startswith(stream, r"^(`+)")
36✔
47
        result = readuntil(stream, ticks)
36✔
48
        if result === nothing
36✔
49
            nothing
2✔
50
        else
51
            result = strip(result)
34✔
52
            # An odd number of backticks wrapping the text will produce a `Code` node, while
53
            # an even number will result in a `LaTeX` node. This allows for arbitrary
54
            # backtick combinations to be embedded inside the resulting node, i.e.
55
            #
56
            # `a`, ``a``, `` `a` ``, ``` ``a`` ```, ``` `a` ```, etc.
57
            #  ^     ^        ^            ^             ^
58
            #  C     L        L            C             C       with C=Code and L=LaTeX.
59
            #
60
            isodd(length(ticks)) ? Code(result) : LaTeX(result)
34✔
61
        end
62
    end
63
end
64

65
# ––––––––––––––
66
# Images & Links
67
# ––––––––––––––
68

69
mutable struct Image
70
    url::String
1✔
71
    alt::String
72
end
73

74
@trigger '!' ->
×
75
function image(stream::IO, md::MD)
4✔
76
    withstream(stream) do
4✔
77
        startswith(stream, "![") || return
7✔
78
        alt = readuntil(stream, ']', match = '[')
1✔
79
        alt ≡ nothing && return
1✔
80
        skipwhitespace(stream)
1✔
81
        startswith(stream, '(') || return
1✔
82
        url = readuntil(stream, ')', match = '(')
1✔
83
        url ≡ nothing && return
1✔
84
        return Image(url, alt)
1✔
85
    end
86
end
87

88
mutable struct Link
89
    text
36✔
90
    url::String
91
end
92

93
@trigger '[' ->
×
94
function link(stream::IO, md::MD)
16✔
95
    withstream(stream) do
16✔
96
        startswith(stream, '[') || return
16✔
97
        text = readuntil(stream, ']', match = '[')
16✔
98
        text ≡ nothing && return
16✔
99
        skipwhitespace(stream)
16✔
100
        startswith(stream, '(') || return
17✔
101
        url = readuntil(stream, ')', match = '(')
15✔
102
        url ≡ nothing && return
15✔
103
        return Link(parseinline(text, md), url)
15✔
104
    end
105
end
106

107
@trigger '[' ->
×
108
function footnote_link(stream::IO, md::MD)
19✔
109
    withstream(stream) do
19✔
110
        regex = r"^\[\^(\w+)\]"
19✔
111
        str = startswith(stream, regex)
19✔
112
        if isempty(str)
35✔
113
            return
16✔
114
        else
115
            ref = (match(regex, str)::AbstractMatch).captures[1]
3✔
116
            return Footnote(ref, nothing)
3✔
117
        end
118
    end
119
end
120

121
@trigger '<' ->
×
122
function autolink(stream::IO, md::MD)
7✔
123
    withstream(stream) do
7✔
124
        startswith(stream, '<') || return
7✔
125
        url = readuntil(stream, '>')
7✔
126
        url ≡ nothing && return
7✔
127
        _is_link(url) && return Link(url, url)
7✔
128
        _is_mailto(url) && return Link(url, url)
5✔
129
        return
4✔
130
    end
131
end
132

133
# This list is taken from the commonmark spec
134
# http://spec.commonmark.org/0.19/#absolute-uri
135
const _allowable_schemes = Set(split("coap doi javascript aaa aaas about acap cap cid crid data dav dict dns file ftp geo go gopher h323 http https iax icap im imap info ipp iris iris.beep iris.xpc iris.xpcs iris.lwz ldap mailto mid msrp msrps mtqp mupdate news nfs ni nih nntp opaquelocktoken pop pres rtsp service session shttp sieve sip sips sms snmp,soap.beep soap.beeps tag tel telnet tftp thismessage tn3270 tip tv urn vemmi ws wss xcon xcon-userid xmlrpc.beep xmlrpc.beeps xmpp z39.50r z39.50s
136
adiumxtra afp afs aim apt,attachment aw beshare bitcoin bolo callto chrome,chrome-extension com-eventbrite-attendee content cvs,dlna-playsingle dlna-playcontainer dtn dvb ed2k facetime feed finger fish gg git gizmoproject gtalk hcp icon ipn irc irc6 ircs itms jar jms keyparc lastfm ldaps magnet maps market,message mms ms-help msnim mumble mvn notes oid palm paparazzi platform proxy psyc query res resource rmi rsync rtmp secondlife sftp sgn skype smb soldat spotify ssh steam svn teamspeak
137
things udp unreal ut2004 ventrilo view-source webcal wtai wyciwyg xfire xri ymsgr"))
138

139
function _is_link(s::AbstractString)
7✔
140
    '<' in s && return false
7✔
141

142
    m = match(r"^(.*)://(\S+?)(:\S*)?$", s)
7✔
143
    m ≡ nothing && return false
7✔
144
    scheme = lowercase(m.captures[1])
2✔
145
    return scheme in _allowable_schemes
2✔
146
end
147

148
# non-normative regex from the HTML5 spec
149
const _email_regex = r"^mailto\:[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
150

151
function _is_mailto(s::AbstractString)
5✔
152
    return occursin(_email_regex, s)
5✔
153
end
154

155
# –––––––––––
156
# Punctuation
157
# –––––––––––
158

159
mutable struct LineBreak end
4✔
160

161
@trigger '\\' ->
×
162
function linebreak(stream::IO, md::MD)
4✔
163
    if startswith(stream, "\\\n")
4✔
164
        return LineBreak()
3✔
165
    end
166
end
167

168
@trigger '-' ->
×
169
function en_dash(stream::IO, md::MD)
2✔
170
    if startswith(stream, "--")
2✔
171
        return "–"
×
172
    end
173
end
174

175
const escape_chars = "\\`*_#+-.!{}[]()\$"
176

177
@trigger '\\' ->
×
178
function escapes(stream::IO, md::MD)
1✔
179
    withstream(stream) do
1✔
180
        if startswith(stream, "\\") && !eof(stream) && (c = read(stream, Char)) in escape_chars
1✔
181
            return string(c)
1✔
182
        end
183
    end
184
end
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