Forum

Thread tagged as: Question, Configuration, Discussion

HTML5 & Perch

My first question is: how do I stop Perch from adding the closing slash to image tags (ie, <img ... />). I've tried a few things and a few searches and I can't figure it out. We have the PERCH_HTML5 constant set as true.

Also, while I was looking for info on HTML5 and Perch, I stumbled on this page: https://solutions.grabaperch.com/html-and-css/can-i-use-html5

It's probably not the end of the world, but a couple thoughts on the page:

  1. Under HTML5 Boilerplate, it includes the html5shiv from Google Code (https://html5shiv.googlecode.com/svn/trunk/html5.js). As Google Code has been shutdown, this unfortunately resolves to a 404.

  2. Under HTML5 Boilerplate and HTML5 Audio and Video, the self-closing tags have closing slashes. Since this isn't needed or generally recommended in HTML5, it'd probably be good to remove them...not that it breaks anything or is really a big deal.

Just looking to cleanup up my HTML when I noticed this. Nothing of any urgency :)

Darryl Hein

Darryl Hein 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

how do I stop Perch from adding the closing slash to image tags

Do you mean when using output="tag"? If not, the code is in your template. If so, turn it off with:

define('PERCH_XHTML_MARKUP', false);

It's probably not the end of the world, but a couple thoughts on the page:

That page is from 2012, so you should read it in that context.

I should have been more clear: I don't want Perch to include the closing slash in output from Markdown (not a separate content item/field so output=tag doesn't apply). I think PERCH_XHTML_MARKUP is the right setting, but...

I tried putting in define('PERCH_XHTML_MARKUP', false); but it hasn't made a difference. (I put it in config/config.php.) I checked the diagnostics and it's showing as blank, which, based on other options, seems that means false. I've tried editing/saving the content and republishing all the pages. I also tried setting PERCH_RWD to false, but it still isn't outputting the the width and height on the image tags while showing false in the diagnostics.

Lastly, what are the defaults for these config options? (Some of the Markdown and other ones that don't have defaults in the docs.) I've searched the source and determined some of them...but that's a bit annoying. Also, the docs say Perch defaults to HTML5 markup, but when I look in the source (and what I see when I remove define('PERCH_HTML5', true); in the diagnostics) is that it defaults to false, based on this line:

if (!defined('PERCH_HTML5')) define('PERCH_HTML5', false);
Drew McLellan

Drew McLellan 2638 points
Perch Support

When you install the initial setting placed in your config.php file is

define('PERCH_HTML5', true);

If you're using Markdown and the /> isn't being converted back to a bare > then that could be a bug. We massively refactored the Markdown parsing routines recently, and it's possible that that step got lost. A quick scan through the code suggests that may be the case.

Ah, so the documentation is misleading then as it says true is the default for HTML5 markup when in reality, the default config is true the default value is false.

I guess I'll leave it as is and see what the results are once the bugs are fixed.

Thanks for your help.

Hi Drew,

I just found a really annoying bug related to setting PERCH_XHTML_MARKUP to false. It seems that changing this setting requires that all Perch tags are not self closing. Spent that last 3 hours trying to figure out why perch_blog_post_field() didn't work any more, only to learn that if PERCH_XHTML_MARKUP is set to false, the Perch tags generated for parsing aren't self closing (in PerchXMLTag::create()). I don't know if this is the intention of the config option, but it definitely is not clear in the docs!

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, that's not intentional. You're better to avoid that option in that case.