From 15588960c6d44b527156e05edf656d80954b8980 Mon Sep 17 00:00:00 2001 From: Michael Hatherly Date: Mon, 25 Jul 2016 00:35:32 +0200 Subject: [PATCH] Allow escaped `|` chars in tables Markdown tables might require literal `|` to be written within a cell, such as when writing the function `|`. This allows `|` to be escaped using a `\`. --- base/markdown/GitHub/table.jl | 8 +++++--- test/markdown.jl | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/base/markdown/GitHub/table.jl b/base/markdown/GitHub/table.jl index e4e74f152a0f4..9822aed14d1fd 100644 --- a/base/markdown/GitHub/table.jl +++ b/base/markdown/GitHub/table.jl @@ -8,10 +8,10 @@ end function parserow(stream::IO) withstream(stream) do line = readline(stream) |> chomp - row = split(line, "|") + row = split(line, r"(? strip(replace(x, "\\|", "|")), row) row[end] == "" && pop!(row) return row end @@ -103,7 +103,9 @@ _dash(width, align) = throw(ArgumentError("Invalid alignment $align")) function plain(io::IO, md::Table) - cells = mapmap(plaininline, md.rows) + cells = mapmap(md.rows) do each + replace(plaininline(each), "|", "\\|") + end padcells!(cells, md.align, len = length, min = 3) for i = indices(cells,1) print(io, "| ") diff --git a/test/markdown.jl b/test/markdown.jl index 6a12e836e6294..d854a857e40c4 100644 --- a/test/markdown.jl +++ b/test/markdown.jl @@ -362,6 +362,15 @@ let text = table = Markdown.parse(text) @test text == Markdown.plain(table) end +let text = + """ + | a | b | + |:-------- | ---:| + | `x \\| y` | 2 | + """, + table = Markdown.parse(text) + @test text == Markdown.plain(table) +end # LaTeX extension