public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Typesetting Verse: converting line breaks to "paragraph" breaks
@ 2015-03-26  4:40 Case Duckworth
       [not found] ` <fdf902a7-35c5-4757-8be3-b3bfb63639d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Case Duckworth @ 2015-03-26  4:40 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 2611 bytes --]

Hi all,

I've been working on my MFA thesis with pandoc. In it, I have a good amount 
of verse/poetry typesetting (the source is viewable here 
<http://github.com/duckwork/autocento>: pandoc source in src/ folder; 
generated html and stylesheet in /). In the markdown source, I'm 
delineating line breaks with "\" at the ends of lines. In HTML, these are 
rendered with the <br /> tag.

Here's my problem: when the lines of poetry get too long for the viewport 
(either through having an overly long line or a too-narrow viewport), I 
want each line of poetry to have a hanging indent, as explained by this site 
<http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>. 
I've tried doing this purely with CSS on each line, and I'd be open to this 
solution if yall know CSS better than me, but as of now I haven't been able 
to find one that works with <br /> broken lines.

After I found out that Pandoc has the capability of filters, I looked into 
writing one for my verse pieces. Upon further research, I'm not sure this 
is even possible, given that Paragraphs are Blocks and LineBreaks are 
Inline elements in Pandoc. What I'd like to do is typeset text like this in 
the output HTML:

<section class="verse">
    <p class="stanza">
        <span class="line">Line of poetry goes here</span>
        <span class="line">Second line here</span>
        <span class="line">And so on, throughout the poem,</span>
    </p>
    <p class="stanza">
        <span class="line">even over stanza breaks.</span>
    </p>
</section>



Is there a way to do this with a Pandoc filter, in Haskell or Python or 
whatever? Is there a way to do this with a custom writer of some sort 
(though that has problems of its own, for example crashing on non-ASCII 
characters for some reason -- which is outside the scope of this question)? 
Or do I need to write some sort of postprocessor to accomplish this?

Thanks in advance for your help. Let me know if I can clarify anything.

Best,
Case Duckworth

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/fdf902a7-35c5-4757-8be3-b3bfb63639d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 7414 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found] ` <fdf902a7-35c5-4757-8be3-b3bfb63639d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-03-27  4:14   ` John MacFarlane
       [not found]     ` <20150327041452.GD35873-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
  2015-03-27 10:12   ` BP Jonsson
  2015-03-27 19:29   ` Case Duckworth
  2 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2015-03-27  4:14 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

+++ Case Duckworth [Mar 25 15 21:40 ]:
>Hi all,
>
>I've been working on my MFA thesis with pandoc. In it, I have a good amount
>of verse/poetry typesetting (the source is viewable here
><http://github.com/duckwork/autocento>: pandoc source in src/ folder;
>generated html and stylesheet in /). In the markdown source, I'm
>delineating line breaks with "\" at the ends of lines. In HTML, these are
>rendered with the <br /> tag.

Try using line blocks.  This will be easier and look nicer.
http://johnmacfarlane.net/pandoc/README.html#line-blocks

>Here's my problem: when the lines of poetry get too long for the viewport
>(either through having an overly long line or a too-narrow viewport), I
>want each line of poetry to have a hanging indent, as explained by this site
><http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>.
>I've tried doing this purely with CSS on each line, and I'd be open to this
>solution if yall know CSS better than me, but as of now I haven't been able
>to find one that works with <br /> broken lines.

Instead of <br /> broken lines, you could put each line in its own <p>,
and put the whole poem in a special <div>, then use CSS to reduce the
interparagraph spacing so it looks the way you want it to.  You could
then add the hanging indent easily with CSS.

>After I found out that Pandoc has the capability of filters, I looked into
>writing one for my verse pieces. Upon further research, I'm not sure this
>is even possible, given that Paragraphs are Blocks and LineBreaks are
>Inline elements in Pandoc. What I'd like to do is typeset text like this in
>the output HTML:
>
><section class="verse">
>    <p class="stanza">
>        <span class="line">Line of poetry goes here</span>
>        <span class="line">Second line here</span>
>        <span class="line">And so on, throughout the poem,</span>
>    </p>
>    <p class="stanza">
>        <span class="line">even over stanza breaks.</span>
>    </p>
></section>
>
>
>
>Is there a way to do this with a Pandoc filter, in Haskell or Python or
>whatever? Is there a way to do this with a custom writer of some sort
>(though that has problems of its own, for example crashing on non-ASCII
>characters for some reason -- which is outside the scope of this question)?
>Or do I need to write some sort of postprocessor to accomplish this?

Sure, this could be done in a filter.

Let's assume that any paragraph with a line break is verse.

Then your first step will be to find these paragraphs:

    transformVerseParas :: Block -> Block
    transformVerseParas (Para xs)
      | LineBreak `elem` xs = Para (addLineSpans xs)
      | otherwise = Para xs
    transformVerseParas x = x

Now we just need to write addLineSpans:

    addLineSpans :: [Inline] -> [Inline]
    addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
      where encloseInSpan ils = [html "<span class=\"line\">"] ++
                                  ils ++ [html "</span>"]
            html = RawInline (Format "html")

(Completely untested, but I hope this gives you enough to get
something working.)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found] ` <fdf902a7-35c5-4757-8be3-b3bfb63639d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2015-03-27  4:14   ` John MacFarlane
@ 2015-03-27 10:12   ` BP Jonsson
  2015-03-27 19:29   ` Case Duckworth
  2 siblings, 0 replies; 8+ messages in thread
From: BP Jonsson @ 2015-03-27 10:12 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

I have written a filter in Perl which does what you want, 
instructions included:

<https://gist.github.com/2a5639a0005c0124a2d4>

The important bit starts at line 140.  I guess you could rewrite 
that in any language.

https://gist.github.com/2a5639a0005c0124a2d4

Not *quite* as you wished, because
you cannot put classes on `<p>` elements with Pandoc.
Use a selector `div.stanza p` to style stanzas with CSS!

XXX:
Multi-line stanzas should be line-blocks
but single-line stanzas must be 'normal' paras.
because Pandoc doesn't recognise single-line line-blocks
(arguably a bug in Pandoc!


Example input:

````markdown
<div class=verse>

| Hrörnar þöll
| sú er stendr þorpi á,
| hlýrat henni börkr né barr;
| svá er maðr sá
| er manngi ann,
| hvat skal hann lengi lífa ?

</div>
````

HTML output:

````html
<div class="verse">
<div class="stanza">
<p>
<span class="line">Hrörnar þöll</span>
<span class="line">sú er stendr þorpi á,</span>
<span class="line">hlýrat henni börkr né barr;</span>
<span class="line">svá er maðr sá</span>
<span class="line">er manngi ann,</span>
<span class="line">hvat skal hann lengi lífa ?</span>
</p>
</div>
</div>
````

/bpj

Den 2015-03-26 05:40, Case Duckworth skrev:
> Hi all,
>
> I've been working on my MFA thesis with pandoc. In it, I have a good amount
> of verse/poetry typesetting (the source is viewable here
> <http://github.com/duckwork/autocento>: pandoc source in src/ folder;
> generated html and stylesheet in /). In the markdown source, I'm
> delineating line breaks with "\" at the ends of lines. In HTML, these are
> rendered with the <br /> tag.
>
> Here's my problem: when the lines of poetry get too long for the viewport
> (either through having an overly long line or a too-narrow viewport), I
> want each line of poetry to have a hanging indent, as explained by this site
> <http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>.
> I've tried doing this purely with CSS on each line, and I'd be open to this
> solution if yall know CSS better than me, but as of now I haven't been able
> to find one that works with <br /> broken lines.
>
> After I found out that Pandoc has the capability of filters, I looked into
> writing one for my verse pieces. Upon further research, I'm not sure this
> is even possible, given that Paragraphs are Blocks and LineBreaks are
> Inline elements in Pandoc. What I'd like to do is typeset text like this in
> the output HTML:
>
> <section class="verse">
>      <p class="stanza">
>          <span class="line">Line of poetry goes here</span>
>          <span class="line">Second line here</span>
>          <span class="line">And so on, throughout the poem,</span>
>      </p>
>      <p class="stanza">
>          <span class="line">even over stanza breaks.</span>
>      </p>
> </section>
>
>
>
> Is there a way to do this with a Pandoc filter, in Haskell or Python or
> whatever? Is there a way to do this with a custom writer of some sort
> (though that has problems of its own, for example crashing on non-ASCII
> characters for some reason -- which is outside the scope of this question)?
> Or do I need to write some sort of postprocessor to accomplish this?
>
> Thanks in advance for your help. Let me know if I can clarify anything.
>
> Best,
> Case Duckworth
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/55152CF2.3000702%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found]     ` <20150327041452.GD35873-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
@ 2015-03-27 18:06       ` Case Duckworth
       [not found]         ` <e18bf636-1ed5-402b-aebf-93601e55e6ea-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Case Duckworth @ 2015-03-27 18:06 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 4150 bytes --]

This looks great, thanks! I have one more question, though:

Where can I find the `splitWhen` function? Please forgive me, I'm quite the 
Haskell newbie!

On Thursday, March 26, 2015 at 9:15:08 PM UTC-7, John MacFarlane wrote:
>
> +++ Case Duckworth [Mar 25 15 21:40 ]: 
> >Hi all, 
> > 
> >I've been working on my MFA thesis with pandoc. In it, I have a good 
> amount 
> >of verse/poetry typesetting (the source is viewable here 
> ><http://github.com/duckwork/autocento>: pandoc source in src/ folder; 
> >generated html and stylesheet in /). In the markdown source, I'm 
> >delineating line breaks with "\" at the ends of lines. In HTML, these are 
> >rendered with the <br /> tag. 
>
> Try using line blocks.  This will be easier and look nicer. 
> http://johnmacfarlane.net/pandoc/README.html#line-blocks 
>
> >Here's my problem: when the lines of poetry get too long for the viewport 
> >(either through having an overly long line or a too-narrow viewport), I 
> >want each line of poetry to have a hanging indent, as explained by this 
> site 
> ><
> http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>. 
>
> >I've tried doing this purely with CSS on each line, and I'd be open to 
> this 
> >solution if yall know CSS better than me, but as of now I haven't been 
> able 
> >to find one that works with <br /> broken lines. 
>
> Instead of <br /> broken lines, you could put each line in its own <p>, 
> and put the whole poem in a special <div>, then use CSS to reduce the 
> interparagraph spacing so it looks the way you want it to.  You could 
> then add the hanging indent easily with CSS. 
>
> >After I found out that Pandoc has the capability of filters, I looked 
> into 
> >writing one for my verse pieces. Upon further research, I'm not sure this 
> >is even possible, given that Paragraphs are Blocks and LineBreaks are 
> >Inline elements in Pandoc. What I'd like to do is typeset text like this 
> in 
> >the output HTML: 
> > 
> ><section class="verse"> 
> >    <p class="stanza"> 
> >        <span class="line">Line of poetry goes here</span> 
> >        <span class="line">Second line here</span> 
> >        <span class="line">And so on, throughout the poem,</span> 
> >    </p> 
> >    <p class="stanza"> 
> >        <span class="line">even over stanza breaks.</span> 
> >    </p> 
> ></section> 
> > 
> > 
> > 
> >Is there a way to do this with a Pandoc filter, in Haskell or Python or 
> >whatever? Is there a way to do this with a custom writer of some sort 
> >(though that has problems of its own, for example crashing on non-ASCII 
> >characters for some reason -- which is outside the scope of this 
> question)? 
> >Or do I need to write some sort of postprocessor to accomplish this? 
>
> Sure, this could be done in a filter. 
>
> Let's assume that any paragraph with a line break is verse. 
>
> Then your first step will be to find these paragraphs: 
>
>     transformVerseParas :: Block -> Block 
>     transformVerseParas (Para xs) 
>       | LineBreak `elem` xs = Para (addLineSpans xs) 
>       | otherwise = Para xs 
>     transformVerseParas x = x 
>
> Now we just need to write addLineSpans: 
>
>     addLineSpans :: [Inline] -> [Inline] 
>     addLineSpans = map encloseInSpan . splitWhen (== LineBreak) 
>       where encloseInSpan ils = [html "<span class=\"line\">"] ++ 
>                                   ils ++ [html "</span>"] 
>             html = RawInline (Format "html") 
>
> (Completely untested, but I hope this gives you enough to get 
> something working.) 
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e18bf636-1ed5-402b-aebf-93601e55e6ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 7084 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found]         ` <e18bf636-1ed5-402b-aebf-93601e55e6ea-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-03-27 18:18           ` John MacFarlane
  0 siblings, 0 replies; 8+ messages in thread
From: John MacFarlane @ 2015-03-27 18:18 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

+++ Case Duckworth [Mar 27 15 11:06 ]:
>This looks great, thanks! I have one more question, though:
>
>Where can I find the `splitWhen` function? Please forgive me, I'm quite the
>Haskell newbie!

Sorry, it's in the 'split' package on Hackage.
https://hackage.haskell.org/package/split-0.2.2

cabal install split

and then add

import Data.List.Split

to the top of your filter.

>
>On Thursday, March 26, 2015 at 9:15:08 PM UTC-7, John MacFarlane wrote:
>>
>> +++ Case Duckworth [Mar 25 15 21:40 ]:
>> >Hi all,
>> >
>> >I've been working on my MFA thesis with pandoc. In it, I have a good
>> amount
>> >of verse/poetry typesetting (the source is viewable here
>> ><http://github.com/duckwork/autocento>: pandoc source in src/ folder;
>> >generated html and stylesheet in /). In the markdown source, I'm
>> >delineating line breaks with "\" at the ends of lines. In HTML, these are
>> >rendered with the <br /> tag.
>>
>> Try using line blocks.  This will be easier and look nicer.
>> http://johnmacfarlane.net/pandoc/README.html#line-blocks
>>
>> >Here's my problem: when the lines of poetry get too long for the viewport
>> >(either through having an overly long line or a too-narrow viewport), I
>> >want each line of poetry to have a hanging indent, as explained by this
>> site
>> ><
>> http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>.
>>
>> >I've tried doing this purely with CSS on each line, and I'd be open to
>> this
>> >solution if yall know CSS better than me, but as of now I haven't been
>> able
>> >to find one that works with <br /> broken lines.
>>
>> Instead of <br /> broken lines, you could put each line in its own <p>,
>> and put the whole poem in a special <div>, then use CSS to reduce the
>> interparagraph spacing so it looks the way you want it to.  You could
>> then add the hanging indent easily with CSS.
>>
>> >After I found out that Pandoc has the capability of filters, I looked
>> into
>> >writing one for my verse pieces. Upon further research, I'm not sure this
>> >is even possible, given that Paragraphs are Blocks and LineBreaks are
>> >Inline elements in Pandoc. What I'd like to do is typeset text like this
>> in
>> >the output HTML:
>> >
>> ><section class="verse">
>> >    <p class="stanza">
>> >        <span class="line">Line of poetry goes here</span>
>> >        <span class="line">Second line here</span>
>> >        <span class="line">And so on, throughout the poem,</span>
>> >    </p>
>> >    <p class="stanza">
>> >        <span class="line">even over stanza breaks.</span>
>> >    </p>
>> ></section>
>> >
>> >
>> >
>> >Is there a way to do this with a Pandoc filter, in Haskell or Python or
>> >whatever? Is there a way to do this with a custom writer of some sort
>> >(though that has problems of its own, for example crashing on non-ASCII
>> >characters for some reason -- which is outside the scope of this
>> question)?
>> >Or do I need to write some sort of postprocessor to accomplish this?
>>
>> Sure, this could be done in a filter.
>>
>> Let's assume that any paragraph with a line break is verse.
>>
>> Then your first step will be to find these paragraphs:
>>
>>     transformVerseParas :: Block -> Block
>>     transformVerseParas (Para xs)
>>       | LineBreak `elem` xs = Para (addLineSpans xs)
>>       | otherwise = Para xs
>>     transformVerseParas x = x
>>
>> Now we just need to write addLineSpans:
>>
>>     addLineSpans :: [Inline] -> [Inline]
>>     addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
>>       where encloseInSpan ils = [html "<span class=\"line\">"] ++
>>                                   ils ++ [html "</span>"]
>>             html = RawInline (Format "html")
>>
>> (Completely untested, but I hope this gives you enough to get
>> something working.)
>>
>>
>
>-- 
>You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e18bf636-1ed5-402b-aebf-93601e55e6ea%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found] ` <fdf902a7-35c5-4757-8be3-b3bfb63639d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2015-03-27  4:14   ` John MacFarlane
  2015-03-27 10:12   ` BP Jonsson
@ 2015-03-27 19:29   ` Case Duckworth
       [not found]     ` <238a5361-21eb-4e86-bcf4-7d7ddfec1ac4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2 siblings, 1 reply; 8+ messages in thread
From: Case Duckworth @ 2015-03-27 19:29 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


[-- Attachment #1.1: Type: text/plain, Size: 4115 bytes --]

Okay, I've got that but (and here's where my real ignorance of Haskell 
comes to be known) I've got a type error:

verseLineParas.hs:15:20:
    Couldn't match type `[Inline]' with `Inline'
    Expected type: [Inline] -> Inline
      Actual type: [Inline] -> [Inline]
    In the first argument of `map', namely `encloseInSpan'
    In the first argument of `(.)', namely `map encloseInSpan'

Here's the contents of verseLineParas.hs: 

import Text.Pandoc.JSON
import Text.Pandoc
import Data.List.Split

main :: IO ()
main = toJSONFilter transformVerseParas

transformVerseParas :: Block -> Block
transformVerseParas (Para xs)
    | LineBreak `elem` xs = Para (addLineSpans xs)
    | otherwise = Para xs
transformVerseParas x = x

addLineSpans :: [Inline] -> [Inline]
addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
    where encloseInSpan ils = [html "<span class=\"line\">"] ++
                        ils ++ [html "</span>"]
          html = RawInline (Format "html")

Any assistance would be greatly appreciated. I think it has something to do 
with the (list comprehension?) on the <span>s in encloseInSpan. I tried 
looking through the Pandoc sections in Hackage, but like I said, my 
Haskell-foo is lowly. I've been reading "Learn you a Haskell for great 
good!" but I haven't made it to the type declaration chapter yet.


On Wednesday, March 25, 2015 at 9:40:45 PM UTC-7, Case Duckworth wrote:
>
> Hi all,
>
> I've been working on my MFA thesis with pandoc. In it, I have a good 
> amount of verse/poetry typesetting (the source is viewable here 
> <http://github.com/duckwork/autocento>: pandoc source in src/ folder; 
> generated html and stylesheet in /). In the markdown source, I'm 
> delineating line breaks with "\" at the ends of lines. In HTML, these are 
> rendered with the <br /> tag.
>
> Here's my problem: when the lines of poetry get too long for the viewport 
> (either through having an overly long line or a too-narrow viewport), I 
> want each line of poetry to have a hanging indent, as explained by this 
> site 
> <http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>. 
> I've tried doing this purely with CSS on each line, and I'd be open to this 
> solution if yall know CSS better than me, but as of now I haven't been able 
> to find one that works with <br /> broken lines.
>
> After I found out that Pandoc has the capability of filters, I looked into 
> writing one for my verse pieces. Upon further research, I'm not sure this 
> is even possible, given that Paragraphs are Blocks and LineBreaks are 
> Inline elements in Pandoc. What I'd like to do is typeset text like this in 
> the output HTML:
>
> <section class="verse">
>     <p class="stanza">
>         <span class="line">Line of poetry goes here</span>
>         <span class="line">Second line here</span>
>         <span class="line">And so on, throughout the poem,</span>
>     </p>
>     <p class="stanza">
>         <span class="line">even over stanza breaks.</span>
>     </p>
> </section>
>
>
>
> Is there a way to do this with a Pandoc filter, in Haskell or Python or 
> whatever? Is there a way to do this with a custom writer of some sort 
> (though that has problems of its own, for example crashing on non-ASCII 
> characters for some reason -- which is outside the scope of this question)? 
> Or do I need to write some sort of postprocessor to accomplish this?
>
> Thanks in advance for your help. Let me know if I can clarify anything.
>
> Best,
> Case Duckworth
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/238a5361-21eb-4e86-bcf4-7d7ddfec1ac4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 16957 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found]     ` <238a5361-21eb-4e86-bcf4-7d7ddfec1ac4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-03-27 22:01       ` John MacFarlane
       [not found]         ` <20150327220130.GC45731-0VdLhd/A9Pm0ooXD8Eul3Ui9IC4Y7XG3TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2015-03-27 22:01 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Well, that's what I get for giving you an untested code sample.

Here's what I *meant* to do for encloseInSpan:

    addLineSpans :: [Inline] -> [Inline]
    addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
        where encloseInSpan = Span ("",["line"],[])

which should type check and is much more elegant anyway. (But this
is still untested.)

Alternatively you could change map to concatMap in the original code.
But this way is nicer.

+++ Case Duckworth [Mar 27 15 12:29 ]:
>Okay, I've got that but (and here's where my real ignorance of Haskell
>comes to be known) I've got a type error:
>
>verseLineParas.hs:15:20:
>    Couldn't match type `[Inline]' with `Inline'
>    Expected type: [Inline] -> Inline
>      Actual type: [Inline] -> [Inline]
>    In the first argument of `map', namely `encloseInSpan'
>    In the first argument of `(.)', namely `map encloseInSpan'
>
>Here's the contents of verseLineParas.hs:
>
>import Text.Pandoc.JSON
>import Text.Pandoc
>import Data.List.Split
>
>main :: IO ()
>main = toJSONFilter transformVerseParas
>
>transformVerseParas :: Block -> Block
>transformVerseParas (Para xs)
>    | LineBreak `elem` xs = Para (addLineSpans xs)
>    | otherwise = Para xs
>transformVerseParas x = x
>
>addLineSpans :: [Inline] -> [Inline]
>addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
>    where encloseInSpan ils = [html "<span class=\"line\">"] ++
>                        ils ++ [html "</span>"]
>          html = RawInline (Format "html")
>
>Any assistance would be greatly appreciated. I think it has something to do
>with the (list comprehension?) on the <span>s in encloseInSpan. I tried
>looking through the Pandoc sections in Hackage, but like I said, my
>Haskell-foo is lowly. I've been reading "Learn you a Haskell for great
>good!" but I haven't made it to the type declaration chapter yet.
>
>
>On Wednesday, March 25, 2015 at 9:40:45 PM UTC-7, Case Duckworth wrote:
>>
>> Hi all,
>>
>> I've been working on my MFA thesis with pandoc. In it, I have a good
>> amount of verse/poetry typesetting (the source is viewable here
>> <http://github.com/duckwork/autocento>: pandoc source in src/ folder;
>> generated html and stylesheet in /). In the markdown source, I'm
>> delineating line breaks with "\" at the ends of lines. In HTML, these are
>> rendered with the <br /> tag.
>>
>> Here's my problem: when the lines of poetry get too long for the viewport
>> (either through having an overly long line or a too-narrow viewport), I
>> want each line of poetry to have a hanging indent, as explained by this
>> site
>> <http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-allen-ginsbergs-howl/comment-page-1/>.
>> I've tried doing this purely with CSS on each line, and I'd be open to this
>> solution if yall know CSS better than me, but as of now I haven't been able
>> to find one that works with <br /> broken lines.
>>
>> After I found out that Pandoc has the capability of filters, I looked into
>> writing one for my verse pieces. Upon further research, I'm not sure this
>> is even possible, given that Paragraphs are Blocks and LineBreaks are
>> Inline elements in Pandoc. What I'd like to do is typeset text like this in
>> the output HTML:
>>
>> <section class="verse">
>>     <p class="stanza">
>>         <span class="line">Line of poetry goes here</span>
>>         <span class="line">Second line here</span>
>>         <span class="line">And so on, throughout the poem,</span>
>>     </p>
>>     <p class="stanza">
>>         <span class="line">even over stanza breaks.</span>
>>     </p>
>> </section>
>>
>>
>>
>> Is there a way to do this with a Pandoc filter, in Haskell or Python or
>> whatever? Is there a way to do this with a custom writer of some sort
>> (though that has problems of its own, for example crashing on non-ASCII
>> characters for some reason -- which is outside the scope of this question)?
>> Or do I need to write some sort of postprocessor to accomplish this?
>>
>> Thanks in advance for your help. Let me know if I can clarify anything.
>>
>> Best,
>> Case Duckworth
>>
>>
>
>-- 
>You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/238a5361-21eb-4e86-bcf4-7d7ddfec1ac4%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Typesetting Verse: converting line breaks to "paragraph" breaks
       [not found]         ` <20150327220130.GC45731-0VdLhd/A9Pm0ooXD8Eul3Ui9IC4Y7XG3TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
@ 2015-03-27 22:39           ` Case Duckworth
  0 siblings, 0 replies; 8+ messages in thread
From: Case Duckworth @ 2015-03-27 22:39 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 6651 bytes --]

This works beautifully! Thank you so much. This is why I love open-source :)

(P.S. @Benct: I really appreciate your solution as well, and I'm sure it
works great -- but I don't know any Perl and I'd want to tweak that
functionality just a little bit for it to work with my thesis. But thank
you!)

Best,
Case Duckworth

On Fri, Mar 27, 2015 at 3:01 PM John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:

> Well, that's what I get for giving you an untested code sample.
>
> Here's what I *meant* to do for encloseInSpan:
>
>     addLineSpans :: [Inline] -> [Inline]
>     addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
>         where encloseInSpan = Span ("",["line"],[])
>
> which should type check and is much more elegant anyway. (But this
> is still untested.)
>
> Alternatively you could change map to concatMap in the original code.
> But this way is nicer.
>
> +++ Case Duckworth [Mar 27 15 12:29 ]:
> >Okay, I've got that but (and here's where my real ignorance of Haskell
> >comes to be known) I've got a type error:
> >
> >verseLineParas.hs:15:20:
> >    Couldn't match type `[Inline]' with `Inline'
> >    Expected type: [Inline] -> Inline
> >      Actual type: [Inline] -> [Inline]
> >    In the first argument of `map', namely `encloseInSpan'
> >    In the first argument of `(.)', namely `map encloseInSpan'
> >
> >Here's the contents of verseLineParas.hs:
> >
> >import Text.Pandoc.JSON
> >import Text.Pandoc
> >import Data.List.Split
> >
> >main :: IO ()
> >main = toJSONFilter transformVerseParas
> >
> >transformVerseParas :: Block -> Block
> >transformVerseParas (Para xs)
> >    | LineBreak `elem` xs = Para (addLineSpans xs)
> >    | otherwise = Para xs
> >transformVerseParas x = x
> >
> >addLineSpans :: [Inline] -> [Inline]
> >addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
> >    where encloseInSpan ils = [html "<span class=\"line\">"] ++
> >                        ils ++ [html "</span>"]
> >          html = RawInline (Format "html")
> >
> >Any assistance would be greatly appreciated. I think it has something to
> do
> >with the (list comprehension?) on the <span>s in encloseInSpan. I tried
> >looking through the Pandoc sections in Hackage, but like I said, my
> >Haskell-foo is lowly. I've been reading "Learn you a Haskell for great
> >good!" but I haven't made it to the type declaration chapter yet.
> >
> >
> >On Wednesday, March 25, 2015 at 9:40:45 PM UTC-7, Case Duckworth wrote:
> >>
> >> Hi all,
> >>
> >> I've been working on my MFA thesis with pandoc. In it, I have a good
> >> amount of verse/poetry typesetting (the source is viewable here
> >> <http://github.com/duckwork/autocento>: pandoc source in src/ folder;
> >> generated html and stylesheet in /). In the markdown source, I'm
> >> delineating line breaks with "\" at the ends of lines. In HTML, these
> are
> >> rendered with the <br /> tag.
> >>
> >> Here's my problem: when the lines of poetry get too long for the
> viewport
> >> (either through having an overly long line or a too-narrow viewport), I
> >> want each line of poetry to have a hanging indent, as explained by this
> >> site
> >> <http://blogs.publishersweekly.com/blogs/PWxyz/2010/10/06/this-is-not-
> allen-ginsbergs-howl/comment-page-1/>.
> >> I've tried doing this purely with CSS on each line, and I'd be open to
> this
> >> solution if yall know CSS better than me, but as of now I haven't been
> able
> >> to find one that works with <br /> broken lines.
> >>
> >> After I found out that Pandoc has the capability of filters, I looked
> into
> >> writing one for my verse pieces. Upon further research, I'm not sure
> this
> >> is even possible, given that Paragraphs are Blocks and LineBreaks are
> >> Inline elements in Pandoc. What I'd like to do is typeset text like
> this in
> >> the output HTML:
> >>
> >> <section class="verse">
> >>     <p class="stanza">
> >>         <span class="line">Line of poetry goes here</span>
> >>         <span class="line">Second line here</span>
> >>         <span class="line">And so on, throughout the poem,</span>
> >>     </p>
> >>     <p class="stanza">
> >>         <span class="line">even over stanza breaks.</span>
> >>     </p>
> >> </section>
> >>
> >>
> >>
> >> Is there a way to do this with a Pandoc filter, in Haskell or Python or
> >> whatever? Is there a way to do this with a custom writer of some sort
> >> (though that has problems of its own, for example crashing on non-ASCII
> >> characters for some reason -- which is outside the scope of this
> question)?
> >> Or do I need to write some sort of postprocessor to accomplish this?
> >>
> >> Thanks in advance for your help. Let me know if I can clarify anything.
> >>
> >> Best,
> >> Case Duckworth
> >>
> >>
> >
> >--
> >You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> >To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >To view this discussion on the web visit https://groups.google.com/d/
> msgid/pandoc-discuss/238a5361-21eb-4e86-bcf4-7d7ddfec1ac4%
> 40googlegroups.com.
> >For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "pandoc-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/pandoc-discuss/_JnTJnsSK3k/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pandoc-discuss/20150327220130.GC45731%40dhcp-
> 128-32-252-59.lips.berkeley.edu.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAKH8a9mhyGxo-86fo2%2BJ26ZPb%3DMeyPKaE_uTeHyiCAkQsxRZpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 9672 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-27 22:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26  4:40 Typesetting Verse: converting line breaks to "paragraph" breaks Case Duckworth
     [not found] ` <fdf902a7-35c5-4757-8be3-b3bfb63639d2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-03-27  4:14   ` John MacFarlane
     [not found]     ` <20150327041452.GD35873-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
2015-03-27 18:06       ` Case Duckworth
     [not found]         ` <e18bf636-1ed5-402b-aebf-93601e55e6ea-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-03-27 18:18           ` John MacFarlane
2015-03-27 10:12   ` BP Jonsson
2015-03-27 19:29   ` Case Duckworth
     [not found]     ` <238a5361-21eb-4e86-bcf4-7d7ddfec1ac4-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-03-27 22:01       ` John MacFarlane
     [not found]         ` <20150327220130.GC45731-0VdLhd/A9Pm0ooXD8Eul3Ui9IC4Y7XG3TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
2015-03-27 22:39           ` Case Duckworth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).