DannyBen / madness

Instant Markdown Server
https://madness.dannyb.co
MIT License
128 stars 19 forks source link

Escape characters in a table #166

Closed xorguy closed 7 months ago

xorguy commented 7 months ago

Hi.

I tried to use a table where an entry contains a password set with ` and contains symbols, when one of the symbols of the password is a | , even it have been escaped with \ it is not taken into account and | changes to the next column.

I have attached an image of the code. pastebin

Is it possible to set somehow a piece of text in a way that is not parsed for markdown?

DannyBen commented 7 months ago

This seems to be a bug in redcarpet (the markdown renderer madness uses).

This ruby code demonstrates the problem:

require 'redcarpet'
redcarpet_options = { tables: true }
redcarpet_renderer = Redcarpet::Render::HTML.new
markdown = <<MARKDOWN
| User  | Password |
|-------|----------|
| admin | a\|b     |
| admin | `a\|b`   |
MARKDOWN

html = Redcarpet::Markdown.new(redcarpet_renderer, redcarpet_options).render markdown
puts html

output:

<table><thead>
<tr>
<th>User</th>
<th>Password</th>
</tr>
</thead><tbody>
<tr>
<td>admin</td>
<td>a</td>
</tr>
<tr>
<td>admin</td>
<td>`a</td>
</tr>
</tbody></table>

Is it possible to set somehow a piece of text in a way that is not parsed for markdown?

The only way I can point is the ability to show links to any document in the sidebar by enabling this feature in the settings.

# .madness.yml
# expose_extensions: pdf,docx,xlsx,txt
expose_extensions: txt

Other than this, the only advice I can offer is to either avoid pipes in passwords, or avoid displaying strings with pipes in markdown tables.

Or - of course - you can place the HTML table directly in your markdown document.

<table>
  <tr>
    <th>User</th>
    <th>Password</th>
  </tr>
  <tr>
    <td>admin</td>
    <td><code>a|b</code></td>
  </tr>
</table>
xorguy commented 7 months ago

Right, I forgot to try with HTML, it works perfect that way.

Thanks

DannyBen commented 7 months ago

I have subscribed to the redcarpet bug, if it will be fixed there (which is unlikely considering the bug is 7 years old...), I will release an update.

DannyBen commented 6 months ago

Version 1.2.0 is now released with support for pandoc as an alternative markdown renderer. When using renderer: pandoc in .madness.yml settings, this bug seems to be fixed.

The output of the problematic table line is:

<td><code>a|b</code></td>

Note that this requires having pandoc installed, but it should be as simple as brew install pandoc or any other OS package manager (apt / apk etc).

If you can confirm this works, or report that it doesn't, it will be appreciated.