From 9be9bccfcfc2c46459b3da963bc59a37f841fe8a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 15 Jul 2010 19:01:00 -0700 Subject: Added --section-divs option. + Header identifiers now get attached to the headers, unless --section-divs is specified, in which case they are added to enclosing divs. By default, the divs are not added. + Resolves Issue #230, #239. --- README | 11 + man/man1/pandoc.1.md | 4 + src/Text/Pandoc/Shared.hs | 2 + src/Text/Pandoc/Writers/HTML.hs | 19 +- src/pandoc.hs | 9 + tests/s5.fragment.html | 34 +- tests/s5.inserts.html | 34 +- tests/writer.html | 1984 +++++++++++++++++++-------------------- 8 files changed, 1027 insertions(+), 1070 deletions(-) diff --git a/README b/README index 6c3a61ca5..72d2c01b5 100644 --- a/README +++ b/README @@ -400,6 +400,11 @@ For further documentation, see the `pandoc(1)` man page. : causes sections to be numbered in LaTeX, ConTeXt, or HTML output. By default, sections are not numbered. +`--section-divs` +: causes sections to be wrapped in `
` tags. In this case, + [section identifiers](#header-identifiers-in-html) + are attached to the enclosing `
` rather than the header itself. + `--no-wrap` : disables text-wrapping in output. By default, text is wrapped appropriately for the output format. @@ -1170,6 +1175,12 @@ another. A link to this section, for example, might look like this: Note, however, that this method of providing links to sections works only in HTML. +If the `--section-divs` option is specified, then each section will +be wrapped in a `div`, and the identifier will be attached to the +enclosing `
` tag rather than the header itself. This allows entire +sections to be manipulated using javascript or treated differently in +CSS. + Blank lines before headers and blockquotes ------------------------------------------ diff --git a/man/man1/pandoc.1.md b/man/man1/pandoc.1.md index e1cf67847..d8cddb1d5 100644 --- a/man/man1/pandoc.1.md +++ b/man/man1/pandoc.1.md @@ -151,6 +151,10 @@ should pipe input and output through `iconv`: : Number section headings in LaTeX, ConTeXt, or HTML output. (Default is not to number them.) +\--section-divs +: Wrap sections in `
` tags, and attach identifiers to the + enclosing `
` rather than the header itself. + \--no-wrap : Disable text wrapping in output. (Default is to wrap text.) diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index b8eb14177..633708046 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -487,6 +487,7 @@ data WriterOptions = WriterOptions , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc) , writerNumberSections :: Bool -- ^ Number sections in LaTeX + , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst , writerWrapText :: Bool -- ^ Wrap text to line length @@ -512,6 +513,7 @@ defaultWriterOptions = , writerHTMLMathMethod = PlainMath , writerIgnoreNotes = False , writerNumberSections = False + , writerSectionDivs = True , writerStrictMarkdown = False , writerReferenceLinks = False , writerWrapText = True diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 20022e182..e9006a39b 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -208,15 +208,16 @@ elementToHtml opts (Sec level num id' title' elements) = do innerContents <- mapM (elementToHtml opts) elements modify $ \st -> st{stSecNum = num} -- update section number header' <- blockToHtml opts (Header level title') - let stuff = header' : innerContents - return $ case writerSlideVariant opts of - SlidySlides -> toHtmlFromList stuff - S5Slides -> toHtmlFromList stuff - -- S5 gets confused by the extra divs around sections - _ | (writerStrictMarkdown opts && - not (writerTableOfContents opts)) -> - toHtmlFromList stuff - _ -> thediv ! [prefixedId opts id'] << stuff + let slides = writerSlideVariant opts `elem` [SlidySlides, S5Slides] + let header'' = header' ! [prefixedId opts id' | + not (writerStrictMarkdown opts || + writerSectionDivs opts || slides)] + let stuff = header'' : innerContents + return $ if slides -- S5 gets confused by the extra divs around sections + then toHtmlFromList stuff + else if writerSectionDivs opts + then thediv ! [prefixedId opts id'] << stuff + else toHtmlFromList stuff -- | Convert list of Note blocks to a footnote
. -- Assumes notes are sorted. diff --git a/src/pandoc.hs b/src/pandoc.hs index 9546d6026..cd4d65aa5 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -142,6 +142,7 @@ data Opt = Opt , optVariables :: [(String,String)] -- ^ Template variables to set , optOutputFile :: String -- ^ Name of output file , optNumberSections :: Bool -- ^ Number sections in LaTeX + , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML , optIncremental :: Bool -- ^ Use incremental lists in Slidy/S5 , optXeTeX :: Bool -- ^ Format latex for xetex , optSmart :: Bool -- ^ Use smart typography @@ -182,6 +183,7 @@ defaultOpts = Opt , optVariables = [] , optOutputFile = "-" -- "-" means stdout , optNumberSections = False + , optSectionDivs = False , optIncremental = False , optXeTeX = False , optSmart = False @@ -325,6 +327,11 @@ options = (\opt -> return opt { optNumberSections = True })) "" -- "Number sections in LaTeX" + , Option "" ["section-divs"] + (NoArg + (\opt -> return opt { optSectionDivs = True })) + "" -- "Put sections in div tags in HTML" + , Option "" ["no-wrap"] (NoArg (\opt -> return opt { optWrapText = False })) @@ -643,6 +650,7 @@ main = do , optTemplate = template , optOutputFile = outputFile , optNumberSections = numberSections + , optSectionDivs = sectionDivs , optIncremental = incremental , optXeTeX = xetex , optSmart = smart @@ -782,6 +790,7 @@ main = do writerXeTeX = xetex, writerIgnoreNotes = False, writerNumberSections = numberSections, + writerSectionDivs = sectionDivs, writerStrictMarkdown = strict, writerReferenceLinks = referenceLinks, writerWrapText = wrap, diff --git a/tests/s5.fragment.html b/tests/s5.fragment.html index 32346a331..9845e1409 100644 --- a/tests/s5.fragment.html +++ b/tests/s5.fragment.html @@ -1,21 +1,17 @@ -

First slide

    First slide
    • first bullet
    • first bullet
    • second bullet

Math

  • $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
second bullet

Math

  • $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
diff --git a/tests/s5.inserts.html b/tests/s5.inserts.html index 69ab6f5e1..f909850d8 100644 --- a/tests/s5.inserts.html +++ b/tests/s5.inserts.html @@ -13,26 +13,22 @@ STUFF INSERTED

My S5 Document

-

First slide

    First slide
    • first bullet
    • first bullet
    • second bullet

Math

  • $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
second bullet

Math

  • $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
STUFF INSERTED diff --git a/tests/writer.html b/tests/writer.html index adf0bb9ca..72c93ee71 100644 --- a/tests/writer.html +++ b/tests/writer.html @@ -13,119 +13,96 @@

This is a set of tests for pandoc. Most of them are adapted from John Gruber’s markdown test suite.


Headers

Level 1

Level 2 with emphasis

Level 3

with no blank line

Level 2

with no blank line


Paragraphs

Here’s a regular paragraph.

In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item.

Here’s one with a bullet. * criminey.

Headers

Level 3 with emphasis

Level 4

Level 5

Level 1

Level 2 with emphasis

Level 3

with no blank line

Level 2

with no blank line


Paragraphs

Here’s a regular paragraph.

In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item.

Here’s one with a bullet. * criminey.

There should be a hard line break
here.


Block Quotes

E-mail style:

This is a block quote. It is pretty short.

Code in a block quote:

sub status {
+    print "working";
+}
+

There should be a hard line break
here.


Block Quotes

A list:

  1. item one
  2. item two

E-mail style:

Nested block quotes:

This is a block quote. It is pretty short.

nested

Code in a block quote:

sub status {
-    print "working";
-}
-

A list:

  1. item one
  2. item two

Nested block quotes:

nested

nested

nested

This should not be a block quote: 2 > 1.

And a following paragraph.


Code Blocks

Code:

---- (should be four hyphens)
+  >

This should not be a block quote: 2 > 1.

And a following paragraph.


Code Blocks

Code:

---- (should be four hyphens)
 
 sub status {
     print "working";
@@ -133,540 +110,524 @@ sub status {
 
 this code block is indented by one tab
 

And:

    this code block is indented by two tabs
+  >

And:

    this code block is indented by two tabs
 
 These should not be escaped:  \$ \\ \> \[ \{
 

Lists

Unordered

Asterisks tight:

  • asterisk 1
  • asterisk 2
  • asterisk 3

Lists

Unordered

Asterisks tight:

  • asterisk 1
  • asterisk 2
  • asterisk 3

Asterisks loose:

  • asterisk 1

  • asterisk 2

  • asterisk 3

Pluses tight:

  • Plus 1
  • Plus 2
  • Plus 3

Pluses loose:

  • Plus 1

  • Plus 2

  • Plus 3

Minuses tight:

  • Minus 1
  • Minus 2
  • Minus 3

Minuses loose:

  • Minus 1

  • Minus 2

  • Minus 3

Ordered

Tight:

  1. First
  2. Second
  3. Third

and:

  1. One
  2. Two
  3. Three

Loose using tabs:

  1. First

  2. Second

  3. Third

and using spaces:

  1. One

  2. Two

  3. Three

Multiple paragraphs:

  1. Item 1, graf one.

    Asterisks loose:

      Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.

    • Item 2.

    • Item 3.

Nested

  • Tab
    • asterisk 1

    • asterisk 2

    • asterisk 3

      Tab
      • Tab

    Pluses tight:

    • Plus 1
    • Plus 2
    • Plus 3

    Pluses loose:

      Here’s another:

      1. First
      2. Second:
        • Plus 1

        • Fee
        • Plus 2

        • Fie
        • Plus 3

        • Foe

        Minuses tight:

      3. Third

      Same thing but with paragraphs:

      1. First

      2. Second:

        • Minus 1
        • Fee
        • Minus 2
        • Fie
        • Minus 3
        • Foe

        Minuses loose:

      3. Third

      Tabs and spaces

      • this is a list item indented with tabs

      • this is a list item indented with spaces

        • Minus 1

        • Minus 2

          this is an example list item indented with tabs

        • Minus 3

          this is an example list item indented with spaces

    Ordered

    Tight:

    1. First
    2. Second
    3. Third

    and:

    1. One
    2. Two
    3. Three

    Loose using tabs:

    1. First

    2. Second

    3. Third

    and using spaces:

    1. One

    2. Two

    3. Three

    Multiple paragraphs:

    1. Item 1, graf one.

      Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.

    2. Item 2.

    3. Item 3.

    Nested

    • Tab
      • Tab
        • Tab

    Here’s another:

    1. First
    2. Second:
      • Fee
      • Fie
      • Foe
    3. Third

    Fancy list markers

    1. begins with 2
    2. and now 3

      Same thing but with paragraphs:

      1. First

      2. Second:

        • Fee
        • Fie
        • Foe
      3. Third

    Tabs and spaces

    • this is a list item indented with tabs

    • this is a list item indented with spaces

      • this is an example list item indented with tabs

      • this is an example list item indented with spaces

    Fancy list markers

      with a continuation

      1. begins with 2
      2. sublist with roman numerals, starting with 4
      3. and now 3

        with a continuation

          more items
          1. sublist with roman numerals, starting with 4
          2. a subsublist
          3. more items
            1. a subsublist
            2. a subsublist
          4. a subsublist

        Nesting:

          Nesting:

          1. Upper Alpha
            1. Upper Alpha
                Upper Roman.
                1. Upper Roman.
                    Decimal start with 6
                    1. Decimal start with 6
                      1. Lower alpha with paren
                    2. Lower alpha with paren

                Autonumbering:

                  Autonumbering:

                  1. Autonumber.
                  2. More.
                    1. Autonumber.
                    2. More.
                      1. Nested.
                    3. Nested.

                    Should not be a list item:

                    M.A. 2007

                    B. Williams


        Definition Lists

        Tight using spaces:

        Should not be a list item:

        M.A. 2007

        B. Williams


        Definition Lists

        Tight using spaces:

        apple
        red fruit
        apple
        red fruit
        orange
        orange fruit
        banana
        yellow fruit

        Tight using tabs:

        orange
        orange fruit
        apple
        red fruit
        orange
        orange fruit
        banana
        yellow fruit

        Loose:

        banana
        yellow fruit

        Tight using tabs:

        apple
        red fruit
        apple

        red fruit

        orange

        orange fruit

        banana

        yellow fruit

        Multiple blocks with italics:

        orange
        orange fruit
        apple

        red fruit

        contains seeds, crisp, pleasant to taste

        orange

        orange fruit

        { orange code block }
        -

        orange block quote

        Multiple definitions, tight:

        banana
        yellow fruit

        Loose:

        apple

        red fruit

        apple
        red fruit
        computer
        orange
        orange fruit
        bank
        orange

        Multiple definitions, loose:

        orange fruit

        apple

        red fruit

        computer

        orange

        orange fruit

        bank

        Blank line after term, indented marker, alternate markers:

        banana

        yellow fruit

        Multiple blocks with italics:

        apple

        red fruit

        contains seeds, crisp, pleasant to taste

        apple

        red fruit

        computer

        orange
        orange

        orange fruit

        { orange code block }
        +

        orange fruit

        1. sublist
        2. sublist

        HTML Blocks

        orange block quote

        Multiple definitions, tight:

        apple
        red fruit
        computer
        orange
        orange fruit
        bank

        Multiple definitions, loose:

        apple

        red fruit

        computer

        orange

        orange fruit

        bank

        Blank line after term, indented marker, alternate markers:

        apple

        red fruit

        computer

        orange

        Simple block on one line:

        foo
        + >orange fruit

        1. sublist
        2. sublist

        HTML Blocks

        Simple block on one line:

        foo

        And nested without indentation:

        +>And nested without indentation:

        foo
        bar

        Interpreted markdown in a table:

        +>Interpreted markdown in a table:

        +>emphasized +>strong
        This is emphasized And this is strong

        Here’s a simple block:

        +>Here’s a simple block:

        foo

        This should be a code block, though:

        <div>
        +>This should be a code block, though:

        <div>
             foo
         </div>
         

        As should this:

        <div>foo</div>
        +  >

        As should this:

        <div>foo</div>
         

        Now, nested:

        + >

        Now, nested:

        foo

        This should just be an HTML comment:

        +>This should just be an HTML comment:

        Multiline:

        @@ -675,25 +636,25 @@ Blah This is another comment. -->

        Code block:

        <!-- Comment -->
        +>Code block:

        <!-- Comment -->
         

        Just plain comment, with trailing spaces on the line:

        + >

        Just plain comment, with trailing spaces on the line:

        Code:

        <hr />
        +>Code:

        <hr />
         

        Hr’s:


        + >

        Hr’s:



        @@ -711,477 +672,454 @@ Blah

        Inline Markup

        Inline Markup

        This is emphasized, and so is this.

        This is strong, and so is this.

        An emphasized link.

        This is strong and em.

        So is this word.

        This is strong and em.

        So is this word.

        This is code: >, $, \, \$, <html>.

        This is emphasized, and so is this.

        This is strong, and so is this.

        An emphasized link.

        This is strong and em.

        So is this word.

        strikeout.

        Superscripts: abcd ahello ahello there.

        Subscripts: H2O, H23O, Hmany of themO.

        These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.


        Smart quotes, ellipses, dashes

        “Hello,” said the spider. “‘Shelob’ is my name.”

        ‘A’, ‘B’, and ‘C’ are letters.

        ‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’

        ‘He said, “I want to go.”’ Were you alive in the 70’s?

        Here is some quoted ‘code’ and a “quoted link”.

        Some dashes: one—two — three—four — five.

        Dashes between numbers: 5–7, 255–66, 1987–1999.

        Ellipses…and…and….


        LaTeX

        • 2 + 2 = 4
        • This is strong and em.

          So is x ∈ y

        • α ∧ ω
        • 223
        • this word.

          This is code: >, p-Tree

        • Here’s some display math:
          $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
        • Here’s one that has a line break in it: α + ω × x2.

        These shouldn’t be math:

        • To get the famous equation, write $e = mc^2$.
        • $22,000 is a lot of money. So is $34,000. (It worked if “lot” is emphasized.)
        • Shoes ($20) and socks ($5).
        • Escaped $, \, \$, <html>.

          This is strikeout.

          Superscripts: abcd ahello ahello there.

          Subscripts: H2O, H23O, Hmany of themO.

          These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.


        Smart quotes, ellipses, dashes

        “Hello,” said the spider. “‘Shelob’ is my name.”

        ‘A’, ‘B’, and ‘C’ are letters.

        ‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’

        ‘He said, “I want to go.”’ Were you alive in the 70’s?

        Here is some quoted ‘code’ and a “quoted link”.

        Some dashes: one—two — three—four — five.

        Dashes between numbers: 5–7, 255–66, 1987–1999.

        Ellipses…and…and….


        LaTeX

          : $73 this should be emphasized 23$.

        Here’s a LaTeX table:


        Special Characters

        Here is some unicode:

        • I hat: Î
        • 2 + 2 = 4
        • x ∈ y
        • α ∧ ω
        • 223
        • p-Tree
        • Here’s some display math:
          $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
        • Here’s one that has a line break in it: α + ω × x2.

        These shouldn’t be math:

          o umlaut: ö
        • To get the famous equation, write $e = mc^2$.
        • $22,000 is a lot of money. So is $34,000. (It worked if “lot” is emphasized.)
        • Shoes ($20) and socks ($5).
        • Escaped $: $73 this should be emphasized 23$.

        Here’s a LaTeX table:


        Special Characters

        Here is some unicode:

          section: §
        • I hat: Î
        • o umlaut: ö
        • section: §
        • set membership: ∈
        • copyright: ©

        AT&T has an ampersand in their name.

        AT&T is another way to write it.

        This & that.

        4 < 5.

        6 > 5.

        Backslash: \

        Backtick: `

        Asterisk: *

        Underscore: _

        Left brace: {

        Right brace: }

        Left bracket: [

        Right bracket: ]

        Left paren: (

        Right paren: )

        Greater-than: >

        Hash: #

        Period: .

        Bang: !

        Plus: +

        Minus: -