Skip to content

Commit

Permalink
Allow --shift-heading-level-by=-1 to work in djot...
Browse files Browse the repository at this point in the history
...in the same way it works for other formats (with the top-level
heading being promoted to metadata title).  This needed special
treatment because of the way djot surrounds sections with Divs.

Closes #10459.
  • Loading branch information
jgm committed Dec 19, 2024
1 parent 86dd2f7 commit 7cff359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Text/Pandoc/Transforms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ headerShift n (Pandoc meta (Header m _ ils : bs))
| n < 0
, m + n == 0 = headerShift n $
B.setTitle (B.fromList ils) $ Pandoc meta bs
-- for this case, see #10459:
headerShift n (Pandoc meta (Div attr@(_,"section":_,_) (Header m _ ils : as) : bs))
| n < 0
, m + n == 0 = headerShift n $
B.setTitle (B.fromList ils) $ Pandoc meta (Div attr as : bs)
headerShift n (Pandoc meta bs) = Pandoc meta (walk shift bs)

where
Expand Down
11 changes: 11 additions & 0 deletions test/command/10459.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```
% pandoc -s --shift-heading-level-by=-1 -f djot -t native
# hi
^D
Pandoc
Meta
{ unMeta =
fromList [ ( "title" , MetaInlines [ Str "hi" ] ) ]
}
[ Div ( "hi" , [ "section" ] , [] ) [] ]
```

0 comments on commit 7cff359

Please sign in to comment.