From 4919415a8a89ac02fad1a950eb039e514e0cffcd Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Thu, 8 Feb 2018 13:30:41 -0500 Subject: [PATCH] Fix error when trying to highlight only 1 line Also add a test case for that. --- ox-hugo.el | 22 ++++++++++++++---- test/site/content-org/all-posts.org | 17 ++++++++++++++ .../posts/source-block-with-highlighting.md | 23 +++++++++++++++++++ test/site/themes/bare_min | 2 +- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/ox-hugo.el b/ox-hugo.el index 07e56fd..7de3f26 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -868,9 +868,18 @@ is in progress. See `org-hugo--before-export-function' and (dolist (param parameters) (dolist (retain-key param-keys-to-be-retained) (when (equal retain-key (car param)) - (setq str (concat str " " - (symbol-name retain-key) " " - (cdr param)))))) + (let ((val (cdr param))) + (setq str + (concat str " " + (symbol-name retain-key) " " + (cond + ((stringp val) + val) + ((numberp val) + (number-to-string val)) + (t + (user-error "Invalid value %S assigned to %S" + val retain-key))))))))) (org-string-nw-p (org-trim str)))) ret) ;; (message "[ox-hugo ob-exp] info: %S" info) @@ -2020,8 +2029,11 @@ channel." (parameters-str (org-element-property :parameters src-block)) (parameters (org-babel-parse-header-arguments parameters-str)) (hl-lines (cdr (assoc :hl_lines parameters))) - (hl-lines (when hl-lines - (replace-regexp-in-string "," " " hl-lines))) ;"1,3-4" -> "1 3-4" + (hl-lines (cond + ((stringp hl-lines) + (replace-regexp-in-string "," " " hl-lines)) ;"1,3-4" -> "1 3-4" + ((numberp hl-lines) + (number-to-string hl-lines)))) (label (let ((lbl (and (org-element-property :name src-block) (org-export-get-reference src-block info)))) (if lbl diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 6ee9406..894836e 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -1147,6 +1147,15 @@ page/container width. This could be either called a bug in Hugo, or the HTML limitation. A workaround is below.. *use line numbers too!*. +****** Highlighting only 1 line +******* Org source +#+begin_src org :noweb yes +<> +#+end_src +******* Output +#+begin_src org :noweb yes :exports results :results output replace :eval yes +<> +#+end_src **** With line numbers *not* starting from 1 :PROPERTIES: :CUSTOM_ID: source-blocks-with-highlighting-with-linenums-not-starting-from-1 @@ -5528,6 +5537,14 @@ So, for emacs version 25.0.50.1, this variable will be 25_0.") :PROPERTIES: :CUSTOM_ID: source-block-with-line-highlighting-examples :END: +#+begin_src org :noweb-ref src-block-hl-without-n-just-1-line +,#+begin_src emacs-lisp :hl_lines 2 +(message "This is line 1") +(message "This is line 2") +(message "This is line 3") +,#+end_src +#+end_src + #+begin_src org :noweb-ref src-block-hl-without-n ,#+begin_src emacs-lisp :hl_lines 1,3-5 (message "This is line 1") diff --git a/test/site/content/posts/source-block-with-highlighting.md b/test/site/content/posts/source-block-with-highlighting.md index 8e81a45..6bf7ec0 100644 --- a/test/site/content/posts/source-block-with-highlighting.md +++ b/test/site/content/posts/source-block-with-highlighting.md @@ -39,6 +39,29 @@ the HTML limitation. A workaround is below.. **use line numbers too!**. +#### Highlighting only 1 line {#highlighting-only-1-line} + + +##### Org source {#org-source} + +```org +#+begin_src emacs-lisp :hl_lines 2 +(message "This is line 1") +(message "This is line 2") +(message "This is line 3") +#+end_src +``` + + +##### Output {#output} + +{{< highlight emacs-lisp "hl_lines=2" >}} +(message "This is line 1") +(message "This is line 2") +(message "This is line 3") +{{< /highlight >}} + + ## With line numbers **not** starting from 1 {#source-blocks-with-highlighting-with-linenums-not-starting-from-1} With line numbers enabled, the highlighting is limited to the width of diff --git a/test/site/themes/bare_min b/test/site/themes/bare_min index 083f86e..4f1f3d1 160000 --- a/test/site/themes/bare_min +++ b/test/site/themes/bare_min @@ -1 +1 @@ -Subproject commit 083f86e585548dbf9c0b3e00246f9daa6e87863f +Subproject commit 4f1f3d129b1043232f15c65cf4255d6f8dd6540b