Skip to content

Commit

Permalink
Move markdown types into their own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
hayd committed May 20, 2015
1 parent 8f7531b commit 8e3d178
Show file tree
Hide file tree
Showing 25 changed files with 698 additions and 730 deletions.
17 changes: 14 additions & 3 deletions base/markdown/Common/Common.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

include("block.jl")
include("inline.jl")
include("blockquote.jl")
include("bold.jl")
include("code.jl")
include("escapes.jl")
include("header.jl")
include("horizontalrule.jl")
include("image.jl")
include("italic.jl")
include("linebreak.jl")
include("link.jl")
include("list.jl")
include("paragraph.jl")
include("vector.jl")

@flavor common [list, indentcode, blockquote, hashheader, horizontalrule,
paragraph,
fencedcode, paragraph,

linebreak, escapes, inline_code,
asterisk_bold, asterisk_italic, image, link]
238 changes: 0 additions & 238 deletions base/markdown/Common/block.jl

This file was deleted.

45 changes: 45 additions & 0 deletions base/markdown/Common/blockquote.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
type BlockQuote
content
end

BlockQuote() = BlockQuote([])

# TODO: Laziness
@breaking true ->
function blockquote(stream::IO, block::MD)
withstream(stream) do
buffer = IOBuffer()
empty = true
while eatindent(stream) && startswith(stream, '>')
startswith(stream, " ")
write(buffer, readline(stream))
empty = false
end
empty && return false

md = takebuf_string(buffer)
push!(block, BlockQuote(parse(md, flavor = config(block)).content))
return true
end
end

function html(io::IO, md::BlockQuote)
withtag(io, :blockquote) do
println(io)
html(io, md.content)
end
end

function latex(io::IO, md::BlockQuote)
wrapblock(io, "quote") do
latex(io, md.content)
end
end

function term(io::IO, md::BlockQuote, columns)
s = sprint(io->term(io, md.content, columns - 10))
for line in split(rstrip(s), "\n")
println(io, " "^margin, "|", line)
end
println(io)
end
27 changes: 27 additions & 0 deletions base/markdown/Common/bold.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type Bold
text
end

@trigger '*' ->
function asterisk_bold(stream::IO, md::MD)
result = parse_inline_wrapper(stream, "**")
return result == nothing ? nothing : Bold(parseinline(result, md))
end

function htmlinline(io::IO, md::Bold)
withtag(io, :strong) do
htmlinline(io, md.text)
end
end

function latexinline(io::IO, md::Bold)
wrapinline(io, "textbf") do
latexinline(io, md.text)
end
end

plaininline(io::IO, md::Bold) = plaininline(io, "**", md.text, "**")

function terminline(io::IO, md::Bold)
with_output_format(:bold, terminline, io, md.text)
end
Loading

0 comments on commit 8e3d178

Please sign in to comment.