Skip to content

Commit

Permalink
Add minlevel option
Browse files Browse the repository at this point in the history
Closes: #8
  • Loading branch information
tarleb committed May 17, 2024
1 parent 4fe28f3 commit 21ada4b
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif
# Ensure that the `test` target is run each time it's called.
.PHONY: test
test: test-default test-no-citeproc test-refs-name test-section-level \
test-unnumbered-section
test-unnumbered-section test-minlevel

# Test that running the filter on the sample input document yields
# the expected output.
Expand All @@ -32,7 +32,7 @@ test-%: $(FILTER_FILE) test/input.md test/input-unnumbered-section.md \
# Update files that contain the expected test output
.PHONY: update-expected update-%
update-expected: update-default update-no-citeproc update-refs-name \
update-section-level update-unnumbered-section
update-section-level update-unnumbered-section update-minlevel
update-%: $(FILTER_FILE) \
test/input.md \
test/input-unnumbered-section.md \
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ nested below the `section-bibliographies` value:
(so if it occurs at the end of a level-1 section, it will
receive a level-2 header, and so on).

`section-bibiliograpies.minlevel`
: Sets the minimum section level at which bibliographies will be
produced. The default is 1. Higher numbers will leave
top-level sections unprocessed.

`section-bibliographies.bibliography`
: Behaves like `bibliography` in the context of this filter.
This variable exists because pandoc automatically invokes
Expand Down
14 changes: 13 additions & 1 deletion _extensions/section-bibliographies/section-bibliographies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ local function create_section_bibliography (meta, opts)
if not header or not suffix or opts.level < header.level then
-- Don't do anything for deeply-nested sections.
return div, false
elseif header.level < opts.minlevel then
-- Don't process sections above minlevel
div.content = div.content:map(process_div)
return div, false
elseif opts.level == header.level then
div.content = section_citeproc(div.content, suffix)
return adjust_refs_components(div), false
Expand Down Expand Up @@ -199,12 +203,20 @@ local function get_options (meta)
opts.bibliography = opts.bibliography
or meta['section-bibs-bibliography']
or meta['bibliography']
opts.level = opts.level
opts.level = tonumber(opts.level)
or tonumber(meta['section-bibs-level'])
or 1
opts.minlevel = tonumber(opts.minlevel)
or 1
opts.references = opts.references
or meta['references']

-- sanity check
if opts.level < opts.minlevel then
warn('level cannot be smaller than minlevel, setting minlevel = level')
opts.minlevel = opts.level
end

return opts
end

Expand Down
Loading

0 comments on commit 21ada4b

Please sign in to comment.