forked from pandoc/lua-filters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpected.native
60 lines (60 loc) · 3.17 KB
/
expected.native
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[ 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" ) ]
)
"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
[ Code ( "" , [] , [] ) "detent"
, Space
, Str "removes"
, Space
, Str "specified"
, Space
, Str "number"
, Space
, Str "of"
, Space
, Str "whitespaces"
, Space
, Str "(and"
, Space
, Str "only"
, SoftBreak
, Str "whitespaces)"
, Space
, Str "from"
, Space
, Str "beginning"
, Space
, Str "of"
, Space
, Str "each"
, Space
, 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"
]