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

JuliaLang / julia / #37654

16 Oct 2023 09:16PM UTC coverage: 87.028% (-0.1%) from 87.132%
#37654

push

local

web-flow
support `public` in fallback/legacy parser (#51575)

71982 of 82711 relevant lines covered (87.03%)

12112093.78 hits per line

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

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

3
mutable struct MD
4
    content::Vector{Any}
5
    meta::Dict{Symbol, Any}
6

7
    MD(content::AbstractVector, meta::Dict = Dict()) =
31,079✔
8
        new(content, meta)
9
end
10

11
MD(xs...) = MD(vcat(xs...))
9,366✔
12

13
function MD(cfg::Config, xs...)
×
14
    md = MD(xs...)
9,134✔
15
    md.meta[:config] = cfg
9,134✔
16
    return md
9,134✔
17
end
18

19
config(md::MD) = md.meta[:config]::Config
39,276✔
20

21
# Forward some array methods
22

23
Base.push!(md::MD, x) = push!(md.content, x)
24,048✔
24
Base.getindex(md::MD, args...) = md.content[args...]
×
25
Base.setindex!(md::MD, args...) = setindex!(md.content, args...)
×
26
Base.lastindex(md::MD) = lastindex(md.content)
×
27
Base.firstindex(md::MD) = firstindex(md.content)
×
28
Base.length(md::MD) = length(md.content)
×
29
Base.isempty(md::MD) = isempty(md.content)
×
30
Base.copy(md::MD) = MD(copy(md.content), copy(md.meta))
×
31

32
==(a::MD, b::MD) = (html(a) == html(b))
9✔
33

34
# Parser functions:
35
#   md – should be modified appropriately
36
#   return – basically, true if parse was successful
37
#     false uses the next parser in the queue, true
38
#     goes back to the beginning
39
#
40
# Inner parsers:
41
#   return – element to use or nothing
42

43
# Inner parsing
44

45
function parseinline(stream::IO, md::MD, parsers::Vector{Function})
44,122✔
46
    for parser in parsers
44,122✔
47
        inner = parser(stream, md)
50,440✔
48
        inner ≡ nothing || return inner
91,072✔
49
    end
9,808✔
50
end
51

52
function parseinline(stream::IO, md::MD, config::Config)
22,979✔
53
    content = []
22,979✔
54
    buffer = IOBuffer()
22,979✔
55
    while !eof(stream)
1,597,347✔
56
        char = peek(stream, Char)
1,574,368✔
57
        if haskey(config.inner, char) &&
3,148,736✔
58
                (inner = parseinline(stream, md, config.inner[char])) !== nothing
59
            c = String(take!(buffer))
40,632✔
60
            !isempty(c) && push!(content, c)
40,632✔
61
            buffer = IOBuffer()
40,632✔
62
            push!(content, inner)
40,632✔
63
        else
64
            write(buffer, read(stream, Char))
1,533,736✔
65
        end
66
    end
1,574,368✔
67
    c = String(take!(buffer))
22,979✔
68
    !isempty(c) && push!(content, c)
22,979✔
69
    return content
22,979✔
70
end
71

72
parseinline(s::AbstractString, md::MD, c::Config) =
6,682✔
73
    parseinline(IOBuffer(s), md, c)
74

75
parseinline(s, md::MD) = parseinline(s, md, config(md))
22,979✔
76

77
# Block parsing
78

79
function parse(stream::IO, block::MD, config::Config; breaking = false)
101,334✔
80
    skipblank(stream)
50,667✔
81
    eof(stream) && return false
50,667✔
82
    for parser in (breaking ? config.breaking : [config.breaking; config.regular])
41,533✔
83
        parser(stream, block) && return true
317,932✔
84
    end
306,093✔
85
    return false
14,847✔
86
end
87

88
parse(stream::IO, block::MD; breaking = false) =
30,430✔
89
  parse(stream, block, config(block), breaking = breaking)
90

91
function parse(stream::IO; flavor = julia)
18,268✔
92
    isa(flavor, Symbol) && (flavor = flavors[flavor])
80✔
93
    markdown = MD(flavor)
9,134✔
94
    while parse(stream, markdown, flavor) end
61,770✔
95
    return markdown
9,134✔
96
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