User Tools

Site Tools


Dokuwiki Markdown Table Converter

I often seemed to be manually converting tables into markdown so I wrote a quick script to convert copy and pasted comma (or tab) seperated tables into dokuwiki table markdown.

You can try it out at this URL:

Source code

<title>Markdown Converter</title>
<style type='text/css'>
textarea { width: 100%; }
function copy_to_clipboard(id) {
<h1>Table to Markdown Convertor</h1>
<h2>Paste your table</h2>
<form method='post'>
<textarea rows='10' cols='30' name='data'></textarea>
Seperated by:
<input type='radio' value='Tab' name='csv_type' <?php if(empty($_REQUEST['csv_type']) or $_REQUEST['csv_type'] == 'Tab') echo " checked "; ?> /> Tab
<input type='radio' value='Comma' name='csv_type' <?php if(!empty($_REQUEST['csv_type']) and $_REQUEST['csv_type'] == "Comma") echo " checked "; ?> /> Comma
<input type='submit' value='Convert to Markdown' name='go' />
<input type='checkbox' value='header_row' name='header_row' /> Contains header row
<h2>Markdown output</h2>
<input type="button" value="Copy to clipboard" onclick="copy_to_clipboard('output');">
<textarea rows='20' cols='30' id='output'>
if(!empty($_REQUEST['data'])) {
   $data = explode("\n", $_REQUEST['data']);
   $seperator = "\t";
   if(!empty($_REQUEST['csv_type']) and $_REQUEST['csv_type'] == 'Comma')
      $seperator = ",";
   $output = "";
   if(!empty($_REQUEST['header_row'])) {
      $data[0] = str_replace("\r", "", $data[0]);
      $output .= "^".str_replace($seperator, "^", $data[0])."^\n";
   if(is_array($data)) {
      foreach($data as $line) {
         $stripped_line = str_replace("\r", "", $line);
         $output .= "|".str_replace($seperator, "|", $stripped_line)."|\n";
echo $output;
dokuwiki_markdown_table_converter.txt · Last modified: 2020/03/05 23:03 by admin