Skip to content

Commit

Permalink
Allow escaped | chars in tables
Browse files Browse the repository at this point in the history
Markdown tables might require literal `|` to be written within a
cell, such as when writing the function `|`. This allows `|`
to be escaped using a `\`.
  • Loading branch information
MichaelHatherly committed Jul 24, 2016
1 parent 302e0b8 commit 1558896
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions base/markdown/GitHub/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ end
function parserow(stream::IO)
withstream(stream) do
line = readline(stream) |> chomp
row = split(line, "|")
row = split(line, r"(?<!\\)\|")
length(row) == 1 && return
row[1] == "" && shift!(row)
map!(strip, row)
map!(x -> strip(replace(x, "\\|", "|")), row)
row[end] == "" && pop!(row)
return row
end
Expand Down Expand Up @@ -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, "| ")
Expand Down
9 changes: 9 additions & 0 deletions test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1558896

Please sign in to comment.