From 5c15470e619a7b8c14864a526da2eb49694f6143 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Sat, 12 May 2018 20:29:39 -0400 Subject: [PATCH] Add test for code blocks in list using highlight shortcode - https://github.com/kaushalmodi/ox-hugo/issues/161 - https://github.com/gohugoio/hugo/issues/4717 --- test/site/content-org/all-posts.org | 54 ++++++++++++++-- .../content/posts/source-block-indented.md | 64 +++++++++++++++++-- 2 files changed, 110 insertions(+), 8 deletions(-) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 262dd28e..31be601d 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -1281,11 +1281,16 @@ print(str[1:]) : bc The whitespace before "bc" in the results block above should be preserved. -** Indented source block +** Indented source block :indented:lists:code_fence:highlight:code_block:@upstream: :PROPERTIES: :EXPORT_FILE_NAME: source-block-indented :END: -Test that indented source blocks export fine. +#+begin_description +Test that indented source blocks, and also the ones in lists export +fine. +#+end_description + +Some content. #+begin_src emacs-lisp (defun small-shell () @@ -1295,7 +1300,9 @@ Test that indented source blocks export fine. (shrink-window (- (window-height) 12)) (ansi-term)) #+end_src -*** More tests! +*** Code blocks in list using code fences +Reference: {{{hugoissue(4006)}}} + - List item 1 #+begin_src emacs-lisp (message "I am in list at level-1 indentation") @@ -1320,8 +1327,47 @@ Test that indented source blocks export fine. #+begin_src emacs-lisp (message "And now I am at level-0 indentation") #+end_src +*** Code blocks in list using ~highlight~ shortcode +Reference: {{{hugoissue(4717)}}}, {{{oxhugoissue(161)}}} -Reference: {{{hugoissue(4006)}}} +This is an *upstream* bug in ~hugo~ as of 2018-05-12. The issues is +that when the code blocks in ~highlight~ shortcodes are inserted at +the required indentation levels in lists.. so that they get rendered +*in* the list at *that* indentation level, those indentations are not +removed by ~hugo~, and thus become part of those code blocks. + +Also, related to this issue, it can be seen that all such indented +code blocks have an empty second line too, probably just due to the +unremoved indentation on the last line of those code blocks. + +In the above section, the same code blocks are code-fenced instead of +using ~highlight~ shortcode, and the extra indentation is not seen +there. + +- List item 1 + #+begin_src emacs-lisp -n + (message "I am in list at level-1 indentation") + #+end_src + - List item 1.1 + #+begin_src emacs-lisp -n + (message "I am in list at level-2 indentation") + #+end_src + - List item 1.1.1 + #+begin_src emacs-lisp -n + (message "I am in list at level-3 indentation") + #+end_src + - List item 2.1 + #+begin_src emacs-lisp -n + (message "I am in list back at level-2 indentation") + #+end_src +- List item 2 + #+begin_src emacs-lisp -n + (message "I am in list back at level-1 indentation") + #+end_src + +#+begin_src emacs-lisp -n +(message "And now I am at level-0 indentation") +#+end_src ** Markdown source block with Hugo shortcodes :shortcode: :PROPERTIES: :EXPORT_FILE_NAME: source-block-md-with-hugo-shortcodes diff --git a/test/site/content/posts/source-block-indented.md b/test/site/content/posts/source-block-indented.md index 93ff2e04..de74967a 100644 --- a/test/site/content/posts/source-block-indented.md +++ b/test/site/content/posts/source-block-indented.md @@ -1,10 +1,15 @@ +++ title = "Indented source block" -tags = ["src-block"] +description = """ + Test that indented source blocks, and also the ones in lists export + fine. + """ +tags = ["src-block", "indented", "lists", "code-fence", "highlight", "code-block"] +categories = ["upstream"] draft = false +++ -Test that indented source blocks export fine. +Some content. ```emacs-lisp (defun small-shell () @@ -16,7 +21,9 @@ Test that indented source blocks export fine. ``` -## More tests! {#more-tests} +## Code blocks in list using code fences {#code-blocks-in-list-using-code-fences} + +Reference: `hugo` Issue #[4006](https://github.com/gohugoio/hugo/issues/4006) - List item 1 @@ -50,4 +57,53 @@ Test that indented source blocks export fine. (message "And now I am at level-0 indentation") ``` -Reference: `hugo` Issue #[4006](https://github.com/gohugoio/hugo/issues/4006) + +## Code blocks in list using `highlight` shortcode {#code-blocks-in-list-using-highlight-shortcode} + +Reference: `hugo` Issue #[4717](https://github.com/gohugoio/hugo/issues/4717), `ox-hugo` Issue #[161](https://github.com/kaushalmodi/ox-hugo/issues/161) + +This is an **upstream** bug in `hugo` as of 2018-05-12. The issues is +that when the code blocks in `highlight` shortcodes are inserted at +the required indentation levels in lists.. so that they get rendered +**in** the list at **that** indentation level, those indentations are not +removed by `hugo`, and thus become part of those code blocks. + +Also, related to this issue, it can be seen that all such indented +code blocks have an empty second line too, probably just due to the +unremoved indentation on the last line of those code blocks. + +In the above section, the same code blocks are code-fenced instead of +using `highlight` shortcode, and the extra indentation is not seen +there. + +- List item 1 + + {{< highlight emacs-lisp "linenos=table, linenostart=1" >}} + (message "I am in list at level-1 indentation") + {{< /highlight >}} + + - List item 1.1 + + {{< highlight emacs-lisp "linenos=table, linenostart=1" >}} + (message "I am in list at level-2 indentation") + {{< /highlight >}} + + - List item 1.1.1 + + {{< highlight emacs-lisp "linenos=table, linenostart=1" >}} + (message "I am in list at level-3 indentation") + {{< /highlight >}} + - List item 2.1 + + {{< highlight emacs-lisp "linenos=table, linenostart=1" >}} + (message "I am in list back at level-2 indentation") + {{< /highlight >}} +- List item 2 + + {{< highlight emacs-lisp "linenos=table, linenostart=1" >}} + (message "I am in list back at level-1 indentation") + {{< /highlight >}} + +{{< highlight emacs-lisp "linenos=table, linenostart=1" >}} +(message "And now I am at level-0 indentation") +{{< /highlight >}}