-
-
Notifications
You must be signed in to change notification settings - Fork 996
Generalize number sections #1879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c9bc664
50da643
3810583
6b7863e
5bdc30d
3d8bac1
3e6f02e
0939f24
5c091d2
1a83771
e487cd2
0f2f873
55dd2f4
4fe5c2b
06cf99a
1919c55
9bd22bd
8d7ec18
6dee7ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --[[ | ||
| number-sections - Number sections like the --number-sections option | ||
| # MIT License | ||
| Copyright (c) 2020 Atsushi Yasumoto | ||
atusy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| https://github.com/atusy/lua-filters/blob/master/lua/number-sections.lua | ||
| ]] | ||
| local section_number_table = {0, 0, 0, 0, 0, 0, 0, 0, 0} | ||
| local n_section_number_table = #section_number_table | ||
| local previous_header_level = 0 | ||
| local separator = pandoc.Space() | ||
| if FORMAT == "docx" then -- to be consistent with Pandoc >= 2.10.1 | ||
| separator = pandoc.Str("\t") | ||
| end | ||
|
|
||
| function Header(elem) | ||
| -- If unnumbered | ||
| if (elem.classes:find("unnumbered")) then | ||
| return elem | ||
| end | ||
|
|
||
| -- Else | ||
| --- Reset and update section_number_table | ||
| if (elem.level < previous_header_level) then | ||
| for i=elem.level+1,n_section_number_table do | ||
| section_number_table[i] = 0 | ||
| end | ||
| end | ||
| previous_header_level = elem.level | ||
| section_number_table[elem.level] = section_number_table[elem.level] + 1 | ||
|
|
||
| --- Define section number as string | ||
| local section_number_string = tostring(section_number_table[elem.level]) | ||
| if elem.level > 1 then | ||
| for i = elem.level-1,1,-1 do | ||
| section_number_string = section_number_table[i] .. "." .. section_number_string | ||
| end | ||
| end | ||
|
|
||
| --- Update Header element | ||
| table.insert(elem.content, 1, separator) | ||
| table.insert(elem.content, 1, pandoc.Str(section_number_string)) | ||
|
|
||
| return elem | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.