Shared.makeSections: better behavior in some corner cases.
When a div surrounds multiple sections at the same level, or a section of highre level followed by one of lower level, then we just leave it as a div and create a new div for the section. Closes #5846, closes #5761.
This commit is contained in:
parent
47566817c5
commit
a796b655cd
2 changed files with 177 additions and 3 deletions
|
@ -1,12 +1,13 @@
|
|||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE ViewPatterns #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{- |
|
||||
Module : Text.Pandoc.Shared
|
||||
Copyright : Copyright (C) 2006-2019 John MacFarlane
|
||||
|
@ -533,7 +534,10 @@ makeSections numbering mbBaseLevel bs =
|
|||
return $
|
||||
Div divattr (Header level' attr title' : sectionContents') : rest'
|
||||
go (Div (dident,dclasses,dkvs)
|
||||
(Header level (ident,classes,kvs) title':ys) : xs) = do
|
||||
(Header level (ident,classes,kvs) title':ys) : xs)
|
||||
| all (\case
|
||||
Header level' _ _ -> level' > level
|
||||
_ -> True) ys = do
|
||||
inner <- go (Header level (ident,classes,kvs) title':ys)
|
||||
let inner' =
|
||||
case inner of
|
||||
|
|
170
test/command/5846.md
Normal file
170
test/command/5846.md
Normal file
|
@ -0,0 +1,170 @@
|
|||
```
|
||||
% pandoc --section-divs
|
||||
::: {.mydiv}
|
||||
# header 1a
|
||||
|
||||
one
|
||||
|
||||
# header 1b
|
||||
|
||||
two
|
||||
:::
|
||||
^D
|
||||
<div class="mydiv">
|
||||
<section id="header-1a" class="level1">
|
||||
<h1>header 1a</h1>
|
||||
<p>one</p>
|
||||
</section>
|
||||
<section id="header-1b" class="level1">
|
||||
<h1>header 1b</h1>
|
||||
<p>two</p>
|
||||
</section>
|
||||
</div>
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc --section-divs
|
||||
::: mydiv
|
||||
# head 1
|
||||
## head 1.1
|
||||
# head 2
|
||||
:::
|
||||
|
||||
## head 2.1
|
||||
^D
|
||||
<div class="mydiv">
|
||||
<section id="head-1" class="level1">
|
||||
<h1>head 1</h1>
|
||||
<section id="head-1.1" class="level2">
|
||||
<h2>head 1.1</h2>
|
||||
</section>
|
||||
</section>
|
||||
<section id="head-2" class="level1">
|
||||
<h1>head 2</h1>
|
||||
</section>
|
||||
</div>
|
||||
<section id="head-2.1" class="level2">
|
||||
<h2>head 2.1</h2>
|
||||
</section>
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc --section-divs
|
||||
# One
|
||||
## One A
|
||||
::: fence
|
||||
## One B
|
||||
# Two
|
||||
:::
|
||||
^D
|
||||
<section id="one" class="level1">
|
||||
<h1>One</h1>
|
||||
<section id="one-a" class="level2">
|
||||
<h2>One A</h2>
|
||||
</section>
|
||||
<div class="fence">
|
||||
<section id="one-b" class="level2">
|
||||
<h2>One B</h2>
|
||||
</section>
|
||||
<section id="two" class="level1">
|
||||
<h1>Two</h1>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc --section-divs
|
||||
# Beginning
|
||||
|
||||
::: exterior
|
||||
|
||||
At first...
|
||||
|
||||
:::
|
||||
|
||||
In the beginning...
|
||||
|
||||
::: interior
|
||||
|
||||
# Middle
|
||||
|
||||
So it continued...
|
||||
|
||||
:::
|
||||
|
||||
# Ending
|
||||
|
||||
::: exterior
|
||||
|
||||
And finally...
|
||||
|
||||
:::
|
||||
^D
|
||||
<section id="beginning" class="level1">
|
||||
<h1>Beginning</h1>
|
||||
<div class="exterior">
|
||||
<p>At first…</p>
|
||||
</div>
|
||||
<p>In the beginning…</p>
|
||||
</section>
|
||||
<section id="middle" class="level1 interior">
|
||||
<h1>Middle</h1>
|
||||
<p>So it continued…</p>
|
||||
</section>
|
||||
<section id="ending" class="level1">
|
||||
<h1>Ending</h1>
|
||||
<div class="exterior">
|
||||
<p>And finally…</p>
|
||||
</div>
|
||||
</section>
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc --section-divs
|
||||
::: part
|
||||
# One
|
||||
# Two
|
||||
:::
|
||||
::: part
|
||||
# Three
|
||||
# Four
|
||||
# Five
|
||||
:::
|
||||
::: part
|
||||
# Six
|
||||
# Seven
|
||||
# Eight
|
||||
:::
|
||||
^D
|
||||
<div class="part">
|
||||
<section id="one" class="level1">
|
||||
<h1>One</h1>
|
||||
</section>
|
||||
<section id="two" class="level1">
|
||||
<h1>Two</h1>
|
||||
</section>
|
||||
</div>
|
||||
<div class="part">
|
||||
<section id="three" class="level1">
|
||||
<h1>Three</h1>
|
||||
</section>
|
||||
<section id="four" class="level1">
|
||||
<h1>Four</h1>
|
||||
</section>
|
||||
<section id="five" class="level1">
|
||||
<h1>Five</h1>
|
||||
</section>
|
||||
</div>
|
||||
<div class="part">
|
||||
<section id="six" class="level1">
|
||||
<h1>Six</h1>
|
||||
</section>
|
||||
<section id="seven" class="level1">
|
||||
<h1>Seven</h1>
|
||||
</section>
|
||||
<section id="eight" class="level1">
|
||||
<h1>Eight</h1>
|
||||
</section>
|
||||
</div>
|
||||
```
|
Loading…
Reference in a new issue