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

Highlight julia-repl code in Markdown specially #54423

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions stdlib/Markdown/src/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const MARKDOWN_FACES = [
:markdown_h6 => Face(height=1.05, inherit=:markdown_header),
:markdown_admonition => Face(weight=:bold),
:markdown_code => Face(inherit=:code),
:markdown_julia_prompt => Face(inherit=:repl_prompt_julia),
:markdown_footnote => Face(inherit=:bright_yellow),
:markdown_hrule => Face(inherit=:shadow),
:markdown_inlinecode => Face(inherit=:markdown_code),
Expand Down
17 changes: 16 additions & 1 deletion stdlib/Markdown/src/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,23 @@ function term(io::AnnotIO, md::Header{l}, columns) where l
end

function term(io::IO, md::Code, columns)
code = if md.language ∈ ("", "julia", "julia-repl", "jldoctest")
code = if md.language ∈ ("", "julia")
highlight(md.code)
elseif md.language == "julia-repl" || Base.startswith(md.language, "jldoctest")
hl = AnnotatedString(md.code)
for (; match) in eachmatch(r"(?:^|\n)julia>", hl)
StyledStrings.face!(match, :markdown_julia_prompt)
afterprompt = match.offset + ncodeunits(match) + 1
_, exprend = Meta.parse(md.code, afterprompt, raise = false)
highlight!(hl[afterprompt:prevind(md.code, exprend)])
if (nextspace = findnext(' ', md.code, exprend)) |> !isnothing
nextword = hl[exprend:prevind(hl, nextspace)]
if nextword == "ERROR:"
StyledStrings.face!(nextword, :error)
end
end
end
hl
elseif md.language == "styled"
styled(md.code)
else
Expand Down