Markdown In Blocks


#1

Hi All,

Just stopping by, looking good around here :wink: Like the new forum.

I have a tiny code change that greatly improves the use of Markdown in blocks. Right now, you can use Markdown in pages, blocks, and blogs to compose your content. However if you use the pages for structure, blocks for content method, you can run into a problem. For example, if you have your home page set up with some code like this:

<div class="main">
    {{block:home-main}}
</div>

<div class="sidebar">
    {{block:home-sidebar}}
</div>

And then you wish to use Markdown inside either of those content blocks, it will not work since markdown is not parsed when inside of regular html (The divs).

But there is a simple fix that will allow the markdown block to be parsed before it gets put into the page. If you edit the inc/tags/block.php file on line 34.

Change:

echo $home;

to

echo $parsedown->text($home);

Michael - Would be great to get this into the main version.


#2

Great addition @markf and thanks for stopping by to share with us this great addition!

Will get that into the next build :slight_smile:

Thanks and keep in touch!


#3

Hi Mark,

This seems a specification of markdown: only parsing what’s not in a tag.
I worked around this by using parsedownextra by the original maker of parsedown. Just add it to index.php so the source code reflects the following:

include("inc/plugins/parsedown.php");
include("inc/plugins/parsedownextra.php");
$parsedown = new ParsedownExtra();

Next, add markdown=“1” to every DIV that needs markdown in its block. Like:

<div class="unit-60" markdown="1">
     {{block:contact/contact-side}}
</div>

Although this requires adding an attribute, I think this is very controllable. I hope this solves your issue.


#4

Hi Brian,

Thanks for the input, but my post already contained the solution to the issue I was raising. By editing the block.php file, blocks are parsed prior to being placed thus removing the issue of Markdown inside of tags. And you don’t have to add any additional markdown=“1” attributes.


#5

Hi Mark,

True, and adding markdown=“1” is not very nice to do.
How would calling parsedown() for “every” block on a page affect the overall performance? And then once again from layout.php while “all” blocks have already been parsed?
Is it negligible?

I guess I’ll just try to combine both “solutions”, so I can still benefit from the other extra’s that parsedownExtra has. :slight_smile:


#6

Thanks! I was looking for a way to write markdown inside <main> tag, and without a Pulse block.
I have found it in your solution.

PS
It also works without quotes around 1: markdown=1


#8

When you say add it (the includes) to index.php - do you mean at the top level of pulse or are you talking about layout.php??

I’m getting

Fatal error: Cannot redeclare class Parsedown in /Applications/XAMPP/xamppfiles/htdocs/pulse/inc/plugins/parsedown.php on line 17

thanks Ross


#9

@RoZZaH - what version of Pulse are you using? I think @sprksld here is referring to the route index.php :slight_smile: Please try that and see :+1:


#10

@RoZZaH - I made changes only to index.php, not layout.php. Also, I tested it only with version 4.5.2.
I have not yet tested it on 4.6 or higher, but it could work just fine for all version 4.x releases.

To use parsedownextra in version 4.5.2, I did the following to index.php.

change

include("inc/plugins/parsedown.php");
$parsedown = new ParseDown();

to

include("inc/plugins/parsedown.php");
include("inc/plugins/parsedownextra.php");
$parsedown = new ParsedownExtra();   // mind the capitalized word 'Extra'!

You need to copy the parsedownextra files to the inc/plugins/ folder, of course, but that’s all.

Now, let’s hope that, when pulse5 is released, that this forum will be archived. Or even better: split into separate sections for version 3 and version 4; it contains valuable information.


#11

Thanks dude
I tried this with 4.7 and couldn’t get it to work - as a complication I am using localizer so that may have been interfering - I was getting markup as code/html - including markdown hashes - so I just decided to echo $content

I’ve got something working now so i’m happy enough
can’t wait to get my mitts on pulse 5 - hopefully parsedown extra supported

thanks again,
RoZZaH


#12

This exits in 5.0.2! :smiley::+1:
http://help.pulsecms.com/article/10-version-history


closed #13