Raju28
Raju28

Reputation: 335

How to use markdown in middleman yaml locals

I'm using Middleman localization to push a bunch of documentation from yaml to ruby file. The problem is, I don't know how to use markdown in yaml file and yield the markdown yaml to ruby file.

yaml data file:

features:
    title: "14 Chapters"
    text: "The book's main chapters take you through building a **social news site**."
    image: "files.svg"
    title1: "11 Sidebars"
    text1: "In between each chapter, sidebars explain a specific aspect of Meteor."
    image1: "files.svg"

locals.html.erb:

<div class="banner">
    <h2 class="s-heading"> 
          <%= I18n.t("features.title") %> 
    </h2>
    <div class="banner-desc">
       <p>
         <span> <%= I18n.t("features.text") %> </span>
       </p>
    </div>          
</div>

Upvotes: 0

Views: 900

Answers (1)

Anthon
Anthon

Reputation: 76598

For the part of the representation of markdown in YAML, you can follow what I have been doing for reStructuredText (which is similar in concept, but which I prefer to use).

Line breaks and formatting are often significant in such text, so anything that you don't analyse and split up in keyword/value pairs you should put into YAML as a literal scalar (using |:

text: |
    Paragraphs are separated
    by a blank line.

    Leave 2 spaces at the end of a line to do a  
    line break
title: blahblah

and since you will have multiple titles and you shouldn't reuse a key in a YAML mapping, you should make the top structure into a list of flow (not block) style YAML.

That way you can walk over the list take the key value directly to decide what action to take (instead of having to parse the key with title, title1). But most importantly key/value pairs in YAML mappings are not ordered and your parser probably does away with the ordering when reading the value of features):

features:
  - title: 14 Chapters
  - text: |
      The book's main chapters take you through building a 
      **social news site**.
  - image: files.svg
  - title: 11 Sidebars
  - text: |
      In between each chapter, sidebars explain a specific aspect of Meteor.
  - image: files.svg

You don't have to quote string scalars, unless there might be confusion about their type (numbers, dates etc).

Upvotes: 1

Related Questions