Skip to content

Commit

Permalink
Markdown: Resolve Faces eagerly when styling
Browse files Browse the repository at this point in the history
This is the Markdown counterpart to
JuliaLang/StyledStrings.jl#99

which is step 1 to solve the type-piracy in StyledStrings
  • Loading branch information
topolarity committed Oct 16, 2024
1 parent b19a7c1 commit 78c90da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/src/manual/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ julia> lpad(str, 14)
julia> typeof(lpad(str, 7))
Base.AnnotatedString{String}
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face, :magenta)])
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face, Face(foreground = :magenta))])
" julia"
julia> Base.annotatedstring(str, str2)
Expand Down
12 changes: 6 additions & 6 deletions stdlib/Markdown/src/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function term(io::AnnotIO, md::Header{l}, columns) where l
underline = _header_underlines[l]
pre = ' '^margin
local line_width
with_output_annotations(io, :face => face) do io
with_output_annotations(io, :face => getface(face)) do io
headline = annotprint(terminline, md.text)
lines = wraplines(headline, columns - 4margin)
for (i, line) in enumerate(lines)
Expand All @@ -111,7 +111,7 @@ function term(io::AnnotIO, md::Header{l}, columns) where l
header_width = max(0, line_width)
if underline != ' ' && header_width > 0
print(io, '\n', ' '^(margin))
with_output_annotations(io -> print(io, underline^header_width), io, :face => face)
with_output_annotations(io -> print(io, underline^header_width), io, :face => getface(face))
end
end

Expand Down Expand Up @@ -178,11 +178,11 @@ function terminline(io::IO, md::AbstractString)
end

function terminline(io::AnnotIO, md::Bold)
with_output_annotations(io -> terminline(io, md.text), io, :face => :bold)
with_output_annotations(io -> terminline(io, md.text), io, :face => getface(:bold))
end

function terminline(io::AnnotIO, md::Italic)
with_output_annotations(io -> terminline(io, md.text), io, :face => :italic)
with_output_annotations(io -> terminline(io, md.text), io, :face => getface(:italic))
end

function terminline(io::IO, md::LineBreak)
Expand All @@ -199,9 +199,9 @@ end

function terminline(io::AnnotIO, md::Link)
annots = if occursin(r"^(https?|file)://", md.url)
(:face => :markdown_link, :link => md.url)
(:face => getface(:markdown_link), :link => md.url)
else
(:face => :markdown_link,)
(:face => getface(:markdown_link),)
end
with_output_annotations(io -> terminline(io, md.text), io, annots...)
end
Expand Down

0 comments on commit 78c90da

Please sign in to comment.