Skip to content

Instantly share code, notes, and snippets.

@tamouse
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamouse/eb8432d916459b180007 to your computer and use it in GitHub Desktop.
Save tamouse/eb8432d916459b180007 to your computer and use it in GitHub Desktop.

I've been through the links on orgmode.com about doing this, but there's still something missing about it for me.

Jekyll posts and pages begin with YAML frontmatter. This is placed in the .org file with #+BEGIN_HTML / #+END_HTML guards. That limits me to sub-editing that section (with C-c ') in html-mode. I can't switch to yaml-mode and back to html-mode to edit it as YAML, though, as it somehow loses context and can't switch out of the sub-edit mode.

Is there some way to do what I wish, i.e. edit the frontmatter in YAML mode?

File 1-with-html.org-raw shows what one is "supposed" to do, place the frontmatter ins the html block, and this renders exactly as I'd prefer it, but doesn't let me edit the content in yaml-mode, only html-mode. This renders out correctly with running jekyll build.

File 4-with-yaml.org-raw shows what was suggested, with a src block for yaml text, and using the :results html flag. This ends up causing the block's content to be rendered in markdown as a verbatum block, i.e., pushed to the right 4 spaces. That causes problems when run through jekyll, as it renders the frontmatter as content.

What I need is for that source YAML block to be rendered just as is, i.e. copied directly without changes at all. The initial suggestion to add :result html did not do as I'd hoped, sadly.


From user Left Right on the G+ Emacs community, I got the direction and help I need to make this work. The final answer was to tell babel how to execute YAML source:

(defun org-babel-execute:yaml (body params) body)

Now I have the output I want.

#+STARTUP: showall
#+options: toc:nil
#+begin_html
---
layout: post
title: test post with html block frontmatter
gallery:
path: abc123
images:
- blah.png
- bloo.png
---
#+end_html
* hello world
/this/ is the *reason* for the _season_.
---
layout: post
title: test post with html block frontmatter
gallery:
path: abc123
images:
- blah.png
- bloo.png
---
# hello world
*this* is the **reason** for the <span class="underline">season</span>.
<!DOCTYPE html>
<html>
<body>
<h1 class="post-title">test post with html block frontmatter</h1>
<h1 id="hello-world">hello world</h1>
<p><em>this</em> is the <strong>reason</strong> for the <span class="underline">season</span>.</p>
</div>
</body>
</html>
#+STARTUP: showall expand
#+options: toc:nil
#+begin_src yaml :exports results :results value html
---
layout: post
title: test post with yaml source block frontmatter
gallery:
path: abc123
images:
- blah.png
- bloo.png
---
#+end_src
#+results:
* hello world
/this/ is the *reason* for the _season_.
---
layout: post
title: test post with yaml source block frontmatter
gallery:
path: abc123
images:
- blah.png
- bloo.png
---
# hello world
*this* is the **reason** for the <span class="underline">season</span>.
<!DOCTYPE html>
<html>
<body>
<h1 class="post-title">test post with yaml source block frontmatter</h1>
<h1 id="hello-world">hello world</h1>
<p><em>this</em> is the <strong>reason</strong> for the <span class="underline">season</span>.</p>
</div>
</body>
</html>
4c4
< <h1 class="post-title">test post with html block frontmatter</h1>
---
> <h1 class="post-title">test post with yaml source block frontmatter</h1>
@tamouse
Copy link
Author

tamouse commented May 25, 2015

Trying with #+begin_src yaml :exports results :results value html resulted in no frontmatter at all in the markdown file 5-with-yaml.md-raw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment