Skip to content

Commit

Permalink
Support verses
Browse files Browse the repository at this point in the history
Line breaks, indentation and blank lines stay preserved in Org verse
blocks.
  • Loading branch information
kaushalmodi committed Aug 1, 2017
1 parent 67d4748 commit 05aecf7
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
51 changes: 51 additions & 0 deletions example-site/content-org/all-posts.org
Expand Up @@ -812,6 +812,57 @@ Quote 3. This is a multi-paragraph quote.
This is the second paragraph.
#+END_QUOTE
Some other text.
* Verse :verse:
** One verse
:PROPERTIES:
:EXPORT_DATE: 2017-08-01
:EXPORT_FILE_NAME: one-verse
:END:
To preserve the line breaks, indentation and blank lines in a region,
but otherwise use normal formatting, you can use the /verse/
construct, which can also be used to format poetry -- [[http://orgmode.org/manual/Paragraphs.html][Reference]].
#+BEGIN_VERSE
Great clouds overhead
Tiny black birds rise and fall
Snow covers Emacs

-- AlexSchroeder
#+END_VERSE
** Consecutive verses
:PROPERTIES:
:EXPORT_DATE: 2017-08-01
:EXPORT_FILE_NAME: consecutive-verses
:END:
#+BEGIN_VERSE
Tyger Tyger, burning bright,
In the forests of the night;
What immortal hand or eye,
Could frame thy fearful symmetry?

In what distant deeps or skies.
Burnt the fire of thine eyes?
On what wings dare he aspire?
What the hand, dare seize the fire?

-- "The Tyger" /by/ William Blake
#+END_VERSE
#+BEGIN_VERSE
Some parts can be *bold*
Some can be =monospace=
Some can be /italic/ too.
#+END_VERSE
#+BEGIN_VERSE
What is this life if, full of care,
We have no time to stand and stare.

No time to stand beneath the boughs
And stare as long as sheep or cows.

No time to see, when woods we pass,
Where squirrels hide their nuts in grass.

-- "Leisure" /by/ William Henry Davis
#+END_VERSE
* TODO Pre-Draft State
:PROPERTIES:
:EXPORT_FILE_NAME: draft-state-todo
Expand Down
33 changes: 33 additions & 0 deletions example-site/content/posts/consecutive-verses.md
@@ -0,0 +1,33 @@
+++
title = "Consecutive verses"
date = 2017-08-01
tags = ["verse"]
draft = false
+++

Tyger Tyger, burning bright,<br />
In the forests of the night;<br />
What immortal hand or eye,<br />
Could frame thy fearful symmetry?<br />
<br />
In what distant deeps or skies.<br />
Burnt the fire of thine eyes?<br />
On what wings dare he aspire?<br />
What the hand, dare seize the fire?<br />
<br />
&#xa0;&#xa0;&#xa0;-- "The Tyger" _by_ William Blake<br />

Some parts can be **bold**<br />
&#xa0;&#xa0;Some can be `monospace`<br />
&#xa0;&#xa0;&#xa0;&#xa0;Some can be _italic_ too.<br />

What is this life if, full of care,<br />
We have no time to stand and stare.<br />
<br />
No time to stand beneath the boughs<br />
And stare as long as sheep or cows.<br />
<br />
No time to see, when woods we pass,<br />
Where squirrels hide their nuts in grass.<br />
<br />
&#xa0;&#xa0;&#xa0;-- "Leisure" _by_ William Henry Davis<br />
16 changes: 16 additions & 0 deletions example-site/content/posts/one-verse.md
@@ -0,0 +1,16 @@
+++
title = "One verse"
date = 2017-08-01
tags = ["verse"]
draft = false
+++

To preserve the line breaks, indentation and blank lines in a region,
but otherwise use normal formatting, you can use the _verse_
construct, which can also be used to format poetry -- [Reference](http://orgmode.org/manual/Paragraphs.html).

Great clouds overhead<br />
Tiny black birds rise and fall<br />
Snow covers Emacs<br />
<br />
&#xa0;&#xa0;&#xa0;&#xa0;-- AlexSchroeder<br />
21 changes: 19 additions & 2 deletions ox-blackfriday.el
Expand Up @@ -78,8 +78,8 @@
(example-block . org-blackfriday-example-block)
(table-cell . org-blackfriday-table-cell)
(table-row . org-blackfriday-table-row)
(table . org-blackfriday-table)))

(table . org-blackfriday-table)
(verse-block . org-blackfriday-verse-block)))


;;; Transcode Functions
Expand Down Expand Up @@ -339,6 +339,23 @@ contextual information."
;; (message "[ox-bf-table DBG] Tbl:\n%s" tbl)
tbl))

;;;; Verse Block
(defun org-blackfriday-verse-block (_verse-block contents info)
"Transcode a VERSE-BLOCK element from Org to partial HTML.
CONTENTS is verse block contents. INFO is a plist holding
contextual information."
;; Replace leading white spaces with non-breaking spaces.
(replace-regexp-in-string
"^[ \t]+"
(lambda (m)
(org-html--make-string (length m) "&#xa0;"))
;; Replace each newline character with line break. Also
;; remove any trailing "br" close-tag so as to avoid
;; duplicates.
(let* ((br (org-html-close-tag "br" nil info))
(re (format "\\(?:%s\\)?[ \t]*\n" (regexp-quote br))))
(replace-regexp-in-string re (concat br "\n") contents))))

;;;; Table of contents
(defun org-blackfriday-format-toc (headline info)
"Return an appropriate table of contents entry for HEADLINE.
Expand Down

0 comments on commit 05aecf7

Please sign in to comment.