I’ve upgraded my site to Kirby 3 and I noticed a lot of problems on snippets or on page’s text file related to Markdown. I.e. <p>
tag is now added on snippets and page elements. I quickly browsed forum for quick answer and I saw answers related to numbers of spaces on text. Sorry but I don’t want to count spaces around text, that is not how I thing thing should be in 2019. So I am looking to a way to complete remove Markdown parsing.
If you don’t use ->kirbytext()
or ->markdown()
on your field values, it won’t be parsed.
In this case I use ->kirbytext()
. If I stop using it then tags are not parsed… So it doesn’t solve the problem: deactivate Markdown parsing keeping tag parsing.
You could create a custom markdown component that doesn’t render anything but just returns the text as is:
<?php
Kirby::plugin('texnixe/components', [
'components' => [
'markdown' => function (Kirby $kirby, string $text = null, array $options = [], bool $inline = false) {
return $text;
}
]
]);
That will at least render Kirbytext, but nothing else. So you won’t have paragraphs anymore (i.e. same as not using kirbytext()
but with Kirbytags rendered.
Yes, that could do the trick. As I am new to Kirby I do not explore these fields for now. I’ll investigate them later to improve my skills.
Currently one way to do this is to move the part that doesn’t stand Markdown interpolation to another field. Then don’t use kirbytext()
on this new field.
What exactly is your problem with Markdown? Spaces in what context are causing problems?
I have no problem with Markdown at all. For a developper point of view taking care of number of spaces to make thing work is an aberration in my opinion and a big regression.
I have created page that fully works in Kirby 2, a page with HTML and javascript inside it. But it doesn’t work anymore in Kirby 3 because script block of code are polluted with
tags. That’s what I want to deactivate Markdown parsing.
Guess I’d have to see an example to understand what you mean, haven’t experienced that myself yet.
I wonder if it’s a problem with the markdown parser or something else causing that. It’s still Parsedown, but a different version that’s used in Kirby 3.
You could replace the markdown library with your own as well.
In the page file, I use text
field to store page content. In this content I use Leaflet API to create a map. So I add this portion of code:
---
text:
Lorem Lipsum...
<div id="carteMediathequeVA"></div>
<script>
var mymap = L.map('carteMediathequeVA').setView([44.110676231299635, 0.884074866771698], 15);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}',{
attribution: '<a href="https://www.openstreetmap.org/">OpenStreetMap</a> | <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | Images © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 19,
id: 'myMapBoxId',
accessToken: 'myPrivateToken'
}).addTo(mymap);
var marker = L.marker([44.110676231299635, 0.884074866771698]).addTo(mymap);
</script>
This doesn’t work anymore in Kirby 3 because the script block of code is Markdowned!
So I have to move it in another field:
---
text:
Lorem Lipsum...
<div id="carteMediathequeVA"></div>
---
mapScript:
<script>
var mymap = L.map('carteMediathequeVA').setView([44.110676231299635, 0.884074866771698], 15);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}',{
attribution: '<a href="https://www.openstreetmap.org/">OpenStreetMap</a> | <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> | Images © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 19,
id: 'myMapBoxId',
accessToken: 'myPrivateToken'
}).addTo(mymap);
var marker = L.marker([44.110676231299635, 0.884074866771698]).addTo(mymap);
</script>
And then in template file:
<?= $page->text()->kirbytext() ?>
<?= $page-> mapScript() ?>
I see, yeah, that’s pretty shit. And just as annoying as not being able to use spaces in snippets for Kirbytags.
I just did a quick test and included php-markdown in a component plugin. It renders the script tags OK.
So it’s probably an issue with the used version of Parsedown, but I guess it was used for a reason.
Ok, problem solved for this page. But I faced the same problem on another page in which I add a table using related HTML tags. I have to remove all leading spaces to make it work! By doing this HTML code is unreadable. That’s great! A great evolution for developer
May I suggest you create an issue on GitHub?
I won’t fill a Github report. But please let me explain why.
I am a senior developer. As it I spent countless time evangelising for good practices: 1. use you brain, 2. code, 3. test. Or invert 2. and 3. in case you want to write test cases before coding. This work and is the only way for good software. But from years now it’s like many developer skip the first step – use you brain - and the test step too. Code then put on Github. And let users do the brain work and test the software. This, is a very unefficient and poor practice. By not reporting bug I don’t want to encourage these bad practices.
What I want to do is create a small website to share my painting. Write code in good HTML, use a strong CMS to ease the tricky part and that’s all. But today I lose hours because of a poor piece of software. It’s like I’ve been stolen of these hours because someone, somewhere did not want to spend this time to create good software. One can answer me: “Let’s do it yourself if you are so clever”. I’ve already do that many many times.
The problem lie with Parsedown. Let’s go to the testing page – https://parsedown.org/demo– and add the code hereafter. PHP Markdown does the job as Parsedown no. Even better, Markdown is faster!
<table border="0px"
cellspacing="0px"
style="text-align : center;
empty-cells : hide;"
>
<colgroup>
<col width="80px" />
<col width="24px" />
<col width="24px" />
<col width="24px" />
<col width="24px" />
<col width="24px" />
<col width="24px" />
<col width="24px" />
<col width="700px" />
</colgroup>
<tr>
<td></td>
<td colspan="6"><strong>segments</strong></td>
</tr>
<tr>
<td><strong>steps</strong></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>1</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td></td>
<td class="explanation">all segments are displayed in the darkest green [A]</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>2</td>
<td class="greenD">D</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td></td>
<td class="explanation">S1 is lit in the brightest green [D] ; others segments don't change</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>3</td>
<td class="greenC">C</td>
<td class="greenD">D</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td></td>
<td class="explanation">S2 is lit in [D], S1 is lit in [C] ; others segments don't change</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>4</td>
<td class="greenB">B</td>
<td class="greenC">C</td>
<td class="greenD">D</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td></td>
<td class="explanation">S3 is lit in [D], S2 is lit in [C], S1 is lit in [B] ; others segments don't change</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>5</td>
<td class="greenA">A</td>
<td class="greenB">B</td>
<td class="greenC">C</td>
<td class="greenD">D</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td></td>
<td class="explanation">S4 is lit in [D], S3 is lit in [C], S2 is lit in [B], S1 is lit in [A] ; others segments don't change</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>6</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenB">B</td>
<td class="greenC">C</td>
<td class="greenD">D</td>
<td class="greenA">A</td>
<td></td>
<td class="explanation">...</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>7</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenB">B</td>
<td class="greenC">C</td>
<td class="greenD">D</td>
<td></td>
<td class="explanation">and so on</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>8</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenB">B</td>
<td class="greenC">C</td>
<td></td>
<td class="explanation">...</td>
</tr><tr><td class="space"></td></tr>
<tr>
<td>9</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenA">A</td>
<td class="greenB">B</td>
<td></td>
<td class="explanation">step 9 (the last one) : S6 is lit in [B] and all others are lit in [A]</td>
</tr>
</table>
Looks like you did despite what you say…
Yes, gotcha!
The bug lie does not lie in Kirby!!