Skip to content

Commit

Permalink
Disable special string insertion by Org; Title sanitization
Browse files Browse the repository at this point in the history
- Blackfriday automatically renders "--" as en-dash, "---" as em-dash and
  so on. So there is no need for Org to replace those with the HTML
  special characters in the Markdown itself.  This also makes the
  Markdown more readable.
- Titles are now sanitized. HTML anyways does not allow bold, italics,
  etc markup in the <title> section. Now Markdown markup for the same
  are removed from the title variable in front matter.
  • Loading branch information
kaushalmodi committed Jul 22, 2017
1 parent fe39046 commit 669056d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
20 changes: 20 additions & 0 deletions example-site/content-org/all-posts.org
Expand Up @@ -443,6 +443,26 @@ The strings in these two columns should look the exact same.
*Note:* There is a rendering issue is Row 5 above. That seems to be a
corner case, because notice that Row 6 looks fine just because there
was a trailing period. /Will live with this issue for now./
** /ndash/ `and` *mdash*
:PROPERTIES:
:EXPORT_FILE_NAME: ndash-and-mdash
:EXPORT_DATE: 2017-07-22
:END:
The strings in these two columns should look the exact same.
| | Character | Rendered Actual | Rendered Expection |
|---+-----------+-----------------+--------------------|
| 1 | Hyphen | a - b | a - b |
| 2 | Ndash | a -- b | a – b |
| 3 | Mdash | a --- b | a — b |
| 4 | Ellipsis | a ... b | a … b |
#+TBLFM: $1=@#-1
*** Title sanitization
This post has italics, monospace and bold in the title. This is to
test that those markup characters *do not* end up in the =title= front
matter of the post because HTML does not allow markup in the =<title>=
section.

So the title of this post should read as "ndash and mdash".
* Footnotes Test :footnote:
** Footnotes 1
:PROPERTIES:
Expand Down
2 changes: 1 addition & 1 deletion example-site/content/posts/dealing-with-underscores.md
Expand Up @@ -14,4 +14,4 @@ This underscore also shouldn't be escaped as it's in an emoji
code: :raised_hands:

And these ones should be eventually removed and <span class="underline">underline</span> the text
(_Requires CSS to do so._) &#x2013; **Org syntax**.
(_Requires CSS to do so._) -- **Org syntax**.
25 changes: 25 additions & 0 deletions example-site/content/posts/ndash-and-mdash.md
@@ -0,0 +1,25 @@
+++
title = "ndash and mdash"
date = 2017-07-22
tags = ["body"]
draft = false
+++

The strings in these two columns should look the exact same.

| Character | Rendered Actual | Rendered Expection
---|-----------|-----------------|-------------------
1 | Hyphen | a - b | a - b
2 | Ndash | a -- b | a – b
3 | Mdash | a --- b | a — b
4 | Ellipsis | a ... b | a … b


## Title sanitization {#title-sanitization}

This post has italics, monospace and bold in the title. This is to
test that those markup characters **do not** end up in the `title` front
matter of the post because HTML does not allow markup in the `<title>`
section.

So the title of this post should read as "ndash and mdash".
2 changes: 1 addition & 1 deletion example-site/content/posts/shortcode-src-blocks.md
@@ -1,5 +1,5 @@
+++
title = "Source blocks with Hugo `highlight` shortcode"
title = "Source blocks with Hugo highlight shortcode"
date = 2017-07-13T17:57:58-04:00
tags = []
draft = false
Expand Down
5 changes: 5 additions & 0 deletions ox-hugo.el
Expand Up @@ -133,6 +133,7 @@ directory where all Hugo posts should go by default."
(:with-toc nil "toc" nil) ;No TOC by default
(:preserve-breaks nil "\\n" t) ;Preserve breaks so that text filling in Markdown matches that of Org
(:with-smart-quotes nil "'" nil) ;Don't use smart quotes; that is done automatically by Blackfriday
(:with-special-strings nil "-" nil) ;Don't use special strings for ndash, mdash; that is done automatically by Blackfriday
(:hugo-front-matter-format "HUGO_FRONT_MATTER_FORMAT" nil org-hugo-front-matter-format)
(:hugo-level-offset "HUGO_LEVEL_OFFSET" nil 1)
(:hugo-section "HUGO_SECTION" nil org-hugo-default-section-directory)
Expand Down Expand Up @@ -639,6 +640,10 @@ INFO is a plist used as a communication channel."
(org-export-data (plist-get info :hugo-tags) info) " "
(org-export-data (plist-get info :tags) info))))
(title (org-export-data (plist-get info :title) info))
;; Sanitize title.. cannot do bold, italics, monospace in title
(title (replace-regexp-in-string "\\\\?`" "" title))
(title (replace-regexp-in-string "\\`__?\\|\\`\\*\\*?\\|__?\\'\\|\\*\\*?\\'" "" title))
(title (replace-regexp-in-string " __?\\|__? \\| \\*\\*?\\|\\*\\*? " " " title))
(menu-alist (org-hugo--parse-menu-prop-to-alist (plist-get info :hugo-menu)))
(menu-alist-override (org-hugo--parse-menu-prop-to-alist (plist-get info :hugo-menu-override)))
;; If menu-alist-override is non-nil, update menu-alist with values from that.
Expand Down

0 comments on commit 669056d

Please sign in to comment.