Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move markdown types into their own file. #11421

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

52 changes: 52 additions & 0 deletions base/markdown/Common/blockquote.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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 plain(io::IO, md::BlockQuote)
print(io, "> ")
plain(io, md.content)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be implemented in a similar way to the term method below otherwise only the first line of the block will have > added. See below:

julia> a = """
       > a
       > 
       > * 1
       > * 2
       >
       > ```
       > aaa
       > ```
       """
"> a\n> \n> * 1\n> * 2\n>\n> ```\n> aaa\n> ```\n"

julia> a |> Markdown.parse |> Markdown.plain |> print
> a

  * 1
  * 2

```
aaa
```


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
29 changes: 29 additions & 0 deletions base/markdown/Common/bold.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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