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 , .
This commit is contained in:
John MacFarlane 2010-07-15 19:01:00 -07:00
parent 57a91f3b6a
commit 9be9bccfcf
8 changed files with 1039 additions and 1082 deletions

11
README
View file

@ -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 `<div>` tags. In this case,
[section identifiers](#header-identifiers-in-html)
are attached to the enclosing `<div>` 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 `<div>` 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
------------------------------------------

View file

@ -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 `<div>` tags, and attach identifiers to the
enclosing `<div>` rather than the header itself.
\--no-wrap
: Disable text wrapping in output. (Default is to wrap text.)

View file

@ -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

View file

@ -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 <div>.
-- Assumes notes are sorted.

View file

@ -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,

View file

@ -1,5 +1,4 @@
<div id="first-slide"
><h1
<h1 id="first-slide"
>First slide</h1
><ul
><li
@ -7,9 +6,7 @@
><li
>second bullet</li
></ul
></div
><div id="math"
><h1
><h1 id="math"
>Math</h1
><ul
><li
@ -17,5 +14,4 @@
>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
></li
></ul
></div
>

View file

@ -13,8 +13,7 @@
<body>
STUFF INSERTED
<h1 class="title">My S5 Document</h1>
<div id="first-slide"
><h1
<h1 id="first-slide"
>First slide</h1
><ul
><li
@ -22,9 +21,7 @@ STUFF INSERTED
><li
>second bullet</li
></ul
></div
><div id="math"
><h1
><h1 id="math"
>Math</h1
><ul
><li
@ -32,7 +29,6 @@ STUFF INSERTED
>$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span
></li
></ul
></div
>
STUFF INSERTED
</body>

View file

@ -13,55 +13,36 @@
<p
>This is a set of tests for pandoc. Most of them are adapted from John Grubers markdown test suite.</p
><hr
/><div id="headers"
><h1
/><h1 id="headers"
>Headers</h1
><div id="level-2-with-an-embedded-link"
><h2
><h2 id="level-2-with-an-embedded-link"
>Level 2 with an <a href="/url"
>embedded link</a
></h2
><div id="level-3-with-emphasis"
><h3
><h3 id="level-3-with-emphasis"
>Level 3 with <em
>emphasis</em
></h3
><div id="level-4"
><h4
><h4 id="level-4"
>Level 4</h4
><div id="level-5"
><h5
><h5 id="level-5"
>Level 5</h5
></div
></div
></div
></div
></div
><div id="level-1"
><h1
><h1 id="level-1"
>Level 1</h1
><div id="level-2-with-emphasis"
><h2
><h2 id="level-2-with-emphasis"
>Level 2 with <em
>emphasis</em
></h2
><div id="level-3"
><h3
><h3 id="level-3"
>Level 3</h3
><p
>with no blank line</p
></div
></div
><div id="level-2"
><h2
><h2 id="level-2"
>Level 2</h2
><p
>with no blank line</p
><hr
/></div
></div
><div id="paragraphs"
><h1
/><h1 id="paragraphs"
>Paragraphs</h1
><p
>Heres a regular paragraph.</p
@ -73,9 +54,7 @@
>There should be a hard line break<br
/>here.</p
><hr
/></div
><div id="block-quotes"
><h1
/><h1 id="block-quotes"
>Block Quotes</h1
><p
>E-mail style:</p
@ -117,9 +96,7 @@
><p
>And a following paragraph.</p
><hr
/></div
><div id="code-blocks"
><h1
/><h1 id="code-blocks"
>Code Blocks</h1
><p
>Code:</p
@ -144,12 +121,9 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</code
></pre
><hr
/></div
><div id="lists"
><h1
/><h1 id="lists"
>Lists</h1
><div id="unordered"
><h2
><h2 id="unordered"
>Unordered</h2
><p
>Asterisks tight:</p
@ -229,9 +203,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
>Minus 3</p
></li
></ul
></div
><div id="ordered"
><h2
><h2 id="ordered"
>Ordered</h2
><p
>Tight:</p
@ -303,9 +275,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
>Item 3.</p
></li
></ol
></div
><div id="nested"
><h2
><h2 id="nested"
>Nested</h2
><ul
><li
@ -361,9 +331,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
>Third</p
></li
></ol
></div
><div id="tabs-and-spaces"
><h2
><h2 id="tabs-and-spaces"
>Tabs and spaces</h2
><ul
><li
@ -385,9 +353,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ul
></li
></ul
></div
><div id="fancy-list-markers"
><h2
><h2 id="fancy-list-markers"
>Fancy list markers</h2
><ol start="2" style="list-style-type: decimal;"
><li
@ -448,10 +414,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
><p
>B. Williams</p
><hr
/></div
></div
><div id="definition-lists"
><h1
/><h1 id="definition-lists"
>Definition Lists</h1
><p
>Tight using spaces:</p
@ -604,9 +567,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
></ol
></dd
></dl
></div
><div id="html-blocks"
><h1
><h1 id="html-blocks"
>HTML Blocks</h1
><p
>Simple block on one line:</p
@ -711,9 +672,7 @@ Blah
<hr class="foo" id="bar">
<hr
/></div
><div id="inline-markup"
><h1
/><h1 id="inline-markup"
>Inline Markup</h1
><p
>This is <em
@ -796,9 +755,7 @@ Blah
><p
>These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.</p
><hr
/></div
><div id="smart-quotes-ellipses-dashes"
><h1
/><h1 id="smart-quotes-ellipses-dashes"
>Smart quotes, ellipses, dashes</h1
><p
>“Hello,” said the spider. “Shelob is my name.”</p
@ -821,9 +778,7 @@ Blah
><p
>Ellipses…and…and….</p
><hr
/></div
><div id="latex"
><h1
/><h1 id="latex"
>LaTeX</h1
><ul
><li
@ -894,9 +849,7 @@ Blah
><p
></p
><hr
/></div
><div id="special-characters"
><h1
/><h1 id="special-characters"
>Special Characters</h1
><p
>Here is some unicode:</p
@ -955,12 +908,9 @@ Blah
><p
>Minus: -</p
><hr
/></div
><div id="links"
><h1
/><h1 id="links"
>Links</h1
><div id="explicit"
><h2
><h2 id="explicit"
>Explicit</h2
><p
>Just a <a href="/url/"
@ -1005,9 +955,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>')
><a href=""
>Empty</a
>.</p
></div
><div id="reference"
><h2
><h2 id="reference"
>Reference</h2
><p
>Foo <a href="/url/"
@ -1056,9 +1004,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>')
>Foo <a href="/url/" title="Title with &quot;quote&quot; inside"
>biz</a
>.</p
></div
><div id="with-ampersands"
><h2
><h2 id="with-ampersands"
>With ampersands</h2
><p
>Heres a <a href="http://example.com/?foo=1&amp;bar=2"
@ -1076,9 +1022,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'Email link'+'<\/'+'a'+'>')
>Heres an <a href="/script?foo=1&amp;bar=2"
>inline link in pointy braces</a
>.</p
></div
><div id="autolinks"
><h2
><h2 id="autolinks"
>Autolinks</h2
><p
>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2"
@ -1127,10 +1071,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+
</code
></pre
><hr
/></div
></div
><div id="images"
><h1
/><h1 id="images"
>Images</h1
><p
>From “Voyage dans la Lune” by Georges Melies (1902):</p
@ -1143,9 +1084,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+
>Here is a movie <img src="movie.jpg" alt="movie"
/> icon.</p
><hr
/></div
><div id="footnotes"
><h1
/><h1 id="footnotes"
>Footnotes</h1
><p
>Here is a footnote reference,<sup
@ -1181,7 +1120,6 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+'<code>'+e+'</code>'+'<\/'+
></ol
><p
>This paragraph should not be part of the note, as it is not indented.</p
></div
><div class="footnotes"
><hr
/><ol