Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# MarkdownAST.jl changelog

## Version `Unreleased`

* ![Feature][badge-feature] Added support for `Strikethrough` nodes when converting to/from the Markdown stdlib AST. This interop requires Julia 1.14+, because `Markdown.Strikethrough` is only available in the stdlib starting there. ([#31][github-31], [#32][github-32])

## Version `v0.1.2`

* ![Feature][badge-feature] Implemented `replace` and `replace!` to safely mutate trees in arbitrary ways, and `empty!(node.children)` to remove all the children of a node. ([#22][github-22])
Expand All @@ -17,6 +21,8 @@ Initial release.
[github-16]: https://github.com/JuliaDocs/MarkdownAST.jl/pull/16
[github-19]: https://github.com/JuliaDocs/MarkdownAST.jl/pull/19
[github-22]: https://github.com/JuliaDocs/MarkdownAST.jl/pull/22
[github-31]: https://github.com/JuliaDocs/MarkdownAST.jl/issues/31
[github-32]: https://github.com/JuliaDocs/MarkdownAST.jl/pull/32
<!-- end of issue link definitions -->

[markdownast]: https://github.com/JuliaDocs/MarkdownAST.jl
Expand Down
1 change: 1 addition & 0 deletions docs/src/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ List
Paragraph
SoftBreak
Strong
Strikethrough
Text
ThematicBreak
```
Expand Down
8 changes: 8 additions & 0 deletions src/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ Inline singleton element for strong (e.g. bold) styling.
struct Strong <: AbstractInline end
iscontainer(::Strong) = true

"""
struct Strikethrough <: AbstractInline

Inline singleton element for strikethrough styling.
"""
struct Strikethrough <: AbstractInline end
iscontainer(::Strikethrough) = true

"""
mutable struct Code <: AbstractInline

Expand Down
3 changes: 3 additions & 0 deletions src/stdlib/fromstdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ end
# Inline nodes:
_convert_inline(nodefn::NodeFn, s::Markdown.Bold) = _convert(nodefn, Strong(), _convert_inline, s.text)
_convert_inline(nodefn::NodeFn, s::Markdown.Italic) = _convert(nodefn, Emph(), _convert_inline, s.text)
@static if isdefined(Markdown, :Strikethrough)
_convert_inline(nodefn::NodeFn, s::Markdown.Strikethrough) = _convert(nodefn, Strikethrough(), _convert_inline, s.text)
end
function _convert_inline(nodefn::NodeFn, s::Markdown.Link)
# The Base Markdown parser does not parse the title part, so we just default that to
# an empty string.
Expand Down
7 changes: 7 additions & 0 deletions src/stdlib/tostdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ _convert_element(::Node, e::InlineMath) = Markdown.LaTeX(e.math)
_convert_element(::Node, e::JuliaValue) = e.ref
_convert_element(n::Node, e::Link) = Markdown.Link(_convert_element.(n.children), e.destination)
_convert_element(n::Node, ::Strong) = Markdown.Bold(_convert_element.(n.children))
@static if isdefined(Markdown, :Strikethrough)
_convert_element(n::Node, ::Strikethrough) = Markdown.Strikethrough(_convert_element.(n.children))
else
function _convert_element(::Node, ::Strikethrough)
error("Unable to convert Strikethrough to Markdown stdlib on this Julia version")
end
end
_convert_element(::Node, e::Text) = e.text
# Lists
_convert_element(n::Node, e::List) = Markdown.List(
Expand Down
10 changes: 9 additions & 1 deletion test/fromstdlib.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MarkdownAST: MarkdownAST, Node, @ast, Document,
Emph, Strong, InlineMath, Link, Code, Image,
Emph, Strong, Strikethrough, InlineMath, Link, Code, Image,
Paragraph, Heading, CodeBlock, BlockQuote, DisplayMath, ThematicBreak,
List, Item, FootnoteLink, FootnoteDefinition, Admonition,
Table, TableHeader, TableBody, TableRow, TableCell,
Expand Down Expand Up @@ -49,6 +49,14 @@ using Test
end
end

@static if isdefined(Markdown, :Strikethrough)
@test convert(Node, Markdown.parse("~~xxx~~")) == @ast Document() do
Paragraph() do
Strikethrough() do; "xxx"; end
end
end
end

# Top-level elements
@test convert(Node, Markdown.md"""
p1
Expand Down
4 changes: 2 additions & 2 deletions test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using MarkdownAST: AbstractElement, AbstractBlock, AbstractInline,
Document,
Admonition, BlockQuote, CodeBlock, DisplayMath, FootnoteDefinition, HTMLBlock, Heading,
Item, List, Paragraph, ThematicBreak,
Code, Emph, FootnoteLink, HTMLInline, Image, InlineMath, Link, Strong, JuliaValue,
Code, Emph, FootnoteLink, HTMLInline, Image, InlineMath, Link, Strong, Strikethrough, JuliaValue,
TableComponent, Table, TableHeader, TableBody, TableRow, TableCell,
LineBreak, SoftBreak, Backslash,
iscontainer, can_contain, isblock, isinline
Expand Down Expand Up @@ -87,7 +87,7 @@ MarkdownAST.iscontainer(e::PseudoInline) = e.iscontainer
end

# (4) Inlines containing inlines:
for e in [Link("url", "title"), Image("url", "title"), Emph(), Strong()]
for e in [Link("url", "title"), Image("url", "title"), Emph(), Strong(), Strikethrough()]
@test iscontainer(e)
@test ! isblock(e)
@test isinline(e)
Expand Down
18 changes: 17 additions & 1 deletion test/tostdlib.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MarkdownAST: MarkdownAST, Node, @ast, Document,
Emph, Strong, InlineMath, Link, Code, Image,
Emph, Strong, Strikethrough, InlineMath, Link, Code, Image,
Paragraph, Heading, CodeBlock, BlockQuote, DisplayMath, ThematicBreak,
List, Item, FootnoteLink, FootnoteDefinition, Admonition,
Table, TableHeader, TableBody, TableRow, TableCell,
Expand Down Expand Up @@ -91,6 +91,22 @@ struct UnknownBlock <: MarkdownAST.AbstractBlock end
@test ast == convert(Node, md)
end

let ast = @ast Document() do
Paragraph() do
"pre "
Strikethrough() do; "mid"; end
" post"
end
end
if isdefined(Markdown, :Strikethrough)
md = convert(Markdown.MD, ast)
@test md.content[1].content[2] isa Markdown.Strikethrough
@test convert(Node, md) == ast
else
@test_throws ErrorException convert(Markdown.MD, ast)
end
end

# JuliaValue
let ast = @ast Document() do
Paragraph() do
Expand Down
Loading