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

 
 

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

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

Add a New Comment Rich Markup
   

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 Administrator
Wed 19 Jun 2019 05:20:26 PM UTC, comment #6: 

There is also a project here on gnu.org:

https://savannah.gnu.org/projects/src-highlite/

(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.

https://webdesign.tutsplus.com/articles/25-syntax-highlighters-tried-and-tested--cms-23931


Here are some links for checking out if applicable and license.


https://github.com/syntaxhighlighter (MIT License)
<pre class="brush: js">

https://github.com/PrismJS/prism (MIT License)
<pre><code class="language-javascript">

https://github.com/highlightjs/highlight.js (own license)
<pre><code class="language-javascript">

https://github.com/ccampbell/rainbow (Apache License 2.0)
<pre><code data-language="javascript">

https://github.com/google/code-prettify (Apache License 2.0)
<pre class="prettyprint">


https://sourceforge.net/projects/jush/ (LICENSE not set yet)
https://github.com/vrana/jush (LICENSE not set yet)

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

There is Python Pygments and PHPygments
https://github.com/capynet/PHPygments (own license)
and seems to be wide adopted according to http://pygments.org/faq/ . So a serverside syntax highlighting is possible. Maybe not applicable due their license or require change license needed.

My experience with GeSHi (https://github.com/GeSHi/geshi-1.0 (GPL 2) and fork https://github.com/easybook/geshi ) 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 Administrator
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:


overflow-wrap:
(former word-wrap:) see
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap

white-space:
overflow: (or overflow-x: overflow-y:)
hyphens:



example long word in a paragraph

blabla x1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

example long word in code snippet


blabla x1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789



I use currently


word-wrap:anywhere;


for the whole comment/item text/

and


overflow:auto;

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>";
  $ns--;
  while ($ns)
    {
      $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 === ' ')
                {
                  $ns++;
                  continue;
                }
              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",
            "<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>\t",
                                          $verbatim_buffer);
          $verbatim_buffer = str_replace ("\n", "<br />\n", $verbatim_buffer);

Ineiev <ineiev>
Site Administrator
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:
   
   
Comment:
   

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)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    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.13-d3ae.
    Corresponding source code