Export Org src blocks to code fenced Markdown by default

The option is set by the HUGO_CODE_FENCE property.

- If set to t (default), Markdown code fence is used.
- Else Hugo `highlight' shortcode is used.

Add examples.
master
Kaushal Modi 9 years ago
parent e974a39d58
commit 67ec7988b4
  1. 36
      example-site/content-org/all-posts.org
  2. 41
      example-site/content-org/src-blocks-with-highlight-shortcode.org
  3. 37
      example-site/content/posts/code-fenced-src-blocks.md
  4. 37
      example-site/content/posts/shortcode-src-blocks.md
  5. 24
      ox-hugo.el

@ -199,6 +199,42 @@ Here is the second post on Emacs.
| a | b | e | g |
| c | d | f | h |
|---+---+---+---|
* Source blocks :src-block:
** Code-fenced source blocks
:PROPERTIES:
:EXPORT_FILE_NAME: code-fenced-src-blocks
:END:
Here are few variables that you might like to change in the =local.mk=:
- =prefix= :: Org installation directory
#+BEGIN_SRC makefile
prefix = /dir/where/you/want/to/install/org # Default: /usr/share
#+END_SRC
The =.el= files will go to =$(prefix)/emacs/site-lisp/org= by
default. If you'd like to change that, you can tweak the
=lispdir= variable.
- =infodir= :: Org Info installation directory. I like to keep the
Info file for development version of Org in a separate
directory.
#+BEGIN_SRC makefile
infodir = $(prefix)/org/info # Default: $(prefix)/info
#+END_SRC
- =ORG_MAKE_DOC= :: Types of Org documentation you'd like to build by
default.
#+BEGIN_SRC makefile
# Define below you only need info documentation, the default includes html and pdf
ORG_MAKE_DOC = info pdf card # html
#+END_SRC
- =ORG_ADD_CONTRIB= :: Packages from the =contrib/= directory that
you'd like to build along with Org. Below are the ones on my
/must-have/ list.
#+BEGIN_SRC makefile
# Define if you want to include some (or all) files from contrib/lisp
# just the filename please (no path prefix, no .el suffix), maybe with globbing
# org-eldoc - Headline breadcrumb trail in minibuffer
# ox-extra - Allow ignoring just the heading, but still export the body of those headings
# org-mime - Convert org buffer to htmlized format for email
ORG_ADD_CONTRIB = org-eldoc ox-extra org-mime
#+END_SRC
* TODO Pre-Draft State
:PROPERTIES:
:EXPORT_FILE_NAME: draft-state-todo

@ -0,0 +1,41 @@
#+HUGO_BASE_DIR: ../
#+HUGO_CODE_FENCE: nil
#+OPTIONS: loffset:1
#+SEQ_TODO: TODO DRAFT DONE
* Source blocks with Hugo =highlight= shortcode
:PROPERTIES:
:EXPORT_FILE_NAME: shortcode-src-blocks
:END:
Here are few variables that you might like to change in the =local.mk=:
- =prefix= :: Org installation directory
#+BEGIN_SRC makefile
prefix = /dir/where/you/want/to/install/org # Default: /usr/share
#+END_SRC
The =.el= files will go to =$(prefix)/emacs/site-lisp/org= by
default. If you'd like to change that, you can tweak the
=lispdir= variable.
- =infodir= :: Org Info installation directory. I like to keep the
Info file for development version of Org in a separate
directory.
#+BEGIN_SRC makefile
infodir = $(prefix)/org/info # Default: $(prefix)/info
#+END_SRC
- =ORG_MAKE_DOC= :: Types of Org documentation you'd like to build by
default.
#+BEGIN_SRC makefile
# Define below you only need info documentation, the default includes html and pdf
ORG_MAKE_DOC = info pdf card # html
#+END_SRC
- =ORG_ADD_CONTRIB= :: Packages from the =contrib/= directory that
you'd like to build along with Org. Below are the ones on my
/must-have/ list.
#+BEGIN_SRC makefile
# Define if you want to include some (or all) files from contrib/lisp
# just the filename please (no path prefix, no .el suffix), maybe with globbing
# org-eldoc - Headline breadcrumb trail in minibuffer
# ox-extra - Allow ignoring just the heading, but still export the body of those headings
# org-mime - Convert org buffer to htmlized format for email
ORG_ADD_CONTRIB = org-eldoc ox-extra org-mime
#+END_SRC

@ -0,0 +1,37 @@
+++
title = "Code-fenced source blocks"
date = 2017-07-13T17:49:22-04:00
tags = []
draft = false
+++
Here are few variables that you might like to change in the `local.mk`:
- **`prefix`:** Org installation directory
```makefile
prefix = /dir/where/you/want/to/install/org # Default: /usr/share
```
The `.el` files will go to `$(prefix)/emacs/site-lisp/org` by default. If you’d like to change that, you can tweak the `lispdir` variable.
- **`infodir`:** Org Info installation directory. I like to keep the Info file for development version of Org in a separate directory.
```makefile
infodir = $(prefix)/org/info # Default: $(prefix)/info
```
- **`ORG_MAKE_DOC`:** Types of Org documentation you’d like to build by default.
```makefile
# Define below you only need info documentation, the default includes html and pdf
ORG_MAKE_DOC = info pdf card # html
```
- **`ORG_ADD_CONTRIB`:** Packages from the `contrib/` directory that you’d like to build along with Org. Below are the ones on my *must-have* list.
```makefile
# Define if you want to include some (or all) files from contrib/lisp
# just the filename please (no path prefix, no .el suffix), maybe with globbing
# org-eldoc - Headline breadcrumb trail in minibuffer
# ox-extra - Allow ignoring just the heading, but still export the body of those headings
# org-mime - Convert org buffer to htmlized format for email
ORG_ADD_CONTRIB = org-eldoc ox-extra org-mime
```

@ -0,0 +1,37 @@
+++
title = "Source blocks with Hugo `highlight` shortcode"
date = 2017-07-13T17:57:58-04:00
tags = []
draft = false
+++
Here are few variables that you might like to change in the `local.mk`:
- **`prefix`:** Org installation directory
{{< highlight makefile>}}
prefix = /dir/where/you/want/to/install/org # Default: /usr/share
{{< /highlight >}}
The `.el` files will go to `$(prefix)/emacs/site-lisp/org` by default. If you&rsquo;d like to change that, you can tweak the `lispdir` variable.
- **`infodir`:** Org Info installation directory. I like to keep the Info file for development version of Org in a separate directory.
{{< highlight makefile>}}
infodir = $(prefix)/org/info # Default: $(prefix)/info
{{< /highlight >}}
- **`ORG_MAKE_DOC`:** Types of Org documentation you&rsquo;d like to build by default.
{{< highlight makefile>}}
# Define below you only need info documentation, the default includes html and pdf
ORG_MAKE_DOC = info pdf card # html
{{< /highlight >}}
- **`ORG_ADD_CONTRIB`:** Packages from the `contrib/` directory that you&rsquo;d like to build along with Org. Below are the ones on my *must-have* list.
{{< highlight makefile>}}
# Define if you want to include some (or all) files from contrib/lisp
# just the filename please (no path prefix, no .el suffix), maybe with globbing
# org-eldoc - Headline breadcrumb trail in minibuffer
# ox-extra - Allow ignoring just the heading, but still export the body of those headings
# org-mime - Convert org buffer to htmlized format for email
ORG_ADD_CONTRIB = org-eldoc ox-extra org-mime
{{< /highlight >}}

@ -108,7 +108,7 @@ directory where all Hugo posts should go by default."
(:date "DATE" nil nil)
(:tags "TAGS" nil nil 'space)
(:hugo-level-offset "HUGO_LEVEL_OFFSET" loffset 0)
(:hugo-tags "HUGO_TAGS" nil nil 'space) ;TODO: Also parse the Org tags as post tags
(:hugo-tags "HUGO_TAGS" nil nil 'space)
(:hugo-categories "HUGO_CATEGORIES" nil nil 'space)
;; Optional front matter variables
(:hugo-aliases "HUGO_ALIASES" nil nil 'space)
@ -125,7 +125,8 @@ directory where all Hugo posts should go by default."
(:with-toc nil "toc" nil) ;No TOC by default
(:hugo-section "HUGO_SECTION" nil org-hugo-default-section-directory)
(:hugo-base-dir "HUGO_BASE_DIR" nil nil)
(:hugo-static-images "HUGO_STATIC_IMAGES" nil "images")))
(:hugo-static-images "HUGO_STATIC_IMAGES" nil "images")
(:hugo-code-fence "HUGO_CODE_FENCE" nil "t")))
;;; Transcode Functions
@ -244,13 +245,18 @@ section as a string."
(concat "\n" level-mark " " title " " anchor "\n\n"))))
;;;; Source Blocks
(defun org-hugo-src-block (src-block _contents _info)
"Convert SRC-BLOCK element to the Hugo `highlight' shortcode."
(let* ((lang (org-element-property :language src-block))
(code (org-element-property :value src-block))
(shortcode (concat "{{< highlight " lang " >}}\n"))
(close-shortcode "{{< /highlight >}}\n"))
(concat shortcode code close-shortcode)))
(defun org-hugo-src-block (src-block _contents info)
"Convert SRC-BLOCK element to Hugo-compatible element.
If the HUGO_CODE_FENCE property is set to t (default), the
Markdown style triple-backquoted code blocks are created.
Otherwise, the code block is wrapped in Hugo `highlight'
shortcode."
(if (string= "t" (org-export-data (plist-get info :hugo-code-fence) info))
(org-blackfriday-src-block src-block nil info)
(let* ((lang (org-element-property :language src-block))
(code (org-export-format-code-default src-block info)))
(format "{{< highlight %s>}}\n%s{{< /highlight >}}\n" lang code))))
;;;; Links
(defun org-hugo-link (link contents info)

Loading…
Cancel
Save