Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume that docstring code with no lang is julia #55465

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
LilithHafner marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -574,8 +574,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