Skip to content

Commit

Permalink
Strip off any HTML from the input string when deriving slug
Browse files Browse the repository at this point in the history
`org-hugo-slug' earlier stripped off only the `code' HTML tag (`<code>
.. </code>') from the input string, if present.

Now it does that for *any* HTML tag, like `span' (only inside
`org-hugo-slug' when deriving the slug string). For example, `<span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>'.

Move ox-hugo_export-gh-doc function to its own file (so that only that
file needs to be evaluated if that function needs to be run directly
from within Emacs, without doing "make doc").
  • Loading branch information
kaushalmodi committed Oct 11, 2017
1 parent b35dfa0 commit 37d7a0d
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 69 deletions.
21 changes: 15 additions & 6 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,28 @@ The common =ox-hugo= export bindings are:
Do =M-x customize-group=, and select =org-export-hugo= to see the
available customization options for this package.
* Changelog
** 0.2.2 <2017-10-10 Tue>
** v0.2.3 <2017-10-11 Wed>
*** Fixes
- =org-hugo-slug= earlier stripped off only the =code= HTML tag
(~<code> .. </code>~) from the input string, if present. Now it does
that for *any* HTML tag, like =span=. For example, this HTML gets
stripped off from the above heading (only inside =org-hugo-slug=
when deriving the slug string): ~<span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>~.
** v0.2.2 <2017-10-10 Tue>
*** Backward-incompatible changes
- Now =ox-hugo= by default requires text, to be sub/super-scripted, to
be wrapped in ={}=. So now =a_b= will be exported as =a_b=, but
=a_{b}= will be exported as =a<sub>b</sub>=. To revert back to the
earlier behavior, user needs to add =#+OPTIONS: ^:t= to their Org
file.
** 0.2.1 <2017-09-28 Thu>
** v0.2.1 <2017-09-28 Thu>
*** Fixes
- Single column tables now export correctly [[[https://github.com/kaushalmodi/ox-hugo/issues/84][84]]].
- Ignore =HUGO_WEIGHT= set to =auto= for /per-file/ exports
[[[https://github.com/kaushalmodi/ox-hugo/issues/83][83]]].
** 0.2 <2017-09-27 Wed>
** v0.2 <2017-09-27 Wed>
*** Features
- Add support for all Hugo =figure= shortcode parameters
[[[https://github.com/kaushalmodi/ox-hugo/issues/79][79]]].
Expand All @@ -184,17 +193,17 @@ available customization options for this package.
*** Backward-incompatible changes
- Switch the default value of =org-hugo-use-code-for-kbd= option to
=nil= [[[https://github.com/kaushalmodi/ox-hugo/commit/88ba15ae9bc809b0983315446c88fecfda3534e5][88ba15ae]]].
** 0.1.3 <2017-09-13 Wed>
** v0.1.3 <2017-09-13 Wed>
- Now a HUGO key value set to ="nil"=, like =#+HUGO_CODE_FENCE: nil=,
will evaluate as /nil/ instead of /t/, as now
=org-hugo--plist-get-true-p= is used to parse boolean keys instead
of =plist-get=.
** 0.1.2 <2017-09-12 Tue>
** v0.1.2 <2017-09-12 Tue>
- Make DateTime matching better; new internal variable
=org-hugo--date-time-regexp=. Earlier time zones ahead of UTC (with
=+= sign) were not detected as dates in =org-hugo--quote-string= and
thus were unnecessarily quoted.
** 0.1.1 <2017-09-11 Mon>
** v0.1.1 <2017-09-11 Mon>
- Use CLOSED log drawer info if available to set the date in
front-matter [[[https://github.com/kaushalmodi/ox-hugo/issues/68][68]]].
- Code optimization: Use of =org-entry-get= at places instead of
Expand Down
26 changes: 20 additions & 6 deletions doc/content/doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ draft = false
identifier = "changelog"
+++

## 0.2.2 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-10 Tue&gt;</span></span> {#0-dot-2-dot-2-span-class-timestamp-wrapper-span-class-timestamp-and-lt-2017-10-10-tue-and-gt-span-span}
## v0.2.3 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11 Wed&gt;</span></span> {#v0-dot-2-dot-3}


### Fixes {#fixes}

- `org-hugo-slug` earlier stripped off only the `code` HTML tag
(`<code> .. </code>`) from the input string, if present. Now it does
that for **any** HTML tag, like `span`. For example, this HTML gets
stripped off from the above heading (only inside `org-hugo-slug`
when deriving the slug string): `<span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>`.


## v0.2.2 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-10 Tue&gt;</span></span> {#v0-dot-2-dot-2}


### Backward-incompatible changes {#backward-incompatible-changes}
Expand All @@ -18,7 +32,7 @@ draft = false
file.


## 0.2.1 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-28 Thu&gt;</span></span> {#0-dot-2-dot-1-span-class-timestamp-wrapper-span-class-timestamp-and-lt-2017-09-28-thu-and-gt-span-span}
## v0.2.1 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-28 Thu&gt;</span></span> {#v0-dot-2-dot-1}


### Fixes {#fixes}
Expand All @@ -28,7 +42,7 @@ draft = false
[[83](https://github.com/kaushalmodi/ox-hugo/issues/83)].


## 0.2 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-27 Wed&gt;</span></span> {#0-dot-2-span-class-timestamp-wrapper-span-class-timestamp-and-lt-2017-09-27-wed-and-gt-span-span}
## v0.2 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-27 Wed&gt;</span></span> {#v0-dot-2}


### Features {#features}
Expand Down Expand Up @@ -58,23 +72,23 @@ draft = false
`nil` [[88ba15ae](https://github.com/kaushalmodi/ox-hugo/commit/88ba15ae9bc809b0983315446c88fecfda3534e5)].


## 0.1.3 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-13 Wed&gt;</span></span> {#0-dot-1-dot-3-span-class-timestamp-wrapper-span-class-timestamp-and-lt-2017-09-13-wed-and-gt-span-span}
## v0.1.3 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-13 Wed&gt;</span></span> {#v0-dot-1-dot-3}

- Now a HUGO key value set to `"nil"`, like `#+HUGO_CODE_FENCE: nil`,
will evaluate as _nil_ instead of _t_, as now
`org-hugo--plist-get-true-p` is used to parse boolean keys instead
of `plist-get`.


## 0.1.2 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-12 Tue&gt;</span></span> {#0-dot-1-dot-2-span-class-timestamp-wrapper-span-class-timestamp-and-lt-2017-09-12-tue-and-gt-span-span}
## v0.1.2 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-12 Tue&gt;</span></span> {#v0-dot-1-dot-2}

- Make DateTime matching better; new internal variable
`org-hugo--date-time-regexp`. Earlier time zones ahead of UTC (with
`+` sign) were not detected as dates in `org-hugo--quote-string` and
thus were unnecessarily quoted.


## 0.1.1 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-11 Mon&gt;</span></span> {#0-dot-1-dot-1-span-class-timestamp-wrapper-span-class-timestamp-and-lt-2017-09-11-mon-and-gt-span-span}
## v0.1.1 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-09-11 Mon&gt;</span></span> {#v0-dot-1-dot-1}

- Use CLOSED log drawer info if available to set the date in
front-matter [[68](https://github.com/kaushalmodi/ox-hugo/issues/68)].
Expand Down
56 changes: 56 additions & 0 deletions doc/ox-hugo-export-gh-doc.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
;; Time-stamp: <2017-10-11 04:28:38 kmodi>

;; Export Org document to GitHub documents like README.org,
;; CONTRIBUTING.org.

(defvar ox-hugo-git-root (progn
(require 'vc-git)
(file-truename (vc-git-root "."))))

(defun ox-hugo-export-gh-doc ()
"Export `ox-hugo' Org documentation to documentation on GitHub repo."
(interactive)
(let* ((ox-hugo-doc-dir (concat ox-hugo-git-root "doc/"))
(org-src-preserve-indentation t) ;Preserve the leading whitespace in src blocks
(org-id-track-globally nil) ;Prevent "Could not read org-id-values .." error
(org-export-with-sub-superscripts '{})
(org-export-with-smart-quotes t)
(org-export-headline-levels 4)
(org-src-fontify-natively t)
(subtree-tags-to-export '("readme" "contributing"))
;; If a subtree matches a tag, do not try to export further
;; subtrees separately that could be under that.
(org-use-tag-inheritance nil)
(org-export-time-stamp-file nil) ;Do not print "Created <timestamp>" in exported files
(org-export-with-toc nil)) ;Do not export TOC
(dolist (tag subtree-tags-to-export)
(let* (;;Retain tags only in the README; needed for `toc-org-insert-toc' to work
(org-export-with-tags (if (string= tag "readme") t nil))
(exported-file-list (org-map-entries '(org-org-export-to-org nil :subtreep) tag)))
;; Move files to their correct directories
(cond
((or (string= "readme" tag)
(string= "contributing" tag))
(dolist (exported-file exported-file-list)
(rename-file (expand-file-name exported-file ox-hugo-doc-dir)
(expand-file-name exported-file ox-hugo-git-root)
:ok-if-already-exists)))
(t
nil))))
;; Generate TOC in README.org using the `toc-org' package.
(let ((readme-buf (get-buffer "README.org"))
(readme-file (expand-file-name "README.org" ox-hugo-git-root)))
(when readme-buf ;Close README.org if it's already open
(kill-buffer readme-buf))
;; Open the README.org file afresh.
(setq readme-buf (find-file-noselect readme-file))
(with-current-buffer readme-buf
(require 'toc-org)
(toc-org-insert-toc)
;; Now remove all Org tags from the README
(goto-char (point-min))
(while (replace-regexp "^\\(\\* .*?\\)[[:blank:]]*:[^[:blank:]]+:$" "\\1"))
(save-buffer)))))


(provide 'ox-hugo-export-gh-doc)
21 changes: 15 additions & 6 deletions doc/ox-hugo-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@
:PROPERTIES:
:CUSTOM_ID: changelog
:END:
** 0.2.2 <2017-10-10 Tue>
** v0.2.3 <2017-10-11 Wed>
*** Fixes
- =org-hugo-slug= earlier stripped off only the =code= HTML tag
(~<code> .. </code>~) from the input string, if present. Now it does
that for *any* HTML tag, like =span=. For example, this HTML gets
stripped off from the above heading (only inside =org-hugo-slug=
when deriving the slug string): ~<span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>~.
** v0.2.2 <2017-10-10 Tue>
*** Backward-incompatible changes
- Now =ox-hugo= by default requires text, to be sub/super-scripted, to
be wrapped in ={}=. So now =a_b= will be exported as =a_b=, but
=a_{b}= will be exported as =a<sub>b</sub>=. To revert back to the
earlier behavior, user needs to add =#+OPTIONS: ^:t= to their Org
file.
** 0.2.1 <2017-09-28 Thu>
** v0.2.1 <2017-09-28 Thu>
*** Fixes
- Single column tables now export correctly {{{issue(84)}}}.
- Ignore =HUGO_WEIGHT= set to =auto= for /per-file/ exports
{{{issue(83)}}}.
** 0.2 <2017-09-27 Wed>
** v0.2 <2017-09-27 Wed>
*** Features
- Add support for all Hugo =figure= shortcode parameters
{{{issue(79)}}}.
Expand All @@ -42,17 +51,17 @@
*** Backward-incompatible changes
- Switch the default value of =org-hugo-use-code-for-kbd= option to
=nil= [[[https://github.com/kaushalmodi/ox-hugo/commit/88ba15ae9bc809b0983315446c88fecfda3534e5][88ba15ae]]].
** 0.1.3 <2017-09-13 Wed>
** v0.1.3 <2017-09-13 Wed>
- Now a HUGO key value set to ="nil"=, like =#+HUGO_CODE_FENCE: nil=,
will evaluate as /nil/ instead of /t/, as now
=org-hugo--plist-get-true-p= is used to parse boolean keys instead
of =plist-get=.
** 0.1.2 <2017-09-12 Tue>
** v0.1.2 <2017-09-12 Tue>
- Make DateTime matching better; new internal variable
=org-hugo--date-time-regexp=. Earlier time zones ahead of UTC (with
=+= sign) were not detected as dates in =org-hugo--quote-string= and
thus were unnecessarily quoted.
** 0.1.1 <2017-09-11 Mon>
** v0.1.1 <2017-09-11 Mon>
- Use CLOSED log drawer info if available to set the date in
front-matter {{{issue(68)}}}.
- Code optimization: Use of =org-entry-get= at places instead of
Expand Down
9 changes: 5 additions & 4 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; URL: https://ox-hugo.scripter.co
;; Package-Requires: ((emacs "24.5") (org "9.0"))
;; Keywords: Org, markdown, docs
;; Version: 0.2.2
;; Version: 0.2.3

;;; Commentary:

Expand Down Expand Up @@ -689,7 +689,8 @@ returned slug string has the following specification:
- Should contain only lower case alphabet, number and hyphen
characters.
- Remove \"<code>..</code>\" part from STR if present.
- Remove *any* HTML tag like \"<code>..</code>\", \"<span
class=..>..</span>\", etc. from STR if present.
- URLs if present in STR should be removed.
- Replace \".\" in STR with \"and\", and \"&\" with \"and\".
- Parentheses should be replaced with double-hyphens ( \"foo (bar)
Expand All @@ -701,8 +702,8 @@ returned slug string has the following specification:
returned string ."
(let* (;; All lower-case
(str (downcase str))
;; Remove "<code>..</code>" stuff if present.
(str (replace-regexp-in-string "<code>.*</code>" "" str))
;; Remove "<FOO>..</FOO>" HTML tags if present.
(str (replace-regexp-in-string "<\\(?1:[a-z]+\\)[^>]*>.*</\\1>" "" str))
;; Remove URLs if present in the string. The ")" in the
;; below regexp is the closing parenthesis of a Markdown
;; link: [Desc](Link).
Expand Down
53 changes: 6 additions & 47 deletions test/setup-ox-hugo.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;; Time-stamp: <2017-10-10 12:13:14 kmodi>
;; Time-stamp: <2017-10-11 04:31:46 kmodi>

;; Setup to test ox-hugo using emacs -Q and the latest stable version of Org
;; Setup to test ox-hugo using emacs -Q and the latest stable version
;; of Org.

;; Some sane settings
(setq-default require-final-newline t)
Expand Down Expand Up @@ -83,7 +84,8 @@ Emacs installation. If Emacs is installed using
(url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
(add-to-list 'package-archives (cons "melpa" url) :append))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") :append) ;For latest `org'
(add-to-list 'load-path ox-hugo-git-root)
(add-to-list 'load-path ox-hugo-git-root) ;For ox-hugo.el, ox-blackfriday.el
(add-to-list 'load-path (concat ox-hugo-git-root "doc/")) ;For ox-hugo-export-gh-doc.el

;; Load emacs packages and activate them.
;; Don't delete this line.
Expand Down Expand Up @@ -125,50 +127,7 @@ to be installed.")
(defun org-hugo-export-all-subtrees-to-md ()
(org-hugo-export-subtree-to-md :all-subtrees))

(defun ox-hugo-export-gh-doc ()
"Export `ox-hugo' Org documentation to documentation on GitHub repo."
(interactive)
(let* ((ox-hugo-doc-dir (concat ox-hugo-git-root "doc/"))
(org-src-preserve-indentation t) ;Preserve the leading whitespace in src blocks
(org-id-track-globally nil) ;Prevent "Could not read org-id-values .." error
(org-export-with-sub-superscripts '{})
(org-export-with-smart-quotes t)
(org-export-headline-levels 4)
(org-src-fontify-natively t)
(subtree-tags-to-export '("readme" "contributing"))
;; If a subtree matches a tag, do not try to export further
;; subtrees separately that could be under that.
(org-use-tag-inheritance nil)
(org-export-time-stamp-file nil) ;Do not print "Created <timestamp>" in exported files
(org-export-with-toc nil)) ;Do not export TOC
(dolist (tag subtree-tags-to-export)
(let* (;;Retain tags only in the README; needed for `toc-org-insert-toc' to work
(org-export-with-tags (if (string= tag "readme") t nil))
(exported-file-list (org-map-entries '(org-org-export-to-org nil :subtreep) tag)))
;; Move files to their correct directories
(cond
((or (string= "readme" tag)
(string= "contributing" tag))
(dolist (exported-file exported-file-list)
(rename-file (expand-file-name exported-file ox-hugo-doc-dir)
(expand-file-name exported-file ox-hugo-git-root)
:ok-if-already-exists)))
(t
nil))))
;; Generate TOC in README.org using the `toc-org' package.
(let ((readme-buf (get-buffer "README.org"))
(readme-file (expand-file-name "README.org" ox-hugo-git-root)))
(when readme-buf ;Close README.org if it's already open
(kill-buffer readme-buf))
;; Open the README.org file afresh.
(setq readme-buf (find-file-noselect readme-file))
(with-current-buffer readme-buf
(require 'toc-org)
(toc-org-insert-toc)
;; Now remove all Org tags from the README
(goto-char (point-min))
(while (replace-regexp "^\\(\\* .*?\\)[[:blank:]]*:[^[:blank:]]+:$" "\\1"))
(save-buffer)))))
(require 'ox-hugo-export-gh-doc) ;For `ox-hugo-export-gh-doc'

(with-eval-after-load 'org
;; Allow multiple line Org emphasis markup
Expand Down
17 changes: 17 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ Something 2.1
*** ÄËÏÖÜ
*** ÃÐÑÕÞ
*** Ç
** Headings with HTML
*** Checklist [1/3]
Above title would render to ~Checklist <code>[1/3]</code>~ in
Markdown.
**** DONE Item 1
Above would render to ~<span class="todo DONE_">DONE </span> Item 1~
in Markdown.
**** TODO Item 2
Above would render to ~<span class="todo TODO_">TODO </span> Item 2~
in Markdown.
**** TODO Item 3
Above would render to ~<span class="todo TODO_">TODO </span> Item 3~
in Markdown.
*** Version 0.1 <2017-10-11 Wed>
Above title would render to ~Version 0.1 <span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>~ in Markdown.
* Title in Front Matter
** Awesome title with "quoted text"
:PROPERTIES:
Expand Down
34 changes: 34 additions & 0 deletions test/site/content/posts/post-heading-slugs.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,37 @@ draft = false


### Ç {#ç}


## Headings with HTML {#headings-with-html}


### Checklist <code>[1/3]</code> {#checklist}

Above title would render to `Checklist <code>[1/3]</code>` in
Markdown.


#### <span class="todo DONE_">DONE </span> Item 1 {#item-1}

Above would render to `<span class="todo DONE_">DONE </span> Item 1`
in Markdown.


#### <span class="todo TODO_">TODO </span> Item 2 {#item-2}

Above would render to `<span class="todo TODO_">TODO </span> Item 2`
in Markdown.


#### <span class="todo TODO_">TODO </span> Item 3 {#item-3}

Above would render to `<span class="todo TODO_">TODO </span> Item 3`
in Markdown.


### Version 0.1 <span class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11 Wed&gt;</span></span> {#version-0-dot-1}

Above title would render to `Version 0.1 <span
class="timestamp-wrapper"><span class="timestamp">&lt;2017-10-11
Wed&gt;</span></span>` in Markdown.

0 comments on commit 37d7a0d

Please sign in to comment.