"Fossies" - the Fresh Open Source Software Archive

Member "julia-1.1.1/share/julia/stdlib/v1.1/Markdown/src/render/plain.jl" (16 May 2019, 3823 Bytes) of package /linux/misc/julia-1.1.1-linux-i686.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Julia source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is a part of Julia. License is MIT: https://julialang.org/license
    2 
    3 plain(x) = sprint(plain, x)
    4 
    5 function plain(io::IO, content::Vector)
    6     isempty(content) && return
    7     for md in content[1:end-1]
    8         plain(io, md)
    9         println(io)
   10     end
   11     plain(io, content[end])
   12 end
   13 
   14 plain(io::IO, md::MD) = plain(io, md.content)
   15 
   16 function plain(io::IO, header::Header{l}) where l
   17     print(io, "#"^l*" ")
   18     plaininline(io, header.text)
   19     println(io)
   20 end
   21 
   22 function plain(io::IO, code::Code)
   23     # If the code includes a fenced block this will break parsing,
   24     # so it must be enclosed by a longer ````-sequence.
   25     n = mapreduce(m -> length(m.match), max, eachmatch(r"^`+"m, code.code); init=2) + 1
   26     println(io, "`" ^ n, code.language)
   27     println(io, code.code)
   28     println(io, "`" ^ n)
   29 end
   30 
   31 function plain(io::IO, p::Paragraph)
   32     plaininline(io, p.content)
   33     println(io)
   34 end
   35 
   36 function plain(io::IO, list::List)
   37     for (i, item) in enumerate(list.items)
   38         print(io, isordered(list) ? "$(i + list.ordered - 1). " : "  * ")
   39         lines = split(rstrip(sprint(plain, item)), "\n")
   40         for (n, line) in enumerate(lines)
   41             print(io, (n == 1 || isempty(line)) ? "" : "    ", line)
   42             n < length(lines) && println(io)
   43         end
   44         println(io)
   45     end
   46 end
   47 
   48 function plain(io::IO, q::BlockQuote)
   49     s = sprint(plain, q.content)
   50     for line in split(rstrip(s), "\n")
   51         println(io, isempty(line) ? ">" : "> ", line)
   52     end
   53     println(io)
   54 end
   55 
   56 function plain(io::IO, f::Footnote)
   57     print(io, "[^", f.id, "]:")
   58     s = sprint(plain, f.text)
   59     lines = split(rstrip(s), "\n")
   60     # Single line footnotes are printed on the same line as their label
   61     # rather than taking up an additional line.
   62     if length(lines) == 1
   63         println(io, " ", lines[1])
   64     else
   65         println(io)
   66         for line in lines
   67             println(io, isempty(line) ? "" : "    ", line)
   68         end
   69         println(io)
   70     end
   71 end
   72 
   73 function plain(io::IO, md::Admonition)
   74     s = sprint(plain, md.content)
   75     title = md.title == uppercasefirst(md.category) ? "" : " \"$(md.title)\""
   76     println(io, "!!! ", md.category, title)
   77     for line in split(rstrip(s), "\n")
   78         println(io, isempty(line) ? "" : "    ", line)
   79     end
   80     println(io)
   81 end
   82 
   83 function plain(io::IO, md::HorizontalRule)
   84     println(io, "-" ^ 3)
   85 end
   86 
   87 function plain(io::IO, l::LaTeX)
   88     println(io, '$', '$')
   89     println(io, l.formula)
   90     println(io, '$', '$')
   91 end
   92 
   93 function plain(io::IO, md)
   94     show(io,  MIME"text/plain"(), md)
   95     println(io)
   96 end
   97 
   98 # Inline elements
   99 
  100 plaininline(x) = sprint(plaininline, x)
  101 
  102 function plaininline(io::IO, md...)
  103     for el in md
  104         plaininline(io, el)
  105     end
  106 end
  107 
  108 plaininline(io::IO, md::Vector) = !isempty(md) && plaininline(io, md...)
  109 
  110 plaininline(io::IO, f::Footnote) = print(io, "[^", f.id, "]")
  111 
  112 plaininline(io::IO, link::Link) = plaininline(io, "[", link.text, "](", link.url, ")")
  113 
  114 plaininline(io::IO, md::Image) = plaininline(io, "![", md.alt, "](", md.url, ")")
  115 
  116 plaininline(io::IO, s::AbstractString) = print(io, s)
  117 
  118 plaininline(io::IO, md::Bold) = plaininline(io, "**", md.text, "**")
  119 
  120 plaininline(io::IO, md::Italic) = plaininline(io, "*", md.text, "*")
  121 
  122 function plaininline(io::IO, md::Code)
  123     if occursin("`", md.code)
  124         n = maximum(length(m.match) for m in eachmatch(r"(`+)", md.code))
  125         s = "`"^((iseven(n) ? 1 : 2) + n)
  126         print(io, s, Base.startswith(md.code, "`") ? " " : "")
  127         print(io, md.code, endswith(md.code, "`") ? " " : "", s)
  128     else
  129         print(io, "`", md.code, "`")
  130     end
  131 end
  132 
  133 plaininline(io::IO, br::LineBreak) = println(io)
  134 
  135 plaininline(io::IO, x) = show(io, MIME"text/plain"(), x)
  136 
  137 # show
  138 
  139 Base.show(io::IO, md::MD) = plain(io, md)
  140 Base.show(io::IO, ::MIME"text/markdown", md::MD) = plain(io, md)