Skip to content

Commit

Permalink
Reorganize code in src/markdown.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi committed Jul 4, 2022
1 parent 7bc28b3 commit e515b48
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,34 @@ Supertype of all Markdown AST inline types.
"""
abstract type AbstractInline <: AbstractElement end

"""
isblock(element::AbstractElement) -> Bool
Determines if `element` is a block element (a subtype of [`AbstractBlock`](@ref)).
"""
function isblock end
isblock(::AbstractBlock) = true
isblock(::AbstractInline) = false

"""
isinline(element::AbstractElement) -> Bool
Determines if `element` is an inline element (a subtype of [`AbstractInline`](@ref)).
"""
function isinline end
isinline(::AbstractBlock) = false
isinline(::AbstractInline) = true

"""
iscontainer(::T) where {T <: AbstractElement} -> Bool
Determines if the particular Markdown element is a container, meaning that is can contain
child nodes. Adding child nodes to non-container (leaf) nodes is prohibited.
By default, each user-defined element is assumed to be a leaf node by default, and each
container node should override this method.
By default, each user-defined element is assumed to be a leaf node, and each container node
should override this method.
"""
function iscontainer end

iscontainer(::AbstractElement) = false

"""
Expand All @@ -68,7 +85,6 @@ elements that are only allowed to have inline child elements or to make sure tha
If the `parent` element is a leaf node (`iscontainer(parent) === false`)
"""
function can_contain end

# These methods ensure that, by default, container blocks/inlines are allowed to contain
# any blocks/inlines (respectively):
can_contain(parent::AbstractBlock, child::AbstractBlock) = iscontainer(parent)
Expand All @@ -77,24 +93,6 @@ can_contain(parent::AbstractInline, child::AbstractInline) = iscontainer(parent)
# overridden):
can_contain(parent::AbstractElement, child::AbstractElement) = false

"""
isblock(element::AbstractElement) -> Bool
Determines if `element` is a block element (a subtype of [`AbstractBlock`](@ref)).
"""
function isblock end
isblock(::AbstractBlock) = true
isblock(::AbstractInline) = false

"""
isinline(element::AbstractElement) -> Bool
Determines if `element` is an inline element (a subtype of [`AbstractInline`](@ref)).
"""
function isinline end
isinline(::AbstractBlock) = false
isinline(::AbstractInline) = true

"""
struct Document <: AbstractBlock
Expand Down

0 comments on commit e515b48

Please sign in to comment.