helpSavannah Administration - Support: sr #109696, markdown verbatim (for code...


sr #109696: markdown verbatim (for code snippets) does not respect white-space

Submitted by:  Peter Liscovius <peterdd>
Submitted on:  Thu 06 Jun 2019 06:16:28 PM UTC  
Category:  Savannah trackers - bugs, tasks, etc. Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Assigned to:  Ineiev <ineiev> Operating System:  None
Open/Closed:  Closed

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Thu 20 Jun 2019 10:18:08 AM UTC, comment #7: 

The function of +verbatim+ is to disable markup in a block of text, it isn't
supposed to be used to literally copy code from trackers (this is what
the attachments do), and it isn't intended for syntax highlighting of code
(I don't think Savane markup should support such complicated features).

Ineiev <ineiev>
Site AdministratorIn charge of this item.
Wed 19 Jun 2019 05:20:26 PM UTC, comment #6: 

There is also a project here on

(I never tried or if applicable to savane.)

Peter Liscovius <peterdd>
Wed 19 Jun 2019 05:07:35 PM UTC, comment #5: 

Someone compared available webbrowser side based javascript syntax highlighters.

They all work on code sections in the html content wrapped by pre-tags or combinations of pre+code-tags.

Here are some links for checking out if applicable and license. (MIT License)
<pre class="brush: js"> (MIT License)
<pre><code class="language-javascript"> (own license)
<pre><code class="language-javascript"> (Apache License 2.0)
<pre><code data-language="javascript"> (Apache License 2.0)
<pre class="prettyprint"> (LICENSE not set yet) (LICENSE not set yet)

And then there are server side parsers, which are - ummh -  special:

There is Python Pygments and PHPygments (own license)
and seems to be wide adopted according to . So a serverside syntax highlighting is possible. Maybe not applicable due their license or require change license needed.

My experience with GeSHi ( (GPL 2) and fork ) which is used by Dokuwiki and Flyspray: Slow and not solid as I wish (slowiness mitigated by caching to file/database unless origin content changes). Probably will replace it in future.

Peter Liscovius <peterdd>
Wed 19 Jun 2019 02:36:24 PM UTC, comment #4: 

Hello Ineiev,

this is not solved yet.

It converts tabs to &nbsp; too.

As the verbatim section is for nonmodifying code sections that can be copied simple by selection areas with mouse for instance, I really suggest using the pre tag and only cleanup for output with something like htmlspecialchars().

Using the pre tag here is better than p paragraph tag (semantic and by default css of web browsers)

Please do not fiddle with the content inside the verbatim tag if possible.

As I suggested earlier, layout breaks by nasty long or height code sections can be tamed by CSS.

If this is not convincing enough, take a look at other webbased trackers.

Peter Liscovius <peterdd>
Mon 10 Jun 2019 06:52:17 AM UTC, comment #3: 

Long words is a different issue; as you noticed, it applies both to verbatim and non-verbatim parts.

Ineiev <ineiev>
Site AdministratorIn charge of this item.
Sat 08 Jun 2019 09:03:39 AM UTC, comment #2: 

> First, we want to wrap those verbatim elements at reasonable width --- if they aren't, long lines break rendering of whole item.

I do not think it is necessary to change the content except XSS filter before output. CSS has ammunition to handle overlong nasty strings for output not destroying the layout and preserving whitespace in code snippets:

(former word-wrap:) see

overflow: (or overflow-x: overflow-y:)

example long word in a paragraph

blabla x1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

example long word in code snippet

blabla x1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

I use currently


for the whole comment/item text/



for code section

> Then, it's desirable to make this work with CSS-unaware browsers as well.

??? example?

Peter Liscovius <peterdd>
Fri 07 Jun 2019 07:34:56 AM UTC, comment #1: 

First, we want to wrap those verbatim elements at reasonable width --- if they aren't, long lines break rendering of whole item.

Then, it's desirable to make this work with CSS-unaware browsers as well. I'd rather reformat spaces using &nbsp; like this:

function markup_verbatim_spaces ($ns)
  if ($ns < 1)
    return "";
  if ($ns < 2)
    return " ";
  $ret = " <span>";
  while ($ns)
      $ret .= '&nbsp;';
  return $ret . "</span>";
          $verbatim_buffer = str_replace ("\r\n", "\n", $verbatim_buffer);
          $verbatim_buffer = str_replace ("\n\r", "\n", $verbatim_buffer);
          $verbatim_buffer = str_replace ("\r", "\n", $verbatim_buffer);
          # Hopefully preserve spaces in HTML allowing line breaking.
          $verb_out = "";
          $ns = 0;
          for ($i = 0; $i < strlen ($verbatim_buffer); $i++)
              $next_char = substr ($verbatim_buffer, $i, 1);
              if ($next_char === ' ')
              if ($ns)
                  $verb_out .= markup_verbatim_spaces ($ns);
                  $ns = 0;
              $verb_out .= $next_char;
          $verbatim_buffer = $verb_out . markup_verbatim_spaces ($ns);

          $verbatim_buffer = str_replace ("\t",
          $verbatim_buffer = str_replace ("\n", "<br />\n", $verbatim_buffer);

Ineiev <ineiev>
Site AdministratorIn charge of this item.
Thu 06 Jun 2019 06:16:28 PM UTC, original submission:  

spaces (single space, tabs, ..) are not preserved in output of savane markdown verbatim areas.

Easiest solution is to replace the p-tag within the blockquote-tag by a pre-tag, that has CSS

display: block;
font-family: monospace;
white-space: pre;

by default in web browsers.

And then there is no need for putting extra br-tags there too.

Peter Liscovius <peterdd>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by ineiev (Posted a comment)
  • -email is unavailable- added by peterdd (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-17 ineiev StatusIn Progress => Done
        Open/ClosedOpen => Closed
    2019-06-07 ineiev StatusNone => In Progress
        Assigned toNone => ineiev

    Back to the top

    Powered by Savane 3.5