1

I am trying to make a flatfile PHP blog that uses YAML to convert the entries to code, but I can't find out how to get YAML to ignore the HTML tags and everything after the second "---":

---
title = "Entry title"
tags = "tag1 tag2 tag3"
someInportentVariable = "Some Inportent Content"
---

<p>This is some entry content.</p>
<p>Line2.</p>
<p>Line3.</p>
<p>And so on...</p>

How can I be able do that?

Here's a example of what I mean: https://github.com/claco/claco.github.com/blob/master/_posts/2002-10-05-marry-a-sysadmin.textile.

Update: For people who wants to contact me, head over to my new stackoverflow account, RobinLilfelt.

Community
  • 1
  • 1
Robbie
  • 41
  • 1
  • 3

1 Answers1

3

What you probably want to do is treat the HTML as a quoted scalar literal. You do this by starting the HTML section with --- | and indenting all of the lines.

e.g.:

---
title = "Entry title"
tags = "tag1 tag2 tag3"
someInportentVariable = "Some Inportent Content"
postBody: |
  <p>This is some entry content.</p>
  <p>Line2.</p>
  <p>Line3.</p>
  <p>And so on...</p>
Conspicuous Compiler
  • 6,403
  • 1
  • 40
  • 52
  • Thanks for the idea. I've asked my friend I'm working on the project with, and he says it has to be in the same format... So I was thinking, can I use some kind of large REGEX string inside a preg_(something) or should I just split the YAML and HTML? I've already tried preg_split, but then I have to remove the /n between the --- and the html. How can I do that without touching the other /n's? – Robbie Aug 11 '11 at 05:26
  • I don't know what you mean here. You can encode a scalar literal in your document, as I showed above (note recent edit). If you're using some kind of additional parsing to separate items, you are throwing away the value of YAML: having a built in format that saves you from writing your own parsing stages. – Conspicuous Compiler Aug 11 '11 at 06:05