<NME> mdflatten.jl
<BEF> module MDFlattenTests

using Test

import Markdown
using MarkdownAST: MarkdownAST, @ast
using Documenter.Utilities.MDFlatten

parse(s) = convert(MarkdownAST.Node, Markdown.parse(s))

struct UnsupportedElement <: MarkdownAST.AbstractElement end

@testset "MDFlatten" begin
    @test mdflatten(@ast(MarkdownAST.Paragraph() do; "..."; end)) == "..."
    @test mdflatten(@ast(MarkdownAST.Heading(1) do; "..."; end)) == "..."

    # a simple test for blocks in top-level (each gets two newline appended to it)
    @test mdflatten(parse("# Test\nTest")) == "Test\n\nTest\n\n"
    block_md = parse("""
    # MDFlatten test


    ^^^ Ignoring extra whitespace.

    ```markdown
    code
    is forwarded as **is**
    ```
    """)
    block_text = """
    MDFlatten test

    ^^^ Ignoring extra whitespace.

    code
    is forwarded as **is**

    """
    @test mdflatten(block_md) == block_text

    # blocks
    @test mdflatten(parse("> Test\n> Test\n\n> Test")) == "Test Test\n\nTest\n\n"
    @test mdflatten(parse("HRs\n\n---\n\nto whitespace")) == "HRs\n\n\n\nto whitespace\n\n"
    @test mdflatten(parse("HRs\n\n---\n\nto whitespace")) == "HRs\n\n\n\nto whitespace\n\n"
    @test mdflatten(parse("HRs\n\n---\n\nto whitespace")) == "HRs\n\n\n\nto whitespace\n\n"


    # Math
    @test mdflatten(Markdown.parse("\$e=mc^2\$")) == "e=mc^2\n\n"
    if VERSION > v"0.5-"
        # backticks and blocks for math only in 0.5, i.e. these fail on 0.4
        @test mdflatten(Markdown.parse("``e=mc^2``")) == "e=mc^2\n\n"
        @test mdflatten(Markdown.parse("```math\n\\(m+n)(m-n)\nx=3\\sin(x)\n```")) == "(m+n)(m-n)\nx=3sin(x)\n\n"
    end

    # symbols in markdown
    @test mdflatten(Markdown.parse("A \$B C")) == "A B C\n\n"
    @test mdflatten(parse("``e=mc^2``")) == "e=mc^2\n\n"
    @test mdflatten(parse("```math\n\\(m+n)(m-n)\nx=3\\sin(x)\n```")) == "(m+n)(m-n)\nx=3sin(x)\n\n"

    # symbols in markdown
    @test mdflatten(parse("A \$B C")) == "A B C\n\n"

    # linebreaks
    @test mdflatten(parse("A\\\nB")) == "A\nB\n\n"

    # footnotes
    @test mdflatten(parse("[^name]")) == "[name]\n\n"
    @test mdflatten(parse("[^name]:**Strong** text.")) == "[name]: Strong text.\n\n"

    # admonitions
    @test mdflatten(parse("!!! note \"Admonition Title\"\n    Test")) == "note: Admonition Title\nTest\n\n"

    @test mdflatten([@ast("x"), @ast("y"), @ast("z")]) == "xyz"
    @test_throws Exception mdflatten(@ast(UnsupportedElement()))
end

end

<MSG> remove redundant version check (#669)


<DFF> @@ -47,11 +47,9 @@ using Documenter.Utilities.MDFlatten
 
     # Math
     @test mdflatten(Markdown.parse("\$e=mc^2\$")) == "e=mc^2\n\n"
-    if VERSION > v"0.5-"
-        # backticks and blocks for math only in 0.5, i.e. these fail on 0.4
-        @test mdflatten(Markdown.parse("``e=mc^2``")) == "e=mc^2\n\n"
-        @test mdflatten(Markdown.parse("```math\n\\(m+n)(m-n)\nx=3\\sin(x)\n```")) == "(m+n)(m-n)\nx=3sin(x)\n\n"
-    end
+    # backticks and blocks for math only in 0.5, i.e. these fail on 0.4
+    @test mdflatten(Markdown.parse("``e=mc^2``")) == "e=mc^2\n\n"
+    @test mdflatten(Markdown.parse("```math\n\\(m+n)(m-n)\nx=3\\sin(x)\n```")) == "(m+n)(m-n)\nx=3sin(x)\n\n"
 
     # symbols in markdown
     @test mdflatten(Markdown.parse("A \$B C")) == "A B C\n\n"

remove redundant version check (#669)