<commit_before># GitHub markdown
# ---------------

Base.@kwdef mutable struct GitHubMarkdown <: WeaveFormat
    description = "GitHub Markdown"
    extension = "md"
    codestart = "````julia"
    codeend = "````\n\n"
    termstart = codestart
    termend = codeend
    outputstart = "````"
    outputend = "````\n\n"
    fig_ext = ".png"
    mimetypes = ["image/png", "image/svg+xml", "image/jpg",
                "text/markdown", "text/plain"]
    out_width = nothing
    out_height = nothing
    fig_pos = nothing
    fig_env = nothing
    # specials
    preserve_header = true
end
register_format!("github", GitHubMarkdown())

function render_figures(docformat::GitHubMarkdown, chunk)
    fignames = chunk.figures
    caption = chunk.options[:fig_cap]
    result = ""
    figstring = ""

    length(fignames) > 0 || (return "")

    if !isnothing(caption)
        result *= "![$caption]($(fignames[1]))\n"
        for fig in fignames[2:end]
            result *= "![]($fig)\n"
            println("Warning, only the first figure gets a caption\n")
        end
    else
        for fig in fignames
            result *= "![]($fig)\n"
        end
    end
    return result
end

# Hugo markdown
# -------------

Base.@kwdef mutable struct Hugo <: WeaveFormat
    description = "Hugo Markdown (using shortcodes)"
    extension = "md"
    codestart = "````julia"
    codeend = "````\n\n"
    termstart = codestart
    termend = codeend
    outputstart = "````"
    outputend = "````\n\n"
    mimetypes = default_mime_types
    fig_ext = ".png"
    out_width = nothing
    out_height = nothing
    fig_pos = nothing
    fig_env = nothing
    # specials
    preserve_header = true
    uglyURLs = false # if `false`, prepend figure path by `..`
end
register_format!("hugo", Hugo())

function render_figures(docformat::Hugo, chunk)
    relpath = docformat.uglyURLs ? "" : ".."
    mapreduce(*, enumerate(chunk.figures), init = "") do (index, fig)
        if index > 1
            @warn("Only the first figure gets a caption.")
            title_spec = ""
        else
            caption = chunk.options[:fig_cap]
            title_spec = isnothing(caption) ? "" : "title=\"$(caption)\" "
        end
        "{{< figure src=\"$(joinpath(relpath, fig))\" $(title_spec) >}}"
    end
end

# multi language markdown
# -----------------------

Base.@kwdef mutable struct MultiMarkdown <: WeaveFormat
    description = "MultiMarkdown"
    extension = "md"
    codestart = "````julia"
    codeend = "````\n\n"
    termstart = codestart
    termend = codeend
    outputstart = "````"
    outputend = "````\n\n"
    mimetypes = default_mime_types
    fig_ext = ".png"
    out_width = nothing
    out_height = nothing
    fig_pos = nothing
    fig_env = nothing
    # specials
    preserve_header = true
end
register_format!("multimarkdown", MultiMarkdown())

function render_figures(docformat::MultiMarkdown, chunk)
    fignames = chunk.figures
    caption = chunk.options[:fig_cap]
    result = ""
    figstring = ""

    if chunk.options[:out_width] == nothing
        width = ""
    else
        width = "width=$(chunk.options[:out_width])"
    end<commit_msg>triple quote for markdown output<commit_after># GitHub markdown
# ---------------

Base.@kwdef mutable struct GitHubMarkdown <: WeaveFormat
    description = "GitHub Markdown"
    extension = "md"
    codestart = "```julia"
    codeend = "```\n\n"
    termstart = codestart
    termend = codeend
    outputstart = "```"
    outputend = "```\n\n"
    fig_ext = ".png"
    mimetypes = ["image/png", "image/svg+xml", "image/jpg",
                "text/markdown", "text/plain"]
    out_width = nothing
    out_height = nothing
    fig_pos = nothing
    fig_env = nothing
    # specials
    preserve_header = true
end
register_format!("github", GitHubMarkdown())

function render_figures(docformat::GitHubMarkdown, chunk)
    fignames = chunk.figures
    caption = chunk.options[:fig_cap]
    result = ""
    figstring = ""

    length(fignames) > 0 || (return "")

    if !isnothing(caption)
        result *= "![$caption]($(fignames[1]))\n"
        for fig in fignames[2:end]
            result *= "![]($fig)\n"
            println("Warning, only the first figure gets a caption\n")
        end
    else
        for fig in fignames
            result *= "![]($fig)\n"
        end
    end
    return result
end

# Hugo markdown
# -------------

Base.@kwdef mutable struct Hugo <: WeaveFormat
    description = "Hugo Markdown (using shortcodes)"
    extension = "md"
    codestart = "```julia"
    codeend = "```\n\n"
    termstart = codestart
    termend = codeend
    outputstart = "```"
    outputend = "```\n\n"
    mimetypes = default_mime_types
    fig_ext = ".png"
    out_width = nothing
    out_height = nothing
    fig_pos = nothing
    fig_env = nothing
    # specials
    preserve_header = true
    uglyURLs = false # if `false`, prepend figure path by `..`
end
register_format!("hugo", Hugo())

function render_figures(docformat::Hugo, chunk)
    relpath = docformat.uglyURLs ? "" : ".."
    mapreduce(*, enumerate(chunk.figures), init = "") do (index, fig)
        if index > 1
            @warn("Only the first figure gets a caption.")
            title_spec = ""
        else
            caption = chunk.options[:fig_cap]
            title_spec = isnothing(caption) ? "" : "title=\"$(caption)\" "
        end
        "{{< figure src=\"$(joinpath(relpath, fig))\" $(title_spec) >}}"
    end
end

# multi language markdown
# -----------------------

Base.@kwdef mutable struct MultiMarkdown <: WeaveFormat
    description = "MultiMarkdown"
    extension = "md"
    codestart = "```julia"
    codeend = "```\n\n"
    termstart = codestart
    termend = codeend
    outputstart = "```"
    outputend = "```\n\n"
    mimetypes = default_mime_types
    fig_ext = ".png"
    out_width = nothing
    out_height = nothing
    fig_pos = nothing
    fig_env = nothing
    # specials
    preserve_header = true
end
register_format!("multimarkdown", MultiMarkdown())

function render_figures(docformat::MultiMarkdown, chunk)
    fignames = chunk.figures
    caption = chunk.options[:fig_cap]
    result = ""
    figstring = ""

    if chunk.options[:out_width] == nothing
        width = ""
    else
        width = "width=$(chunk.options[:out_width])"
    end
{'fraction_non_alphanumeric': 0.15026153114598192, 'fraction_numerical': 0.0012680297987002695, 'mean_word_length': 2.480419194704909, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '639000', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1998, 'n_words': 469}