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

JuliaLang / julia / #37762

28 Apr 2024 07:31AM UTC coverage: 86.373% (-1.1%) from 87.431%
#37762

push

local

web-flow
infer_effects: add `optimize::Bool` optional argument (#54241)

`optimize=false` would be useful for testing effects refinements with
post-optimization analysis.

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

947 existing lines in 40 files now uncovered.

75087 of 86933 relevant lines covered (86.37%)

14939860.08 hits per line

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

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

3
"""
4
    MD
5

6
`MD` represents a Markdown document. Note that the `MD` constructor should not generally be
7
used directly, since it constructs the internal data structures. Instead, you can construct
8
`MD` objects using the exported macros [`@md_str`](@ref) and [`@doc_str`](@ref).
9
"""
10
mutable struct MD
11
    content::Vector{Any}
12
    meta::Dict{Symbol, Any}
13

14
    MD(content::AbstractVector, meta::Dict = Dict()) =
36,604✔
15
        new(content, meta)
16
end
17

18
public MD
19

20
MD(xs...) = MD(vcat(xs...))
11,212✔
21

22
function MD(cfg::Config, xs...)
23
    md = MD(xs...)
10,939✔
24
    md.meta[:config] = cfg
10,939✔
25
    return md
10,939✔
26
end
27

28
config(md::MD) = md.meta[:config]::Config
46,947✔
29

30
# Forward some array methods
31

32
Base.push!(md::MD, x) = push!(md.content, x)
28,382✔
33
Base.getindex(md::MD, args...) = md.content[args...]
×
34
Base.setindex!(md::MD, args...) = setindex!(md.content, args...)
×
35
Base.lastindex(md::MD) = lastindex(md.content)
×
36
Base.firstindex(md::MD) = firstindex(md.content)
×
UNCOV
37
Base.length(md::MD) = length(md.content)
×
UNCOV
38
Base.isempty(md::MD) = isempty(md.content)
×
UNCOV
39
Base.copy(md::MD) = MD(copy(md.content), copy(md.meta))
×
40

41
==(a::MD, b::MD) = (html(a) == html(b))
9✔
42

43
# Parser functions:
44
#   md – should be modified appropriately
45
#   return – basically, true if parse was successful
46
#     false uses the next parser in the queue, true
47
#     goes back to the beginning
48
#
49
# Inner parsers:
50
#   return – element to use or nothing
51

52
# Inner parsing
53

54
function parseinline(stream::IO, md::MD, parsers::Vector{Function})
52,001✔
55
    for parser in parsers
52,001✔
56
        inner = parser(stream, md)
59,610✔
57
        inner ≡ nothing || return inner
107,370✔
58
    end
11,850✔
59
end
60

61
function parseinline(stream::IO, md::MD, config::Config)
27,527✔
62
    content = []
27,527✔
63
    buffer = IOBuffer()
27,527✔
64
    while !eof(stream)
1,904,084✔
65
        char = peek(stream, Char)
1,876,557✔
66
        if haskey(config.inner, char) &&
3,753,114✔
67
                (inner = parseinline(stream, md, config.inner[char])) !== nothing
68
            c = String(take!(buffer))
85,886✔
69
            !isempty(c) && push!(content, c)
47,760✔
70
            buffer = IOBuffer()
47,760✔
71
            push!(content, inner)
47,760✔
72
        else
73
            write(buffer, read(stream, Char))
1,828,797✔
74
        end
75
    end
1,876,557✔
76
    c = String(take!(buffer))
47,346✔
77
    !isempty(c) && push!(content, c)
27,527✔
78
    return content
27,527✔
79
end
80

81
parseinline(s::AbstractString, md::MD, c::Config) =
15,505✔
82
    parseinline(IOBuffer(s), md, c)
83

84
parseinline(s, md::MD) = parseinline(s, md, config(md))
34,834✔
85

86
# Block parsing
87

88
function parse(stream::IO, block::MD, config::Config; breaking = false)
119,610✔
89
    skipblank(stream)
59,805✔
90
    eof(stream) && return false
59,805✔
91
    for parser in (breaking ? config.breaking : [config.breaking; config.regular])
48,866✔
92
        parser(stream, block) && return true
376,854✔
93
    end
345,536✔
94
    return false
17,548✔
95
end
96

97
parse(stream::IO, block::MD; breaking = false) =
36,088✔
98
  parse(stream, block, config(block), breaking = breaking)
99

100
function parse(stream::IO; flavor = julia)
21,878✔
101
    isa(flavor, Symbol) && (flavor = flavors[flavor])
80✔
102
    markdown = MD(flavor)
10,939✔
103
    while parse(stream, markdown, flavor) end
41,761✔
104
    return markdown
10,939✔
105
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

© 2026 Coveralls, Inc