Skip to content

Commit

Permalink
fix: Do ensure a blank line after a captioned src or example block!
Browse files Browse the repository at this point in the history
The src and example block captions are wrapped in HTML div tags. As
per CommonMark, the block HTML tags like div tags need to be separated
from Markdown by at least one blank line.
  • Loading branch information
kaushalmodi committed May 27, 2022
1 parent ace25a6 commit aa79350
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
14 changes: 11 additions & 3 deletions ox-blackfriday.el
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,11 @@ to this rule:
current item.
3. In an item, if a paragraph is immediately followed by an src
or example block (or vice-versa), don't add a blank line
between those elements."
or example block, don't add a blank line after the paragraph.
4. In an item, if an src or example block doesn't have a caption
and is immediately followed by a paragraph, don't add a blank
line after that src or example block."
(org-element-map tree (remq 'item org-element-all-elements) ;Exception 1 in the doc-string
(lambda (el)
(let ((post-blank (cond
Expand All @@ -771,9 +774,14 @@ to this rule:
(let ((next-el (org-export-get-next-element el info)))
(memq (org-element-type next-el) '(src-block example-block))))
0)
;; Exception 3 in the doc-string (src-block -> paragraph).
;; Exception 4 in the doc-string (caption-less src-block -> paragraph).
;; If an src or example block has a caption,
;; that caption will be wrapped in an HTML
;; div block. In that case, we *do* need to
;; leave a blank line after the div block (CommonMark).
((and (memq (org-element-type el) '(src-block example-block))
(eq (org-element-type (org-element-property :parent el)) 'item)
(null (org-element-property :caption el)) ;<-- "no caption" check
(let ((next-el (org-export-get-next-element el info)))
(memq (org-element-type next-el) '(paragraph))))
0)
Expand Down
18 changes: 12 additions & 6 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -1746,20 +1746,26 @@ code block does not have Markdown syntax lists.
-----
{{{oxhugoissue(645)}}}

1. item one
2. This paragraph is followed by a source block *with* caption.
1. paragraph -> src block with caption -> paragraph -> src block
#+name: code__foo
#+caption: Foo
#+begin_src emacs-lisp
(message "hey")
#+end_src


1. item one
2. This paragraph is followed by a source block without caption.
sandwiched paragraph
#+begin_src emacs-lisp
(message "hey")
#+end_src
last paragraph
2. paragraph -> src block *without* caption -> paragraph -> src block
#+begin_src emacs-lisp
(message "hey")
#+end_src
sandwiched paragraph
#+begin_src emacs-lisp
(message "hey")
#+end_src
last paragraph
**** Source block with list syntax but not in a list
:PROPERTIES:
:EXPORT_DATE: 2017-08-01
Expand Down
18 changes: 12 additions & 6 deletions test/site/content/posts/list-has-src-block-but-no-list-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ code block does not have Markdown syntax lists.

`ox-hugo` Issue #[645](https://github.com/kaushalmodi/ox-hugo/issues/645)

1. item one
2. This paragraph is followed by a source block **with** caption.
1. paragraph -&gt; src block with caption -&gt; paragraph -&gt; src block
<a id="code-snippet--foo"></a>
```emacs-lisp
(message "hey")
Expand All @@ -32,10 +31,17 @@ code block does not have Markdown syntax lists.
Foo
</div>

<!--listend-->

1. item one
2. This paragraph is followed by a source block without caption.
sandwiched paragraph
```emacs-lisp
(message "hey")
```
last paragraph
2. paragraph -&gt; src block **without** caption -&gt; paragraph -&gt; src block
```emacs-lisp
(message "hey")
```
sandwiched paragraph
```emacs-lisp
(message "hey")
```
last paragraph

0 comments on commit aa79350

Please sign in to comment.