fix incorrect folder name for julia-0.6.x
Former-commit-id: ef2c7401e0876f22d2f7762d182cfbcd5a7d9c70
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
|
||||
|
||||
# Styles
|
||||
|
||||
const text_formats = Dict(
|
||||
:black => ("\e[30m", "\e[39m"),
|
||||
:red => ("\e[31m", "\e[39m"),
|
||||
:green => ("\e[32m", "\e[39m"),
|
||||
:yellow => ("\e[33m", "\e[39m"),
|
||||
:blue => ("\e[34m", "\e[39m"),
|
||||
:magenta => ("\e[35m", "\e[39m"),
|
||||
:cyan => ("\e[36m", "\e[39m"),
|
||||
:white => ("\e[37m", "\e[39m"),
|
||||
:reset => ("\e[0m", "\e[0m"),
|
||||
:bold => ("\e[1m", "\e[22m"),
|
||||
:underline => ("\e[4m", "\e[24m"),
|
||||
:blink => ("\e[5m", "\e[25m"),
|
||||
:negative => ("\e[7m", "\e[27m"))
|
||||
|
||||
function with_output_format(f::Function, formats::Vector{Symbol}, io::IO, args...)
|
||||
Base.have_color && for format in formats
|
||||
haskey(text_formats, format) &&
|
||||
print(io, text_formats[format][1])
|
||||
end
|
||||
try f(io, args...)
|
||||
finally
|
||||
Base.have_color && for format in formats
|
||||
haskey(text_formats, format) &&
|
||||
print(io, text_formats[format][2])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
with_output_format(f::Function, format::Symbol, args...) =
|
||||
with_output_format(f, [format], args...)
|
||||
|
||||
with_output_format(format, f::Function, args...) =
|
||||
with_output_format(f, format, args...)
|
||||
|
||||
function print_with_format(format, io::IO, x)
|
||||
with_output_format(format, io) do io
|
||||
print(io, x)
|
||||
end
|
||||
end
|
||||
|
||||
function println_with_format(format, io::IO, x)
|
||||
print_with_format(format, io, x)
|
||||
println(io)
|
||||
end
|
||||
|
||||
# Wrapping
|
||||
|
||||
function ansi_length(s)
|
||||
replace(s, r"\e\[[0-9]+m", "") |> length
|
||||
end
|
||||
|
||||
words(s) = split(s, " ")
|
||||
lines(s) = split(s, "\n")
|
||||
|
||||
# This could really be more efficient
|
||||
function wrapped_lines(s::AbstractString; width = 80, i = 0)
|
||||
if ismatch(r"\n", s)
|
||||
return vcat(map(s->wrapped_lines(s, width = width, i = i), split(s, "\n"))...)
|
||||
end
|
||||
ws = words(s)
|
||||
lines = AbstractString[ws[1]]
|
||||
i += ws[1] |> ansi_length
|
||||
for word in ws[2:end]
|
||||
word_length = ansi_length(word)
|
||||
if i + word_length + 1 > width
|
||||
i = word_length
|
||||
push!(lines, word)
|
||||
else
|
||||
i += word_length + 1
|
||||
lines[end] *= " " * word
|
||||
end
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
wrapped_lines(f::Function, args...; width = 80, i = 0) =
|
||||
wrapped_lines(sprint(f, args...), width = width, i = 0)
|
||||
|
||||
function print_wrapped(io::IO, s...; width = 80, pre = "", i = 0)
|
||||
lines = wrapped_lines(s..., width = width, i = i)
|
||||
println(io, lines[1])
|
||||
for line in lines[2:end]
|
||||
println(io, pre, line)
|
||||
end
|
||||
length(lines), length(pre) + ansi_length(lines[end])
|
||||
end
|
||||
|
||||
print_wrapped(f::Function, io::IO, args...; kws...) = print_wrapped(io, f, args...; kws...)
|
||||
|
||||
function print_centred(io::IO, s...; columns = 80, width = columns)
|
||||
lines = wrapped_lines(s..., width = width)
|
||||
for line in lines
|
||||
print(io, " "^(div(columns-ansi_length(line), 2)))
|
||||
println(io, line)
|
||||
end
|
||||
length(lines), length(pre) + length(lines[end])
|
||||
end
|
||||
|
||||
function centred(s, columns)
|
||||
pad = div(columns - ansi_length(s), 2)
|
||||
" "^pad * s
|
||||
end
|
||||
148
julia-0.6.3/share/julia/base/markdown/render/terminal/render.jl
Normal file
148
julia-0.6.3/share/julia/base/markdown/render/terminal/render.jl
Normal file
@@ -0,0 +1,148 @@
|
||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
|
||||
|
||||
include("formatting.jl")
|
||||
|
||||
const margin = 2
|
||||
cols(io) = displaysize(io)[2]
|
||||
|
||||
function term(io::IO, content::Vector, cols)
|
||||
isempty(content) && return
|
||||
for md in content[1:end-1]
|
||||
term(io, md, cols)
|
||||
println(io)
|
||||
end
|
||||
term(io, content[end], cols)
|
||||
end
|
||||
|
||||
term(io::IO, md::MD, columns = cols(io)) = term(io, md.content, columns)
|
||||
|
||||
function term(io::IO, md::Paragraph, columns)
|
||||
print(io, " "^margin)
|
||||
print_wrapped(io, width = columns-2margin, pre = " "^margin) do io
|
||||
terminline(io, md.content)
|
||||
end
|
||||
end
|
||||
|
||||
function term(io::IO, md::BlockQuote, columns)
|
||||
s = sprint(term, md.content, columns - 10)
|
||||
for line in split(rstrip(s), "\n")
|
||||
println(io, " "^margin, "|", line)
|
||||
end
|
||||
end
|
||||
|
||||
function term(io::IO, md::Admonition, columns)
|
||||
print(io, " "^margin, "| ")
|
||||
with_output_format(:bold, print, io, isempty(md.title) ? md.category : md.title)
|
||||
println(io, "\n", " "^margin, "|")
|
||||
s = sprint(term, md.content, columns - 10)
|
||||
for line in split(rstrip(s), "\n")
|
||||
println(io, " "^margin, "|", line)
|
||||
end
|
||||
end
|
||||
|
||||
function term(io::IO, f::Footnote, columns)
|
||||
print(io, " "^margin, "| ")
|
||||
with_output_format(:bold, print, io, "[^$(f.id)]")
|
||||
println(io, "\n", " "^margin, "|")
|
||||
s = sprint(term, f.text, columns - 10)
|
||||
for line in split(rstrip(s), "\n")
|
||||
println(io, " "^margin, "|", line)
|
||||
end
|
||||
end
|
||||
|
||||
function term(io::IO, md::List, columns)
|
||||
for (i, point) in enumerate(md.items)
|
||||
print(io, " "^2margin, isordered(md) ? "$(i + md.ordered - 1). " : "• ")
|
||||
print_wrapped(io, width = columns-(4margin+2), pre = " "^(2margin+2),
|
||||
i = 2margin+2) do io
|
||||
term(io, point, columns - 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function _term_header(io::IO, md, char, columns)
|
||||
text = terminline(md.text)
|
||||
with_output_format(:bold, io) do io
|
||||
print(io, " "^(2margin), " ")
|
||||
line_no, lastline_width = print_wrapped(io, text,
|
||||
width=columns - 4margin; pre=" ")
|
||||
line_width = min(1 + lastline_width, columns)
|
||||
if line_no > 1
|
||||
line_width = max(line_width, div(columns, 3))
|
||||
end
|
||||
char != ' ' && println(io, " "^(2margin), string(char) ^ line_width)
|
||||
end
|
||||
end
|
||||
|
||||
const _header_underlines = collect("≡=–-⋅ ")
|
||||
# TODO settle on another option with unicode e.g. "≡=≃–∼⋅" ?
|
||||
|
||||
function term{l}(io::IO, md::Header{l}, columns)
|
||||
underline = _header_underlines[l]
|
||||
_term_header(io, md, underline, columns)
|
||||
end
|
||||
|
||||
function term(io::IO, md::Code, columns)
|
||||
with_output_format(:cyan, io) do io
|
||||
for line in lines(md.code)
|
||||
print(io, " "^margin)
|
||||
println(io, line)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function term(io::IO, br::LineBreak, columns)
|
||||
println(io)
|
||||
end
|
||||
|
||||
function term(io::IO, br::HorizontalRule, columns)
|
||||
println(io, " " ^ margin, "-" ^ (columns - 2margin))
|
||||
end
|
||||
|
||||
term(io::IO, x, _) = show(io, MIME"text/plain"(), x)
|
||||
|
||||
# Inline Content
|
||||
|
||||
terminline(md) = sprint(terminline, md)
|
||||
|
||||
function terminline(io::IO, content::Vector)
|
||||
for md in content
|
||||
terminline(io, md)
|
||||
end
|
||||
end
|
||||
|
||||
function terminline(io::IO, md::AbstractString)
|
||||
print(io, replace(md, r"[\s\t\n]+", " "))
|
||||
end
|
||||
|
||||
function terminline(io::IO, md::Bold)
|
||||
with_output_format(:bold, terminline, io, md.text)
|
||||
end
|
||||
|
||||
function terminline(io::IO, md::Italic)
|
||||
with_output_format(:underline, terminline, io, md.text)
|
||||
end
|
||||
|
||||
function terminline(io::IO, md::LineBreak)
|
||||
println(io)
|
||||
end
|
||||
|
||||
function terminline(io::IO, md::Image)
|
||||
terminline(io, "(Image: $(md.alt))")
|
||||
end
|
||||
|
||||
terminline(io::IO, f::Footnote) = with_output_format(:bold, terminline, io, "[^$(f.id)]")
|
||||
|
||||
function terminline(io::IO, md::Link)
|
||||
terminline(io, md.text)
|
||||
end
|
||||
|
||||
function terminline(io::IO, code::Code)
|
||||
print_with_format(:cyan, io, code.code)
|
||||
end
|
||||
|
||||
terminline(io::IO, x) = show(io, MIME"text/plain"(), x)
|
||||
|
||||
# Show in terminal
|
||||
|
||||
Base.display(d::Base.REPL.REPLDisplay, md::MD) = term(Base.REPL.outstream(d.repl), md)
|
||||
Reference in New Issue
Block a user