Skip to content
Snippets Groups Projects
Commit 4d1fa08c authored by Bruno BEAUFILS's avatar Bruno BEAUFILS
Browse files

Add test

parent 909c8be4
No related branches found
No related tags found
No related merge requests found
Pandoc
Meta
{ unMeta =
fromList
[ ( "author" , MetaInlines [ Str "Nullus" ] )
, ( "subtitle"
, MetaInlines [ Str "Lorem" , Space , Str "ipsum" ]
[ Header 1 ( "inclusion" , [] , [] ) [ Str "Inclusion" ]
, CodeBlock
( "" , [ "lua" , "numberLines" ] , [] )
"--- include-code-files.lua \8211 filter to include code from source files\n---\n--- Copyright: \169 2020 Bruno BEAUFILS\n--- License: MIT \8211 see LICENSE file for details\n\n--- Dedent a line\nlocal function dedent (line, n)\n return line:sub(1,n):gsub(\" \",\"\") .. line:sub(n+1)\nend\n\n--- Filter function for code blocks\nlocal function transclude (cb)\n if cb.attributes.include then\n local content = \"\"\n local fh = io.open(cb.attributes.include)\n if not fh then\n io.stderr:write(\"Cannot open file \" .. cb.attributes.include .. \" | Skipping includes\\n\")\n else\n local number = 1\n local start = 1\n\n -- change hyphenated attributes to PascalCase\n for i,pascal in pairs({\"startLine\", \"endLine\"})\n do\n local hyphen = pascal:gsub(\"%u\", \"-%0\"):lower()\n if cb.attributes[hyphen] then\n cb.attributes[pascal] = cb.attributes[hyphen]\n cb.attributes[hyphen] = nil\n end\n end\n\n if cb.attributes.startLine then\n cb.attributes.startFrom = cb.attributes.startLine\n start = tonumber(cb.attributes.startLine)\n end\n for line in fh:lines (\"L\")\n do\n if cb.attributes.dedent then\n line = dedent(line, cb.attributes.dedent)\n end\n if number >= start then\n if not cb.attributes.endLine or number <= tonumber(cb.attributes.endLine) then\n content = content .. line\n end\n end\n number = number + 1\n end \n fh:close()\n end \n -- remove key-value pair for used keys\n cb.attributes.include = nil\n cb.attributes.startLine = nil\n cb.attributes.endLine = nil\n cb.attributes.dedent = nil\n -- return final code block\n return pandoc.CodeBlock(content, cb.attr)\n end\nend\n\nreturn {\n { CodeBlock = transclude }\n}\n"
, Header 1 ( "ranges" , [] , [] ) [ Str "Ranges" ]
, CodeBlock
( ""
, [ "lua" , "numberLines" ]
, [ ( "startFrom" , "7" ) ]
)
, ( "title" , MetaInlines [ Str "Greetings!" ] )
]
}
[ Para
[ Str "Hello"
, Space
, Str "from"
, Space
, Str "the"
, Space
, Str "Lua"
, Space
, Str "filter!"
]
"local function dedent (line, n)\n return line:sub(1,n):gsub(\" \",\"\") .. line:sub(n+1)\nend\n"
, CodeBlock
( ""
, [ "lua" , "numberLines" ]
, [ ( "startFrom" , "7" ) ]
)
"local function dedent (line, n)\n return line:sub(1,n):gsub(\" \",\"\") .. line:sub(n+1)\nend\n"
, Header 1 ( "detent" , [] , [] ) [ Str "Detent" ]
, Para
[ Str "Lorem"
, Space
, Str "ipsum"
[ Code ( "" , [] , [] ) "detent"
, Space
, Str "dolor"
, Str "removes"
, Space
, Str "sit"
, Str "specified"
, Space
, Str "amet,"
, Str "number"
, Space
, Str "consectetuer"
, Str "of"
, Space
, Str "adipiscing"
, Str "whitespaces"
, Space
, Str "elit."
, Str "(and"
, Space
, Str "Donec"
, Str "only"
, SoftBreak
, Str "hendrerit"
, Space
, Str "tempor"
, Space
, Str "tellus."
, Space
, Str "Donec"
, Str "whitespaces)"
, Space
, Str "pretium"
, Space
, Str "posuere"
, Space
, Str "tellus."
, Space
, Str "Proin"
, Space
, Str "quam"
, SoftBreak
, Str "nisl,"
, Space
, Str "tincidunt"
, Space
, Str "et,"
, Space
, Str "mattis"
, Str "from"
, Space
, Str "eget,"
, Str "beginning"
, Space
, Str "convallis"
, Str "of"
, Space
, Str "nec,"
, Str "each"
, Space
, Str "purus."
, Str "line"
]
, CodeBlock
( ""
, [ "lua" , "bash" , "numberLines" ]
, [ ( "startFrom" , "8" ) ]
)
"return line:sub(1,n):gsub(\" \",\"\") .. line:sub(n+1)\n"
, CodeBlock
( ""
, [ "lua" , "numberLines" ]
, [ ( "startFrom" , "61" ) ]
)
"{CodeBlock = transclude }\n"
]
---
title: Lorem ipsum
author: Nullus
author: me
title: Including Hello World
---
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
nisl, tincidunt et, mattis eget, convallis nec, purus.
# Inclusion
``` {include="include-code-files.lua" .lua .numberLines}
```
# Ranges
``` {include="include-code-files.lua" .lua startLine=7 endLine=9 .numberLines}
```
``` {include="include-code-files.lua" .lua start-line=7 end-line=9 .numberLines}
```
# Detent
`detent` removes specified number of whitespaces (and only
whitespaces) from beginning of each line
``` {include="include-code-files.lua" .lua startLine=8 endLine=8 dedent=4 .bash .numberLines}
```
``` {include="include-code-files.lua" .lua startLine=61 endLine=61 dedent=5 .numberLines}
```
input-files: ["test/input.md"]
to: native
standalone: true
standalone: false
filters:
- {type: lua, path: greetings.lua}
- {type: lua, path: include-code-files.lua}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment