mirror of
https://github.com/TangentFoxy/.lua-files.git
synced 2024-11-20 21:34:23 +00:00
close #17 automatic_naming implemented
This commit is contained in:
parent
62b9574b56
commit
d58f161e9e
@ -32,6 +32,7 @@ The following is shared:
|
||||
- `start`: (Optional) Number: Where to start. (`1` is the default, since it is the most common.)
|
||||
- `finish`: Number: Where to end.
|
||||
- `naming`: (Optional) String: How to name sections in the final output. The result is `[naming] [#]` (using section numbers). If not specified, there will be no Table of Contents.
|
||||
- `automatic_naming`: (Optional) Boolean: If any line matches "Prologue" or "Chapter #" (any number), it will be made into a heading. (Note: This does not override `naming`. Both can be used together.)
|
||||
|
||||
Example:
|
||||
```json
|
||||
|
@ -223,7 +223,25 @@ local function concatenate_pages(config)
|
||||
for page = 1, config.page_counts[section - (config.sections.start - 1)] do
|
||||
local page_file, err = io.open(section_dir .. page .. ".md", "r")
|
||||
if not page_file then error(err) end
|
||||
section_file:write(page_file:read("*a") .. "\n") -- the \n probably isn't needed, but does guarantee safety..
|
||||
if config.sections.automatic_naming then
|
||||
local naming_patterns = {
|
||||
"^Prologue$",
|
||||
"^Chapter %d+$",
|
||||
}
|
||||
local line = page_file:read("*line")
|
||||
while line do
|
||||
for _, pattern in ipairs(naming_patterns) do
|
||||
if line:find(pattern) then
|
||||
line = "# " .. line
|
||||
end
|
||||
end
|
||||
section_file:write(line .. "\n")
|
||||
line = page_file:read("*line")
|
||||
end
|
||||
else
|
||||
section_file:write(page_file:read("*a"))
|
||||
end
|
||||
section_file:write("\n") -- guarantees no accidental line collisions
|
||||
page_file:close()
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user