Forum

Thread tagged as: Question, Problem

Using html and Markdown with classes

Is it possible to add a class to html when using Markdown on my template? The html seems to be processed correctly (ie it creates html rather than outputting it onto the page) but whenever I try to add a class it does this:

<ul class=&quotmyclass&quot> <!-- removed semicolons so I can post it here -->
  <li>item1</li>
  <li>item2</li>
  <li>item3</li>
</ul>

Instead of:

<ul class="myclass">
  <li>item1</li>
  <li>item2</li>
  <li>item3</li>
</ul>

My template is:

<perch:content id="text" type="textarea" label="Text" markdown="true" editor="markitup" />

I've tried adding html="true" to my template but all posts get saved as drafts (I assume you can't use html and Markdown at the same time). I've also tried encode="false" which allows me to save the page, but the quotes still get encoded.

I feel like there should be an easy solution but I don't know how to go about it. I would add the normal {.class} using Markdown but it doesn't seem to be support on lists in parsedown. Any help would be greatly appreciated!

Alan Longstaff

Alan Longstaff 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What am I missing here? Those look the same.

Whoops sorry should've checked my post - in the top example myclass is surrounded by &quot (plus a semicolon - it keeps transforming it here, haha) rather than actual quote marks. I'll edit the original post so you can see it better.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I've tried adding html="true" to my template but all posts get saved as drafts (I assume you can't use html and Markdown at the same time).

You should be able to. Can you turn on debug and look to see if you get any errors when this happens?

Yes no problem, this is the output:

Debug Message
SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='2eb22a19c87ae0d1d9e79156b671fdf7' LIMIT 1
UPDATE perch2_users SET userHash='3b7a1dab0e4530592935ebae2d85f696' WHERE userID=1
SELECT p.privKey FROM perch2_user_privileges p
SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID
SELECT * FROM perch2_content_regions WHERE regionID=604 LIMIT 1
SELECT * FROM perch2_pages WHERE pageID='248' LIMIT 1
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=97 AND itemID=930 ORDER BY itemOrder ASC
Using template: \templates\content\story.html
Using sub-template: \templates\content/blocks/textarea.html
Using sub-template: \templates\content/blocks/video.html
Using sub-template: \templates\content/blocks/image.html
Form not posted or did not validate
Setting alert: You are editing a draft. Preview (draft)
Queries: 8
Memory: 2.7379

I noticed it mixes up back and forward slashes for my templates, wonder if it's something to do with hosting in a Windows environment.

Tried changing them to backslashes and the same thing happens so it doesn't appear to be related.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is that after clicking Save or before?

This is before clicking save:

SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='d40190da0527dfe42c2e5d265bf008c9' LIMIT 1
UPDATE perch2_users SET userHash='6559815bebbb950698066df1968c3f01' WHERE userID=1
SELECT p.privKey FROM perch2_user_privileges p
SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID
SELECT * FROM perch2_content_regions WHERE regionID=604 LIMIT 1
SELECT * FROM perch2_pages WHERE pageID='248' LIMIT 1
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=104 AND itemID=930 ORDER BY itemOrder ASC
Using template: \templates\content\story.html
Using sub-template: \templates\content/blocks/textarea.html
Using sub-template: \templates\content/blocks/video.html
Using sub-template: \templates\content/blocks/image.html
Form not posted or did not validate
Queries: 8
Memory: 2.7275

This is after clicking save with no html on the page:

SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='316df97020bc63151a752efce5055af3' LIMIT 1
UPDATE perch2_users SET userHash='059519ff1241c25cd494251e15e0cc4b' WHERE userID=1
SELECT p.privKey FROM perch2_user_privileges p
SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID
SELECT * FROM perch2_content_regions WHERE regionID=604 LIMIT 1
SELECT * FROM perch2_pages WHERE pageID='248' LIMIT 1
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=108 AND itemID=930 ORDER BY itemOrder ASC
Using template: \templates\content\story.html
Using sub-template: \templates\content/blocks/textarea.html
Using sub-template: \templates\content/blocks/video.html
Using sub-template: \templates\content/blocks/image.html
INSERT INTO perch2_content_items (itemID, regionID, pageID, itemRev, itemOrder, itemJSON, itemSearch, itemUpdatedBy) SELECT itemID, regionID, pageID, 109 AS itemRev, itemOrder, itemJSON, itemSearch, 1 AS itemUpdatedBy FROM perch2_content_items WHERE regionID=604 AND itemRev=108 ORDER BY itemOrder ASC
REPLACE INTO perch2_resource_log (appID, itemFK, itemRowID, resourceID) SELECT cr.appID, cr.itemFK, c2.itemRowID, cr.resourceID FROM perch2_resource_log cr, perch2_content_items c1, perch2_content_items c2 WHERE cr.appID='content' AND cr.itemFK='itemRowID' AND cr.itemRowID=c1.itemRowID AND c1.itemID = c2.itemID AND c1.regionID=604 AND c2.regionID=604 AND c1.itemRev = 108 AND c2.itemRev = 109
SELECT itemRowID FROM perch2_content_items WHERE regionID=604 AND itemRev=109 ORDER BY itemOrder ASC
UPDATE perch2_content_items SET itemOrder=1000 WHERE itemRowID='8546'
UPDATE perch2_content_items SET itemOrder=1001 WHERE itemRowID='8547'
UPDATE perch2_content_items SET itemOrder=1002 WHERE itemRowID='8548'
UPDATE perch2_content_items SET itemOrder=1003 WHERE itemRowID='8549'
UPDATE perch2_content_items SET itemOrder=1004 WHERE itemRowID='8550'
UPDATE perch2_content_items SET itemOrder=1005 WHERE itemRowID='8551'
UPDATE perch2_content_regions SET regionLatestRev=109 WHERE regionID=604
SELECT regionRev FROM perch2_content_regions WHERE regionID=604
DELETE FROM perch2_content_items WHERE regionID=604 AND itemRev!=108 AND itemRev IN (SELECT itemRev FROM (SELECT DISTINCT itemRev FROM perch2_content_items WHERE regionID=604 ORDER BY itemRev DESC LIMIT 8, 99999) AS t2)
DELETE FROM perch2_resource_log WHERE appID='content' AND itemFK='itemRowID' AND itemRowID NOT IN (SELECT itemRowID FROM perch2_content_items)
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=109 AND itemID=930 ORDER BY itemOrder ASC
DELETE FROM perch2_resource_log WHERE appID='content' AND itemFK='itemRowID' AND itemRowID='8551'
SELECT * FROM perch2_resources WHERE resourceID='1618' LIMIT 1
SELECT * FROM perch2_resources WHERE resourceAWOL=0 AND resourceParentID='1618' AND resourceKey='thumb'
INSERT IGNORE INTO perch2_resource_log(`appID`, `itemFK`, `itemRowID`, `resourceID`) VALUES('content','itemRowID',8551,1618),('content','itemRowID',8551,1619)
UPDATE perch2_content_items SET itemJSON='{\"_id\":\"930\",\"title\":\"Ellis Broatch\",\"_title\":\"Ellis Broatch\",\"_blocks\":[{\"image\":{\"assetID\":\"1618\",\"title\":\"Ellis\",\"_default\":\"\\/perch\\/resources\\/images\\/ellis.jpg\",\"bucket\":\"images\",\"path\":\"ellis.jpg\",\"size\":67013,\"w\":600,\"h\":522,\"mime\":\"image\\/jpeg\",\"sizes\":{\"thumb\":{\"w\":\"150\",\"h\":\"130\",\"target_w\":150,\"target_h\":150,\"density\":2,\"path\":\"ellis-thumb@2x.jpg\",\"size\":20954,\"mime\":\"\",\"assetID\":\"1619\"}}},\"alt\":null,\"image_position\":\"Left\",\"_block_type\":\"image\",\"_block_id\":\"np29gb\",\"_block_index\":\"0\"},{\"text\":{\"raw\":\"**School:** High Tunstall College of Science \\r\\n**Achieved at HSFC:** A* in Mathematics and Chemistry, A in Physics and Further Maths \\r\\n**Currently studying:** Natural Sciences - Physical at King\'s College Cambridge\",\"processed\":\"<p><strong>School:<\\/strong> High Tunstall College of Science<br \\/>\\n<strong>Achieved at HSFC:<\\/strong> A* in Mathematics and Chemistry, A in Physics and Further Maths<br \\/>\\n<strong>Currently studying:<\\/strong> Natural Sciences - Physical at King\\u2019s College Cambridge<\\/p>\"},\"_block_type\":\"text\",\"_block_id\":\"np29gh\",\"_block_index\":\"1\"}],\"ext\":null,\"video\":{\"raw\":\"\",\"processed\":\"\"},\"image\":null,\"image_position\":\"Left\",\"alt\":null,\"text\":{\"raw\":\"\",\"processed\":\"\"}}', itemSearch=' Ellis Broatch Left School: High Tunstall College of Science\nAchieved at HSFC: A* in Mathematics and Chemistry, A in Physics and Further Maths\nCurrently studying: Natural Sciences - Physical at King’s College Cambridge Left ' WHERE itemRowID=8551
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=109 ORDER BY itemOrder ASC
Using template: \templates\content\story.html
Using sub-template: \templates\content/blocks/textarea.html
Using sub-template: \templates\content/blocks/video.html
Using sub-template: \templates\content/blocks/image.html
UPDATE perch2_content_regions SET regionHTML=' <article class=\"paper paper--inked media\">\r\n \r\n <h2 id=\"ashleigh-lister\">Ashleigh Lister</h2>\r\n \r\n \r\n \r\n <img src=\"/perch/resources/images/ashleigh.jpg\" class=\"media__img\" />\r\n\r\n \r\n \r\n \r\n \r\n \r\n <p><strong>School:</strong> Manor College of Technology<br />\n<strong>Achieved at HSFC:</strong> B in English Language, A in History and A in Law<br />\n<strong>Currently studying:</strong> Law at Durham University</p>\r\n \r\n \r\n \r\n \r\n</article>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n <article class=\"paper paper--inked media\">\r\n \r\n <h2 id=\"danielle-curry\">Danielle Curry</h2>\r\n \r\n \r\n \r\n <img src=\"/perch/resources/images/danielle.jpg\" class=\"media__img\" />\r\n\r\n \r\n \r\n \r\n \r\n \r\n <p><strong>School:</strong> Dyke House Sports & Technology College<br />\n<strong>Achieved at HSFC:</strong> Triple Distinction starred in BTEC Sports and Exercise Science<br />\n<strong>Currently studying:</strong> Sports Coaching at Sunderland University</p>\r\n \r\n \r\n \r\n \r\n</article>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n <article class=\"paper paper--inked media\">\r\n \r\n <h2 id=\"david-littlewood\">David Littlewood</h2>\r\n \r\n \r\n \r\n <img src=\"/perch/resources/images/littlewood.jpg\" class=\"media__img\" />\r\n\r\n \r\n \r\n \r\n \r\n \r\n <p><strong>School:</strong> Manor College of Technology\n<strong>Achieved at HSFC:</strong> A in Biology, A in Psychology and B in Chemistry\n<strong>Currently studying:</strong> Psychology at Northumbria University</p>\r\n \r\n \r\n \r\n \r\n</article>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n <article class=\"paper paper--inked media\">\r\n \r\n <h2 id=\"david-brennan\">David Brennan</h2>\r\n \r\n \r\n \r\n <img src=\"/perch/resources/images/brennan.jpg\" class=\"media__img\" />\r\n\r\n \r\n \r\n \r\n \r\n \r\n <p><strong>School:</strong> St Hild’s Church of England School<br />\n<strong>Achieved at HSFC:</strong> A* in History, A in Geography and B in Economics<br />\n<strong>Currently studying:</strong> History at University of Leeds</p>\r\n \r\n \r\n \r\n \r\n</article>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n <article class=\"paper paper--inked media\">\r\n \r\n <h2 id=\"eleanor-gregory\">Eleanor Gregory</h2>\r\n \r\n \r\n \r\n <img src=\"/perch/resources/images/eleanor.jpg\" class=\"media__img\" />\r\n\r\n \r\n \r\n \r\n \r\n \r\n <p><strong>School:</strong> Manor College of Technology<br />\n<strong>Achieved at HSFC:</strong> A* in Product Design, A in Maths and A in Physics<br />\n<strong>Currently studying:</strong> MEng Electronic and Computer Engineering with industrial placement at Newcastle University</p>\r\n \r\n \r\n \r\n \r\n</article>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n <article class=\"paper paper--inked media\">\r\n \r\n <h2 id=\"ellis-broatch\">Ellis Broatch</h2>\r\n \r\n \r\n \r\n <img src=\"/perch/resources/images/ellis.jpg\" class=\"media__img\" />\r\n\r\n \r\n \r\n \r\n \r\n \r\n <p><strong>School:</strong> High Tunstall College of Science<br />\n<strong>Achieved at HSFC:</strong> A* in Mathematics and Chemistry, A in Physics and Further Maths<br />\n<strong>Currently studying:</strong> Natural Sciences - Physical at King’s College Cambridge</p>\r\n \r\n \r\n \r\n \r\n</article>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n', regionRev=109, regionLatestRev=109 WHERE regionID=604
Setting alert: Content successfully updated (success)
SELECT * FROM perch2_resources WHERE resourceApp='content' AND resourceInLibrary=0 AND resourceCreated<'2015-05-27 15:46:03' AND resourceID NOT IN (SELECT resourceID FROM perch2_resource_log)
SELECT MIN(itemRev) FROM perch2_content_items WHERE regionID=604
DELETE FROM perch2_content_index WHERE regionID=604 AND itemRev<102
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=109 ORDER BY itemOrder ASC
DELETE FROM perch2_content_index WHERE regionID=604 AND itemRev=109
Using template: \templates\content\story.html
Using sub-template: \templates\content/blocks/textarea.html
Using sub-template: \templates\content/blocks/video.html
Using sub-template: \templates\content/blocks/image.html
INSERT INTO perch2_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (925,604,248,109,'title','Ashleigh Lister'),(925,604,248,109,'ext',''),(925,604,248,109,'video',''),(925,604,248,109,'image',''),(925,604,248,109,'image_position','Left'),(925,604,248,109,'alt',''),(925,604,248,109,'text',''),(925,604,248,109,'_id',925),(925,604,248,109,'_order','1000')
INSERT INTO perch2_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (926,604,248,109,'title','Danielle Curry'),(926,604,248,109,'ext',''),(926,604,248,109,'video',''),(926,604,248,109,'image','/perch/resources/images/danielle.jpg'),(926,604,248,109,'image_position','Left'),(926,604,248,109,'alt',''),(926,604,248,109,'text','School: Dyke House Sports & Technology College\nAchieved at HSFC: Triple Distinction starred in BTEC Sports and Exercise Science\nCurrently studying: Sports Coaching at Sunderland University'),(926,604,248,109,'_id',926),(926,604,248,109,'_order','1001')
INSERT INTO perch2_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (927,604,248,109,'title','David Littlewood'),(927,604,248,109,'ext',''),(927,604,248,109,'video',''),(927,604,248,109,'image','/perch/resources/images/littlewood.jpg'),(927,604,248,109,'image_position','Left'),(927,604,248,109,'alt',''),(927,604,248,109,'text','School: Manor College of Technology\nAchieved at HSFC: A in Biology, A in Psychology and B in Chemistry\nCurrently studying: Psychology at Northumbria University'),(927,604,248,109,'_id',927),(927,604,248,109,'_order','1002')
INSERT INTO perch2_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (928,604,248,109,'title','David Brennan'),(928,604,248,109,'ext',''),(928,604,248,109,'video',''),(928,604,248,109,'image','/perch/resources/images/brennan.jpg'),(928,604,248,109,'image_position','Left'),(928,604,248,109,'alt',''),(928,604,248,109,'text','School: St Hild’s Church of England School\nAchieved at HSFC: A* in History, A in Geography and B in Economics\nCurrently studying: History at University of Leeds'),(928,604,248,109,'_id',928),(928,604,248,109,'_order','1003')
INSERT INTO perch2_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (929,604,248,109,'title','Eleanor Gregory'),(929,604,248,109,'ext',''),(929,604,248,109,'video',''),(929,604,248,109,'image','/perch/resources/images/eleanor.jpg'),(929,604,248,109,'image_position','Left'),(929,604,248,109,'alt',''),(929,604,248,109,'text','School: Manor College of Technology\nAchieved at HSFC: A* in Product Design, A in Maths and A in Physics\nCurrently studying: MEng Electronic and Computer Engineering with industrial placement at Newcastle University'),(929,604,248,109,'_id',929),(929,604,248,109,'_order','1004')
INSERT INTO perch2_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (930,604,248,109,'title','Ellis Broatch'),(930,604,248,109,'ext',''),(930,604,248,109,'video',''),(930,604,248,109,'image',''),(930,604,248,109,'image_position','Left'),(930,604,248,109,'alt',''),(930,604,248,109,'text',''),(930,604,248,109,'_id',930),(930,604,248,109,'_order','1005')
OPTIMIZE TABLE perch2_content_index
UPDATE perch2_pages SET pageModified='2015-05-28 15:46:04' WHERE pageID=248
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=109 AND itemID=930 ORDER BY itemOrder ASC
Queries: 58
Memory: 3.6721

And this is after clicking save after I add html to the page:

SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='e0cb5b1dbd1d144c88397b48e2ece880' LIMIT 1
UPDATE perch2_users SET userHash='36ccb481f19d69c38724fe2bb5b5cb5a' WHERE userID=1
SELECT p.privKey FROM perch2_user_privileges p
SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID
SELECT * FROM perch2_content_regions WHERE regionID=604 LIMIT 1
SELECT * FROM perch2_pages WHERE pageID='248' LIMIT 1
SELECT * FROM perch2_content_items WHERE regionID=604 AND itemRev=110 AND itemID=930 ORDER BY itemOrder ASC
Using template: \templates\content\story.html
Using sub-template: \templates\content/blocks/textarea.html
Using sub-template: \templates\content/blocks/video.html
Using sub-template: \templates\content/blocks/image.html
Form not posted or did not validate
Setting alert: You are editing a draft. Preview (draft)
Queries: 8
Memory: 2.733

This is the html I'm adding:

<ul class="test">
  <li>School: High Tunstall College of Science</li>
  <li>Achieved at HSFC: A* in Mathematics and Chemistry, A in Physics and Further Maths</li>
  <li>Currently studying: Natural Sciences - Physical at King's College Cambridge</li>
</ul>
Drew McLellan

Drew McLellan 2638 points
Perch Support

As you can see, it's hard work being a content management system.

I can't see anything in that that should be throwing it into Draft mode.

Haha yes, it's a strange one. I'll see if I can figure something out on my end - if html and markdown should work at the same time I'll try doing that on a page that has less content on it (the one above is on a live site). I'll post back if I find anything, but if you work it out it'd be great to find out what's causing the problem

In case anyone else has the same problem: it was being caused by not having the php mbstring extension enabled - added it to my php.ini and it works perfectly.