Skip to content

Commit

Permalink
Assume that docstring code with no lang is julia (JuliaLang#55465)
Browse files Browse the repository at this point in the history
  • Loading branch information
tecosaur authored Sep 19, 2024
1 parent 4045e7b commit a73ba3b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function term(io::AnnotIO, md::Header{l}, columns) where l
end

function term(io::IO, md::Code, columns)
code = if md.language ("", "julia")
code = if md.language == "julia"
highlight(md.code)
elseif md.language == "julia-repl" || Base.startswith(md.language, "jldoctest")
hl = AnnotatedString(md.code)
Expand Down
24 changes: 23 additions & 1 deletion stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function formatdoc(d::DocStr)
for part in d.text
formatdoc(buffer, d, part)
end
Markdown.MD(Any[Markdown.parse(seekstart(buffer))])
md = Markdown.MD(Any[Markdown.parse(seekstart(buffer))])
assume_julia_code!(md)
end
@noinline formatdoc(buffer, d, part) = print(buffer, part)

Expand All @@ -95,6 +96,27 @@ function parsedoc(d::DocStr)
d.object
end

"""
assume_julia_code!(doc::Markdown.MD) -> doc
Assume that code blocks with no language specified are Julia code.
"""
function assume_julia_code!(doc::Markdown.MD)
assume_julia_code!(doc.content)
doc
end

function assume_julia_code!(blocks::Vector)
for (i, block) in enumerate(blocks)
if block isa Markdown.Code && block.language == ""
blocks[i] = Markdown.Code("julia", block.code)
elseif block isa Vector || block isa Markdown.MD
assume_julia_code!(block)
end
end
blocks
end

## Trimming long help ("# Extended help")

struct Message # For direct messages to the terminal
Expand Down
4 changes: 2 additions & 2 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ end

let T = meta(DocVars)[@var(DocVars.T)],
S = meta(DocVars)[@var(DocVars.S)],
Tname = Markdown.parse("```\n$(curmod_prefix)DocVars.T\n```"),
Sname = Markdown.parse("```\n$(curmod_prefix)DocVars.S\n```")
Tname = Markdown.parse("```julia\n$(curmod_prefix)DocVars.T\n```"),
Sname = Markdown.parse("```julia\n$(curmod_prefix)DocVars.S\n```")
# Splicing the expression directly doesn't work
@test docstrings_equal(T.docs[Union{}],
doc"""
Expand Down

0 comments on commit a73ba3b

Please sign in to comment.