Skip to content

Commit 6dde42f

Browse files
committed
Markdown: Resolve Faces eagerly when styling
This is the Markdown counterpart to JuliaLang/StyledStrings.jl#99 which is step 1 to solve the type-piracy in StyledStrings
1 parent b19a7c1 commit 6dde42f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

doc/src/manual/strings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ julia> lpad(str, 14)
12421242
julia> typeof(lpad(str, 7))
12431243
Base.AnnotatedString{String}
12441244
1245-
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face, :magenta)])
1245+
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face, Face(foreground = :magenta))])
12461246
" julia"
12471247
12481248
julia> Base.annotatedstring(str, str2)

stdlib/Markdown/src/Markdown.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Markdown
1212
import Base: AnnotatedString, AnnotatedIOBuffer, show, ==, with_output_color, mapany
1313
using Base64: stringmime
1414

15-
using StyledStrings: StyledStrings, Face, addface!, @styled_str, styled
15+
using StyledStrings: StyledStrings, Face, addface!, @styled_str, styled, getface
1616
using JuliaSyntaxHighlighting: highlight, highlight!
1717

1818
# Margin for printing in terminal.

stdlib/Markdown/src/render/terminal/render.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function term(io::AnnotIO, md::Header{l}, columns) where l
9393
underline = _header_underlines[l]
9494
pre = ' '^margin
9595
local line_width
96-
with_output_annotations(io, :face => face) do io
96+
with_output_annotations(io, :face => getface(face)) do io
9797
headline = annotprint(terminline, md.text)
9898
lines = wraplines(headline, columns - 4margin)
9999
for (i, line) in enumerate(lines)
@@ -111,7 +111,7 @@ function term(io::AnnotIO, md::Header{l}, columns) where l
111111
header_width = max(0, line_width)
112112
if underline != ' ' && header_width > 0
113113
print(io, '\n', ' '^(margin))
114-
with_output_annotations(io -> print(io, underline^header_width), io, :face => face)
114+
with_output_annotations(io -> print(io, underline^header_width), io, :face => getface(face))
115115
end
116116
end
117117

@@ -178,11 +178,11 @@ function terminline(io::IO, md::AbstractString)
178178
end
179179

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

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

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

200200
function terminline(io::AnnotIO, md::Link)
201201
annots = if occursin(r"^(https?|file)://", md.url)
202-
(:face => :markdown_link, :link => md.url)
202+
(:face => getface(:markdown_link), :link => md.url)
203203
else
204-
(:face => :markdown_link,)
204+
(:face => getface(:markdown_link),)
205205
end
206206
with_output_annotations(io -> terminline(io, md.text), io, annots...)
207207
end

0 commit comments

Comments
 (0)