Skip to content

Commit

Permalink
Introduce MarkdownElement abstract type
Browse files Browse the repository at this point in the history
It's convenient for dispatch.
  • Loading branch information
tecosaur committed Oct 29, 2023
1 parent 98542d7 commit 1b47feb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions stdlib/Markdown/src/Common/Common.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

abstract type MarkdownElement end

include("block.jl")
include("inline.jl")

Expand Down
16 changes: 8 additions & 8 deletions stdlib/Markdown/src/Common/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Paragraphs
# ––––––––––

mutable struct Paragraph
mutable struct Paragraph <: MarkdownElement
content
end

Expand Down Expand Up @@ -39,7 +39,7 @@ end
# Headers
# –––––––

mutable struct Header{level}
mutable struct Header{level} <: MarkdownElement
text
end

Expand Down Expand Up @@ -95,7 +95,7 @@ end
# Code
# ––––

mutable struct Code
mutable struct Code <: MarkdownElement
language::String
code::String
end
Expand Down Expand Up @@ -124,7 +124,7 @@ end
# Footnote
# --------

mutable struct Footnote
mutable struct Footnote <: MarkdownElement
id::String
text
end
Expand Down Expand Up @@ -159,7 +159,7 @@ end
# Quotes
# ––––––

mutable struct BlockQuote
mutable struct BlockQuote <: MarkdownElement
content
end

Expand Down Expand Up @@ -188,7 +188,7 @@ end
# Admonitions
# -----------

mutable struct Admonition
mutable struct Admonition <: MarkdownElement
category::String
title::String
content::Vector
Expand Down Expand Up @@ -246,7 +246,7 @@ end
# Lists
# –––––

mutable struct List
mutable struct List <: MarkdownElement
items::Vector{Any}
ordered::Int # `-1` is unordered, `>= 0` is ordered.
loose::Bool # TODO: Renderers should use this field
Expand Down Expand Up @@ -332,7 +332,7 @@ pushitem!(list, buffer) = push!(list.items, parse(String(take!(buffer))).content
# HorizontalRule
# ––––––––––––––

mutable struct HorizontalRule
mutable struct HorizontalRule <: MarkdownElement
end

function horizontalrule(stream::IO, block::MD)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/Markdown/src/Common/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Emphasis
# ––––––––

mutable struct Italic
mutable struct Italic <: MarkdownElement
text
end

Expand All @@ -20,7 +20,7 @@ function underscore_italic(stream::IO, md::MD)
return result === nothing ? nothing : Italic(parseinline(result, md))
end

mutable struct Bold
mutable struct Bold <: MarkdownElement
text
end

Expand Down Expand Up @@ -66,7 +66,7 @@ end
# Images & Links
# ––––––––––––––

mutable struct Image
mutable struct Image <: MarkdownElement
url::String
alt::String
end
Expand All @@ -85,7 +85,7 @@ function image(stream::IO, md::MD)
end
end

mutable struct Link
mutable struct Link <: MarkdownElement
text
url::String
end
Expand Down Expand Up @@ -156,7 +156,7 @@ end
# Punctuation
# –––––––––––

mutable struct LineBreak end
mutable struct LineBreak <: MarkdownElement end

@trigger '\\' ->
function linebreak(stream::IO, md::MD)
Expand Down

0 comments on commit 1b47feb

Please sign in to comment.