Skip to content

Commit a49554b

Browse files
committed
Body wrapper customization (prologue and epilogue)
Add markdown-xhtml-body-preamble and markdown-xhtml-body-epilogue variables for wrapping additional XHTML tags around the output. Based on pull request GH-281 by Jimmy Yuen Ho Wong (@wyuenho). Closes GH-280.
1 parent 34ed009 commit a49554b

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
`help-mode`. ([GH-296][])
4141
- Optionally add footnote definitions to the end of the imenu
4242
index using `markdown-add-footnotes-to-imenu`. ([GH-235][])
43+
- Add custom variables `markdown-xhtml-body-preamble` and
44+
`markdown-xhtml-body-epilogue` for wrapping additional XHTML
45+
tags around the output. ([GH-280][], [GH-281][])
4346

4447
* Improvements:
4548

@@ -130,6 +133,8 @@
130133
[gh-275]: https://github.com/jrblevin/markdown-mode/issues/275
131134
[gh-276]: https://github.com/jrblevin/markdown-mode/issues/276
132135
[gh-277]: https://github.com/jrblevin/markdown-mode/pull/277
136+
[gh-280]: https://github.com/jrblevin/markdown-mode/issues/280
137+
[gh-281]: https://github.com/jrblevin/markdown-mode/pull/281
133138
[gh-284]: https://github.com/jrblevin/markdown-mode/issues/284
134139
[gh-291]: https://github.com/jrblevin/markdown-mode/issues/291
135140
[gh-296]: https://github.com/jrblevin/markdown-mode/issues/296

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,16 @@ provides an interface to all of the possible customizations:
762762
* `markdown-xhtml-header-content` - additional content to include
763763
in the XHTML `<head>` block (default: `""`).
764764

765+
* `markdown-xhtml-body-preamble` - additional content to include in
766+
the XHTML <body> block, before the output (default: `""`). This
767+
is useful for enclosing additional elements around the Markdown
768+
output.
769+
770+
* `markdown-xhtml-body-epilogue` - additional content to include in
771+
the XHTML <body> block, after the output (default: `""`). This is
772+
useful for enclosing additional elements around the Markdown
773+
output.
774+
765775
* `markdown-xhtml-standalone-regexp` - a regular expression which
766776
`markdown-mode` uses to determine whether the output of
767777
`markdown-command` is a standalone XHTML document or an XHTML

markdown-mode.el

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ exporting with `markdown-export'."
353353
:group 'markdown
354354
:type 'string)
355355

356+
(defcustom markdown-xhtml-body-preamble ""
357+
"Content to include in the XHTML <body> block, before the output."
358+
:group 'markdown
359+
:type 'string
360+
:safe 'stringp
361+
:package-version '(markdown-mode . "2.4"))
362+
363+
(defcustom markdown-xhtml-body-epilogue ""
364+
"Content to include in the XHTML <body> block, after the output."
365+
:group 'markdown
366+
:type 'string
367+
:safe 'stringp
368+
:package-version '(markdown-mode . "2.4"))
369+
356370
(defcustom markdown-xhtml-standalone-regexp
357371
"^\\(<\\?xml\\|<!DOCTYPE\\|<html\\)"
358372
"Regexp indicating whether `markdown-command' output is standalone XHTML."
@@ -7251,7 +7265,11 @@ Standalone XHTML output is identified by an occurrence of
72517265
(insert markdown-xhtml-header-content))
72527266
(insert "\n</head>\n\n"
72537267
"<body>\n\n")
7268+
(when (> (length markdown-xhtml-body-preamble) 0)
7269+
(insert markdown-xhtml-body-preamble "\n"))
72547270
(goto-char (point-max))
7271+
(when (> (length markdown-xhtml-body-epilogue) 0)
7272+
(insert "\n" markdown-xhtml-body-epilogue))
72557273
(insert "\n"
72567274
"</body>\n"
72577275
"</html>\n"))

tests/markdown-test.el

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5140,6 +5140,36 @@ This includes preserving whitespace after the pipe."
51405140
;; Output buffer should be killed.
51415141
(should-not export-buffer))))
51425142

5143+
(ert-deftest test-markdown-export/body-preamble ()
5144+
"Test `markdown-xhtml-body-preamble'."
5145+
(markdown-test-temp-file "inline.text"
5146+
(let* ((str "<!-- body preamble test -->")
5147+
(markdown-xhtml-body-preamble str)
5148+
(markdown-command #'markdown-command-identity)
5149+
(markdown-export-kill-buffer nil)
5150+
(ofile (markdown-export))
5151+
(obuffer (get-file-buffer ofile)))
5152+
(with-current-buffer obuffer
5153+
(goto-char (point-min))
5154+
(should (search-forward str)))
5155+
(kill-buffer obuffer)
5156+
(delete-file ofile))))
5157+
5158+
(ert-deftest test-markdown-export/body-epilogue ()
5159+
"Test `markdown-xhtml-body-epilogue'."
5160+
(markdown-test-temp-file "inline.text"
5161+
(let* ((str "<!-- body epilogue test -->")
5162+
(markdown-xhtml-body-epilogue str)
5163+
(markdown-command #'markdown-command-identity)
5164+
(markdown-export-kill-buffer nil)
5165+
(ofile (markdown-export))
5166+
(obuffer (get-file-buffer ofile)))
5167+
(with-current-buffer obuffer
5168+
(goto-char (point-min))
5169+
(should (search-forward str)))
5170+
(kill-buffer obuffer)
5171+
(delete-file ofile))))
5172+
51435173
;;; Hook tests:
51445174

51455175
(ert-deftest test-markdown-hook/before-export ()

0 commit comments

Comments
 (0)