Wrapping each line of verse in a <span>? [Rime of the Ancient Mariner]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrapping each line of verse in a <span>? [Rime of the Ancient Mariner]

sethwoodworth
I have a fork of the Project Gutenberg copy of Rime of the Ancient Mariner.
The format is a simple text file of the poem.
I've been looking around at markup formats, and I really like asciidoc.
So I'm porting *Rime* to asciidoc.

With a couple of hours of doc reading, I was able to make a really great looking rendered html copy of the poem.  
The source is on github automatically rendered into also pretty nice looking html.

I'm looking for some advice about how to correctly tag for verse in asciidoc.  
The book is broken into 7 sections with `== PART THE NTH`.
Then I wrap the internal text with:

    [verse]
    ____
    ... text
    ____

Does this sound like the right semantic markup?

Separate question, how should I extend verse block rendering to:
   - wrap each line with a span.line
   - wrap each paragraph break with p.stanza

My understanding is I should probably make a new backend (template?) like this  erb html verse parser from asciidoctor-backends?

--Seth
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping each line of verse in a <span>? [Rime of the Ancient Mariner]

jxxcarlson
I prefer this solution:

[verse]
--
<TEXT OF POEM>
--

Of course if there is a complicated format, this won't work.
But the idea is to define [verse] so that "inside" it you do
not have to do anything.  See, for example,

http://www.noteshare.io/notebook/90/?note=592
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping each line of verse in a <span>? [Rime of the Ancient Mariner]

mojavelinux
Administrator
Any of these are equally correct:

[source,asciidoc]
----
[verse] 
____ 
<TEXT OF POEM> 
____ 
----

[source,asciidoc]
----
[verse] 
""
<TEXT OF POEM> 
""
----

or

[source,asciidoc]
----
[verse]
--
<TEXT OF POEM>
--
----

As you suggested, the most convenient way to custom the output is to supply a custom template. I much prefer haml or slim over erb because it's more human readable.

Here's an example of how you would accomplish your two goals.

First, create the file verse.html.slim:

.verse.html.slim
[source,slim]
----
.verseblock id=@id class=role
  - if title?
    .title=title
  pre.content
    =content.gsub(/^.+$/, '<span>\0</span>').gsub(/(.+?)(?:\n\n|\Z)/m, %(\n<p class="stanza">\\1</p>))
  - attribution = (attr? :attribution) ? (attr :attribution) : nil
  - citetitle = (attr? :citetitle) ? (attr :citetitle) : nil 
  - if attribution || citetitle
    .attribution
      - if citetitle
        cite=citetitle
      - if attribution
        - if citetitle
          br 
        | &#8212; #{attribution}
----

The key line is the one containing the gsub calls. The first gsub wraps a <span> around any non-blank line. The second gsub wraps a <p class="stanza"> around contiguous lines (i.e., lines in a single stanza).

Put the file verse.html.slim in a folder named templates (or whatever you want to call it), then invoke Asciidoctor as:

 $ asciidoctor -T templates rime.adoc

Make sure you the slim, tilt and, optionally, thread_safe gems:

 $ gem install slim tilt thread_safe

Good luck!

-Dan

On Fri, Sep 19, 2014 at 10:25 PM, jxxcarlson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I prefer this solution:

[verse]
--
<TEXT OF POEM>
--

Of course if there is a complicated format, this won't work.
But the idea is to define [verse] so that "inside" it you do
not have to do anything.  See, for example,

http://www.noteshare.io/notebook/90/?note=592


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Wrapping-each-line-of-verse-in-a-span-Rime-of-the-Ancient-Mariner-tp2253p2254.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--