Skip to content

Commit

Permalink
Render em dash, en dash and horizontal ellipsis in titles too
Browse files Browse the repository at this point in the history
This gets around the limitation where the Blackfriday smartDashes
feature does not work on post titles as Hugo does not render the
titles as Markdown by default.

gohugoio/hugo#4175
  • Loading branch information
kaushalmodi committed Dec 19, 2017
1 parent 1d0fae1 commit 0f38756
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
11 changes: 10 additions & 1 deletion ox-hugo.el
Expand Up @@ -1784,7 +1784,16 @@ INFO is a plist used as a communication channel."
(title (replace-regexp-in-string "\\`__?\\|\\`\\*\\*?\\|__?\\'\\|\\*\\*?\\'" "" title))
(title (replace-regexp-in-string " __?\\|__? \\| \\*\\*?\\|\\*\\*? " " " title))
;; Do not escape underscores in title
(title (replace-regexp-in-string "\\\\_" "_" title)))
(title (replace-regexp-in-string "\\\\_" "_" title))
;; Hugo does not render Markdown in the titles and so the
;; Blackfriday smartDashes conversion does not work there.
;; So do that here instead.
;; Convert "---" and "--" to EM DASH (—) and EN DASH (–) respectively.
;; Convert "..." to HORIZONTAL ELLIPSIS (…).
;; The order of below two replacements is important!
(title (replace-regexp-in-string "---\\([^-]\\)" "" title)) ;EM DASH
(title (replace-regexp-in-string "--\\([^-]\\)" "" title)) ;EN DASH
(title (replace-regexp-in-string "\\.\\.\\." "" title))) ;HORIZONTAL ELLIPSIS
title)))

(defun org-hugo--transform-org-tags (tag-list info &optional no-prefer-hyphen)
Expand Down
10 changes: 9 additions & 1 deletion test/site/content-org/all-posts.org
Expand Up @@ -4,6 +4,7 @@

#+MACRO: doc [[https://ox-hugo.scripter.co/doc/$1][$2]]
#+MACRO: oxhugoissue =ox-hugo= Issue #[[https://github.com/kaushalmodi/ox-hugo/issues/$1][$1]]
#+MACRO: hugoissue =hugo= Issue #[[https://github.com/gohugoio/hugo/issues/$1][$1]]

#+AUTHOR:

Expand Down Expand Up @@ -316,6 +317,13 @@ get escaped.. =foo_bar= must not become =foo\_bar=.
:END:
This post will be exported without =title= in the front-matter because
it is explicitly set to /empty/ using =:EXPORT_TITLE:=.
** En dash --, Em dash ---, Horizontal ellipsis ... in titles :@upstream:
:PROPERTIES:
:EXPORT_FILE_NAME: en-dash-em-dash-hellip-in-titles
:END:
This tests an =ox-hugo= feature that gets around an upstream
limitation, where the Blackfriday /smartDashes/ rendering does not
happen in post titles ({{{hugoissue(4175)}}}).
* Description meta-data with "quoted text"
:PROPERTIES:
:EXPORT_FILE_NAME: post-description-quotes
Expand Down Expand Up @@ -782,7 +790,7 @@ Test that indented source blocks export fine.
(message "And now I am at level-0 indentation")
#+END_SRC

Reference -- [[https://github.com/gohugoio/hugo/issues/4006][hugo#4006]]
Reference: {{{hugoissue(4006)}}}
** Markdown source block with Hugo shortcodes :shortcode:
:PROPERTIES:
:EXPORT_FILE_NAME: source-block-md-with-hugo-shortcodes
Expand Down
10 changes: 10 additions & 0 deletions test/site/content/posts/en-dash-em-dash-hellip-in-titles.md
@@ -0,0 +1,10 @@
+++
title = "En dash – Em dash — Horizontal ellipsis … in titles"
tags = ["title"]
categories = ["upstream"]
draft = false
+++

This tests an `ox-hugo` feature that gets around an upstream
limitation, where the Blackfriday _smartDashes_ rendering does not
happen in post titles (`hugo` Issue #[4175](https://github.com/gohugoio/hugo/issues/4175)).
2 changes: 1 addition & 1 deletion test/site/content/posts/source-block-indented.md
Expand Up @@ -50,4 +50,4 @@ Test that indented source blocks export fine.
(message "And now I am at level-0 indentation")
```

Reference -- [hugo#4006](https://github.com/gohugoio/hugo/issues/4006)
Reference: `hugo` Issue #[4006](https://github.com/gohugoio/hugo/issues/4006)

0 comments on commit 0f38756

Please sign in to comment.