Skip to content

Commit

Permalink
ws trimming: Fix case where there's a > char before trimmed block
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Jan 27, 2022
1 parent be849de commit 9ff4a16
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/ox-hugo-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,7 @@ will export as:

and render as:

#+header: :trim-pre nil
#+begin_mark
This sentence is marked.
#+end_mark
Expand Down
14 changes: 11 additions & 3 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1852,9 +1852,17 @@ holding export options."
(> toc-level 0)) ;TOC will be exported only if toc-level is positive
(concat (org-hugo--build-toc info toc-level) "\n")
""))
(contents (replace-regexp-in-string ;Trim stuff before selected exported elements
(concat "\\([[:space:]>]\\|\n\\)+" (regexp-quote org-hugo--trim-pre-marker))
"\n" contents))
;; Handling the case of special blocks inside markdown quote
;; blocks.
(contents (replace-regexp-in-string
(concat "\\(\n> \\)*" (regexp-quote org-hugo--trim-pre-marker))
;; ^^ Markdown quote blocks have lines beginning with "> ".
org-hugo--trim-pre-marker ;Keep the trim marker; it will be removed next.
contents))
(contents (replace-regexp-in-string
(concat "\\([[:space:]]\\|\n\\)*" (regexp-quote org-hugo--trim-pre-marker))
"\n"
contents))
(contents (replace-regexp-in-string ;Trim stuff after selected exported elements
(concat (regexp-quote org-hugo--trim-post-marker) "\\([[:space:]>]\\|\n\\)+")
"\n" contents))
Expand Down
12 changes: 12 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -4922,6 +4922,18 @@ something
#+begin_mark
marked text
#+end_mark
**** ~>~ character before a special block with ~:trim_pre~ set
#+begin_export html
<style>
.red {
color: red;
}
</style>
#+end_export
#+attr_html: :class red
#+begin_mark
This marked text's foreground is red.
#+end_mark
**** Last element of a post
#+begin_mark
No "post" trim markers should be inserted after this block as it's the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ something
<mark>marked text</mark>


## `>` character before a special block with `:trim_pre` set {#character-before-a-special-block-with-trim-pre-set}

<style>
.red {
color: red;
}
</style>
<mark class="red">This marked text's foreground is red.</mark>


## Last element of a post {#last-element-of-a-post}
<mark>No "post" trim markers should be inserted after this block as it's the
last element of this post.</mark>

0 comments on commit 9ff4a16

Please sign in to comment.