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

JuliaLang / julia / #37992

10 Jan 2025 02:24AM UTC coverage: 85.957% (+0.6%) from 85.38%
#37992

push

local

web-flow
Make write(IO, Char) actually return the amount of printed bytes instead of the attempted written bytes. (#56980)

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

374 existing lines in 34 files now uncovered.

51810 of 60274 relevant lines covered (85.96%)

12043363.27 hits per line

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

92.16
/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()) =
34,872✔
15
        new(content, meta)
16
end
17

18
MD(xs...) = MD(vcat(xs...))
10,788✔
19

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

26
config(md::MD) = md.meta[:config]::Config
45,102✔
27

28
# Forward some array methods
29

30
Base.push!(md::MD, x) = push!(md.content, x)
27,236✔
UNCOV
31
Base.getindex(md::MD, args...) = md.content[args...]
×
UNCOV
32
Base.setindex!(md::MD, args...) = setindex!(md.content, args...)
×
33
Base.lastindex(md::MD) = lastindex(md.content)
×
34
Base.firstindex(md::MD) = firstindex(md.content)
×
35
Base.length(md::MD) = length(md.content)
4✔
36
Base.isempty(md::MD) = isempty(md.content)
1✔
37
Base.copy(md::MD) = MD(copy(md.content), copy(md.meta))
1✔
38

39
==(a::MD, b::MD) = (html(a) == html(b))
51✔
40

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

50
# Inner parsing
51

52
function parseinline(stream::IO, md::MD, parsers::Vector{Function})
49,984✔
53
    for parser in parsers
49,984✔
54
        inner = parser(stream, md)
57,516✔
55
        inner ≡ nothing || return inner
103,186✔
56
    end
11,846✔
57
end
58

59
function parseinline(stream::IO, md::MD, config::Config)
26,406✔
60
    content = []
26,406✔
61
    buffer = IOBuffer()
26,406✔
62
    while !eof(stream)
1,809,580✔
63
        char = peek(stream, Char)
1,783,174✔
64
        if haskey(config.inner, char) &&
1,833,158✔
65
                (inner = parseinline(stream, md, config.inner[char])) !== nothing
66
            c = String(take!(buffer))
82,148✔
67
            !isempty(c) && push!(content, c)
45,670✔
68
            buffer = IOBuffer()
45,670✔
69
            push!(content, inner)
45,670✔
70
        else
71
            write(buffer, read(stream, Char))
1,737,504✔
72
        end
73
    end
1,783,174✔
74
    c = String(take!(buffer))
45,272✔
75
    !isempty(c) && push!(content, c)
26,406✔
76
    return content
26,406✔
77
end
78

79
parseinline(s::AbstractString, md::MD, c::Config) =
7,894✔
80
    parseinline(IOBuffer(s), md, c)
81

82
parseinline(s, md::MD) = parseinline(s, md, config(md))
26,406✔
83

84
# Block parsing
85

86
function _parse(stream::IO, block::MD, config::Config; breaking = false)
114,318✔
87
    skipblank(stream)
57,159✔
88
    eof(stream) && return false
57,159✔
89
    for parser in (breaking ? config.breaking : [config.breaking; config.regular])
46,670✔
90
        parser(stream, block) && return true
361,045✔
91
    end
331,071✔
92
    return false
16,696✔
93
end
94

95
_parse(stream::IO, block::MD; breaking = false) =
34,438✔
96
    _parse(stream, block, config(block), breaking = breaking)
97

98
"""
99
    parse(stream::IO) -> MD
100

101
Parse the content of `stream` as Julia-flavored Markdown text and return the corresponding `MD` object.
102
"""
103
function parse(stream::IO; flavor = julia)
10,489✔
104
    isa(flavor, Symbol) && (flavor = flavors[flavor])
196✔
105
    markdown = MD(flavor)
10,489✔
106
    while _parse(stream, markdown, flavor) end
39,940✔
107
    return markdown
10,489✔
108
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