Skip to content

Commit

Permalink
Allow unnested lower-level headings to mark abstracts
Browse files Browse the repository at this point in the history
Closes: #4
  • Loading branch information
tarleb committed Apr 27, 2023
1 parent 8888986 commit 0ecb36f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion _extensions/abstract-section/abstract-section.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ local section_identifiers = {
abstract = true,
}
local collected = {}
--- The level of the highest heading that was seen so far. Abstracts
--- must be at or above this level to prevent nested sections from being
--- treated as metadata. Only top-level sections should become metadata.
local toplevel = 6

--- Extract abstract from a list of blocks.
local function abstract_from_blocklist (blocks)
local body_blocks = {}
local looking_at_section = false

for _, block in ipairs(blocks) do
if block.t == 'Header' and block.level == 1 then
if block.t == 'Header' and block.level <= toplevel then
toplevel = block.level
if section_identifiers[block.identifier] then
looking_at_section = block.identifier
collected[looking_at_section] = {}
Expand Down
13 changes: 13 additions & 0 deletions test/expected-shifted-headings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
abstract: |
Nullam eu ante vel est convallis dignissim. Fusce suscipit, wisi nec
facilisis facilisis, est dui fermentum leo, quis tempor ligula erat
quis odio. Nunc porta vulputate tellus.
---

## Lorem Ipsum

Quo dolore molestiae et laboriosam occaecati explicabo corrupti. Earum
expedita ducimus quaerat est quam ut molestiae. Illum deleniti vel
labore facilis et cum est. Est nemo est vel ad. Assumenda consequatur
rerum officiis atque officia. Est nihil iste cumque ad qui.
13 changes: 13 additions & 0 deletions test/input-shifted-headings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Abstract

Nullam eu ante vel est convallis dignissim. Fusce suscipit, wisi
nec facilisis facilisis, est dui fermentum leo, quis tempor ligula
erat quis odio. Nunc porta vulputate tellus.

## Lorem Ipsum

Quo dolore molestiae et laboriosam occaecati explicabo corrupti.
Earum expedita ducimus quaerat est quam ut molestiae. Illum
deleniti vel labore facilis et cum est. Est nemo est vel ad.
Assumenda consequatur rerum officiis atque officia. Est nihil iste
cumque ad qui.
4 changes: 4 additions & 0 deletions test/test-shifted-headings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input-files: [test/input-shifted-headings.md]
standalone: true
filters: [{type: lua, path: abstract-section.lua}]
to: markdown

0 comments on commit 0ecb36f

Please sign in to comment.