Commit graph

195 commits

Author SHA1 Message Date
Albert Krewinkel
672a4bdd1d Lua filters: allow filtering of element lists (#6040)
Lists of Inline and Block elements can now be filtered via `Inlines` and
`Blocks` functions, respectively. This is helpful if a filter conversion
depends on the order of elements rather than a single element.

For example, the following filter can be used to remove all spaces
before a citation:

    function isSpaceBeforeCite (spc, cite)
      return spc and spc.t == 'Space'
       and cite and cite.t == 'Cite'
    end

    function Inlines (inlines)
      for i = #inlines-1,1,-1 do
        if isSpaceBeforeCite(inlines[i], inlines[i+1]) then
          inlines:remove(i)
        end
      end
      return inlines
    end

Closes: #6038
2020-01-15 14:26:00 -08:00
John MacFarlane
ebf413cdec Update filters doc with better cabal v2 instructions. 2020-01-14 16:31:09 -08:00
John MacFarlane
dfac1239d9 Update filter documentation.
Remove example using pandoc API directly (we have other
docs for that and it was outdated).

Closes #6065.
2020-01-14 11:18:24 -08:00
Albert Krewinkel
11e99409ce
docs: capitalize Lua where it refers to the programming language name
This follows the advise on the Lua
website (https://www.lua.org/about.html#name):

> […] "Lua" is a name, the name of the Earth's moon and the name of the
> language. Like most names, it should be written in lower case with an
> initial capital, that is, "Lua".
2020-01-12 11:29:05 +01:00
Albert Krewinkel
6fd3d546a2
Lua filter docs: cross-link constructors and types
Thanks to @bpj for the idea.
2020-01-11 23:51:07 +01:00
Albert Krewinkel
4ede11a75f
Lua: add methods insert, remove, and sort to pandoc.List
The functions `table.insert`, `table.remove`, and `table.sort` are added
to pandoc.List elements.  They can be used as methods, e.g.

    local numbers = pandoc.List {2, 3, 1}
    numbers:sort()     -- numbers is now {1, 2, 3}
2020-01-11 21:31:20 +01:00
Albert Krewinkel
23d81081d0
doc/lua-filters.md: sort pandoc.List methods alphabetically 2020-01-11 21:29:47 +01:00
Albert Krewinkel
d09bcc7f16 doc/lua-filters.md: unify, fix anchors and internal links (#6061)
Links and anchors now follow consistent conventions, like lowercase-only
anchor names.

This breaks some links to specific sections in the document, but will
make it much easier to link documentation in the future.
2020-01-11 11:55:02 -08:00
Albert Krewinkel
e98921ae57
pandoc.List.lua: make pandoc.List a callable constructor
It is now possible to construct a new List via `pandoc.List()` instead of
`pandoc.List:new()`.
2020-01-11 19:38:27 +01:00
Albert Krewinkel
467ea4e02c docs/lua-filters.md: clarify filter function execution order (#6059) 2020-01-10 15:19:26 -08:00
Albert Krewinkel
2cf89ade85 doc/lua-filters.md: replace metadata example with image centering (#6004)
Metadata defaults can be given via the command line `--metadata-file`.
Adding raw format snippets is a common use case for Lua filters, so it
seems sensible to provide an example.

Thanks to @efx for proposing this filter.

Closes: pandoc/lua-filters#70
2019-12-22 16:09:30 -08:00
Mauro Bieg
abb0e35b94 lua-filters.md remove spurious dot in title (#5996) 2019-12-17 10:01:42 -08:00
Brian Wignall
a946424e3c Fix typos (#5919) 2019-11-20 09:44:23 -08:00
Albert Krewinkel
791043772b
doc/lua-filters.md: mention which Lua version is shipped with pandoc
See: #5892
2019-11-13 08:48:34 +01:00
John MacFarlane
8a2e87758e Fix metadata replacement example in lua-filters doc.
Closes #5851.

We avoid the failure with a boolean value by simply checking
to make sure we have a table before indexing.
2019-11-02 22:55:58 -07:00
Marcus Stollsteimer
57e2148ca2 Fix capitalization of "Linux" in docs (#5859) 2019-10-28 10:45:36 -07:00
Albert Krewinkel
88409f9afa
doc/lua-filters.md: fix mistakes in mediabag module docs
See: #5851
2019-10-27 23:09:20 +01:00
Albert Krewinkel
d0261d7387 Lua filters: allow passing of HTML-like tables instead of Attr (#5750)
Attr values can now be given as normal Lua tables; this can be used as a
convenient alternative to define Attr values, instead of constructing
values with `pandoc.Attr`. Identifiers are taken from the *id* field,
classes must be given as space separated words in the *class* field. All
remaining fields are included as misc attributes.

With this change, the following lines now create equal elements:

    pandoc.Span('test', {id = 'test', class = 'a b', check = 1})
    pandoc.Span('test', pandoc.Attr('test', {'a','b'}, {check = 1}))

This also works when using the *attr* setter:

    local span = pandoc.Span 'text'
    span.attr = {id = 'test', class = 'a b', check = 1}

Furthermore, the *attributes* field of AST elements can now be a plain
key-value table even when using the `attributes` accessor:

    local span = pandoc.Span 'test'
    span.attributes = {check = 1}   -- works as expected now

Closes: #5744
2019-09-15 12:11:58 -07:00
John MacFarlane
9f984ff26a Replace Element and makeHierarchical with makeSections.
Text.Pandoc.Shared:

+ Remove `Element` type [API change]
+ Remove `makeHierarchicalize` [API change]
+ Add `makeSections` [API change]
+ Export `deLink` [API change]

Now that we have Divs, we can use them to represent the structure
of sections, and we don't need a special Element type.
`makeSections` reorganizes a block list, adding Divs with
class `section` around sections, and adding numbering
if needed.

This change also fixes some longstanding issues recognizing
section structure when the document contains Divs.
Closes #3057, see also #997.

All writers have been changed to use `makeSections`.
Note that in the process we have reverted the change
c1d058aeb1
made in response to #5168, which I'm not completely
sure was a good idea.

Lua modules have also been adjusted accordingly.
Existing lua filters that use `hierarchicalize` will
need to be rewritten to use `make_sections`.
2019-09-08 22:20:19 -07:00
John MacFarlane
b6490de03b lua-filters - avoid duplicate id element-components. 2019-08-08 11:29:36 -07:00
John MacFarlane
01ad9399b9 Update lua-filters doc from lua sources. 2019-08-08 11:21:31 -07:00
John MacFarlane
808602ed8a Fix links to Attr in lua-filters.doc. 2019-08-08 11:14:43 -07:00
John MacFarlane
21c9548960 lua-filters.doc: make table narrower so it doesn't crowd out TOC. 2019-08-08 11:02:23 -07:00
Albert Krewinkel
11bb862767 Lua: add a clone() method to all AST elements (#5572)
Closes: #5568
2019-06-12 09:58:38 -07:00
John MacFarlane
62f8422b8c Fix typo in lua documentation.
Closes #5552.
2019-06-05 14:48:48 -07:00
Albert Krewinkel
9f43b2ef1a
doc/lua-filters.md: fix typos in pandoc.mediabag docs 2019-05-30 20:03:23 +02:00
Albert Krewinkel
5a82ecaaa1
pandoc.mediabag module: add function delete
Function `pandoc.mediabag.delete` allows to remove a single item of the given
name from the media bag.
2019-05-29 23:18:44 +02:00
Albert Krewinkel
0a6a11cfab
pandoc.mediabag module: add function empty
Function `pandoc.mediabag.empty` was added. It allows to clean-out the media
bag, removing all entries.
2019-05-29 23:18:44 +02:00
Albert Krewinkel
3097ee100e
pandoc.mediabag module: add items function iterating over mediabag
A new function `pandoc.mediabag.items` was added to Lua module
pandoc.mediabag. This allows users to lazily iterate over all media bag
items, loading items into Lua one-by-one. Example:

    for filename, mime_type, content in pandoc.mediabag.items() do
      -- use media bag item.
    end

This is a convenient alternative to using `mediabag.list` in combination
with `mediabag.lookup`.
2019-05-29 23:17:12 +02:00
Albert Krewinkel
8507d98a15
doc/lua-filters.md: improve docs for Version type/constructor 2019-05-29 22:59:45 +02:00
Albert Krewinkel
505f5bf5d9
Lua: add Version type to simplify comparisons
Version specifiers like `PANDOC_VERSION` and `PANDOC_API_VERSION` are
turned into `Version` objects. The objects simplify version-appropriate
comparisons while maintaining backward-compatibility.

A function `pandoc.types.Version` is added as part of the newly
introduced module `pandoc.types`, allowing users to create version
objects in scripts.
2019-05-29 10:07:43 +02:00
Albert Krewinkel
786594b23b Lua: add pandoc.system module (#5468)
The `system` Lua module provides utility functions to interact with the
operating- and file system. E.g.

    print(pandoc.system.get_current_directory())

or

    pandoc.system.with_temporary_directory('tikz', function (dir)
      -- write and compile a TikZ file with pdflatex
    end)
2019-05-04 01:06:30 -04:00
Shim Myeongseob
73efef589a Fix broken links in documents (#5473)
Fix broken links in doc/epub.md, doc/getting-started.md,
doc/customizing-pandoc.md, doc/using-the-pandoc-api.md.
Also, use absolute links to pandoc.org when possible, so that
the links can be followed by people viewing these documents
on GitHub.
2019-05-01 20:09:36 -04:00
Matthew Doty
32e358bfe9 Improved sample lua tikz filter in lua-filters docs (#5445)
There are three changes:

- It only processes elements which begin with \begin{tikzpicture}
- It uses pdf2svg instead of imagemagick to preserve fidelity
- The images produced have transparent backgrounds
2019-04-15 21:39:03 -07:00
Albert Krewinkel
b11ad32605
doc/lua-filters.md: fixed typos in mediabag docs. 2019-02-16 12:12:42 +01:00
Albert Krewinkel
75c791b4fe Lua filters: load module pandoc before calling init.lua (#5287)
The file `init.lua` in pandoc's data directory is run as part of
pandoc's Lua initialization process. Previously, the `pandoc` module was
loaded in `init.lua`, and the structure for marshaling was set-up after.
This allowed simple patching of element marshaling, but made using
`init.lua` more difficult:

  - it encouraged mixing essential initialization with user-defined
    customization;

  - upstream changes to init.lua had to be merged manually;

  - accidentally breaking marshaling by removing required modules was
    possible;

Instead, all required modules are now loaded before calling `init.lua`.
The file can be used entirely for user customization. Patching
marshaling functions, while discouraged, is still possible via the
`debug` module.
2019-02-09 13:56:49 -08:00
Albert Krewinkel
9a9c138d9c
data/pandoc.lua: re-export all bundled modules
All Lua modules bundled with pandoc, i.e., `pandoc.List`,
`pandoc.mediabag`, `pandoc.utils`, and `text` are re-exported from the
`pandoc` module. They are assigned to the fields `List`, `mediabag`,
`utils`, and `text`, respectively.
2019-02-09 20:12:33 +01:00
John MacFarlane
403aafe983 Small fix in lua-filters doc. 2019-02-08 11:11:57 -08:00
Albert Krewinkel
713ed7c0c5
data/pandoc.lua: re-export List and utils module 2019-02-07 10:10:55 +01:00
Albert Krewinkel
b436087bc8
doc/lua-filters.md: fix docs for OrderedList items 2019-02-01 21:19:52 +01:00
John MacFarlane
4e6ef53295 More improvements on lua-filters docs. 2019-01-31 10:13:36 -08:00
Albert Krewinkel
7b7db934a8
doc/lua-filters.md: use 3rd level headers for module fields 2019-01-30 21:41:40 +01:00
Albert Krewinkel
4eb8a97a1c
doc/org.md: improve documentation of org features 2018-12-29 15:20:44 +01:00
Julien Kirch
cefb0886c3 Fix progit book url 2018-11-29 16:26:31 -05:00
Albert Krewinkel
c0d8b0abcb
Lua filters: test AST object equality via Haskell
Equality of Lua objects representing pandoc AST elements is tested by
unmarshalling the objects and comparing the result in Haskell. A new
function `equals` which performs this test has been added to the
`pandoc.utils` module.

Closes: #5092
2018-11-19 21:46:20 +01:00
Mauro Bieg
f07ae68558
cusomizing-pandoc.md: streamline template text 2018-11-17 14:39:26 +01:00
Mauro Bieg
0466c0a8b0
customizing-templates.md: variable options table 2018-11-17 14:23:49 +01:00
John MacFarlane
2f579193ae getting-started.md: Added title to test1.md to avoid warning. 2018-11-01 11:49:49 -07:00
Albert Krewinkel
096cbe6987 Lua: allow access to pandoc state (#5015)
* Lua: allow access to pandoc state

Lua filters and custom writers now have read-only access to most fields
of pandoc's internal state via the global variable `PANDOC_STATE`.

* Lua: allow iterating through fields of PANDOC_STATE

* Lua filters doc: describe CommonState

* Lua filters doc: mention global variable PANDOC_STATE

* Lua: add access to logs

Log messages can currently only be printed, but not decomposed.
2018-10-25 22:12:14 -07:00
Albert Krewinkel
00b0c4a57b
Lua filter doc: merge type references into main document 2018-10-19 08:14:10 +02:00
Albert Krewinkel
e3b85517d6
Lua filters doc: fix and add more links to types 2018-10-18 22:27:14 +02:00
John MacFarlane
63b3886bfe Added note to customizing-pandoc. 2018-10-16 10:42:48 -07:00
John MacFarlane
a552af612e customizing-pandoc: add suggestion about 'pandoc -t native'. 2018-10-16 09:57:10 -07:00
John MacFarlane
e32220ef4f Revised customizing-pandoc.md and included TODOs. 2018-10-16 09:54:59 -07:00
Mauro Bieg
a5fc46cb8f add docs about customizing pandoc (#4972)
closes #3288
2018-10-16 09:10:34 -07:00
Albert Krewinkel
b831bd9fc1 Lua filter docs: extend description of table fields 2018-10-16 08:01:59 +02:00
Albert Krewinkel
7e9e24b8bc Lua filter docs: describe Attr type 2018-10-15 23:01:23 +02:00
Albert Krewinkel
f6559e5def Lua filter docs: render field names as code 2018-10-15 22:52:02 +02:00
Albert Krewinkel
d9f179f7f2 Lua filter docs: fix typos 2018-10-15 22:17:12 +02:00
Albert Krewinkel
aed7aecfc3 Lua filter docs: complete, fix MetaValue documentation 2018-10-15 21:10:05 +02:00
Albert Krewinkel
1435d0b079
Lua filters doc: add ReaderOptions to list of objects 2018-10-15 07:56:35 +02:00
Albert Krewinkel
418f6e093c
Lua filter docs: add documentation for Element/Sec 2018-10-13 16:25:54 +02:00
Albert Krewinkel
1ac87b487f
Lua filter docs: document list attributes 2018-10-11 22:30:40 +02:00
Albert Krewinkel
5f6f2c69f5
data/pandoc.lua: add datatype ListAttributes
Make ListAttributes a datatype. The type is similar to Attr.
2018-10-11 22:28:24 +02:00
Albert Krewinkel
484056a4cd
Lua filter docs: document fields of Citation objects 2018-10-11 21:25:26 +02:00
Albert Krewinkel
2e63e2f2bc
Lua filter docs: document fields of inline objects 2018-10-11 20:51:54 +02:00
Albert Krewinkel
36a6a40ef7
Documentation: add draft for Lua objects reference 2018-10-06 21:48:25 +02:00
Albert Krewinkel
05efa5a0e6
Lua filter doc: fix description of Code.text 2018-10-06 21:48:24 +02:00
John MacFarlane
ba09d2942a lua-filters.md: add links to filters, and to lua-filters repository.
Closes #4874.
2018-09-07 16:29:21 -07:00
Albert Krewinkel
fb94c0f6a1 Lua Utils module: add function blocks_to_inlines (#4799)
Exposes a function converting which flattenes a list of blocks into a
list of inlines. An example use case would be the conversion of Note
elements into other inlines.
2018-07-30 10:55:25 -07:00
Alexander Krotov
41cf6d540f More spellcheck 2018-07-02 19:07:28 +03:00
HeirOfNorton
f5b89b5adb Fix example in lua-filters docs. Fixes #4459 (#4476) 2018-03-19 21:43:43 -07:00
Albert Krewinkel
b4717a6acb
doc/org.md: Add Org-mode documentation (very first draft) 2018-02-25 14:30:15 +01:00
Albert Krewinkel
eb16f3354f
doc/lua-filters.md: document global vars set for filters 2018-02-24 23:38:27 +01:00
Alexander Krotov
b818623d42 Fix Text.Pandoc.Builder link 2018-01-22 15:43:48 +03:00
Albert Krewinkel
8d5422f36b
Lua modules: add function pandoc.utils.run_json_filter
Runs a JSON filter on a Pandoc document.
2018-01-13 00:07:03 +01:00
Albert Krewinkel
b6cec3da3f
data/pandoc.lua: fix docstrings
Change: minor
2018-01-07 22:41:59 +01:00
Albert Krewinkel
7fa286fff1
Update tool which generates lua module docs
All "helper functions" are not part of the Lua code for module pandoc,
but are added in Haskell. The respective documentation section must
therefore be excluded from automatic regeneration.
2017-12-29 10:04:55 +01:00
Albert Krewinkel
9be2c7624c
data/pandoc.lua: drop function pandoc.global_filter
The function `global_filter` was used internally to get the implicitly
defined global filter. It was of little value to end-users, but caused
unnecessary code duplication in pandoc. The function has hence been
dropped. Internally, the global filter is now received by interpreting
the global table as lua filter.

This is a Lua API change.
2017-12-29 10:04:55 +01:00
Albert Krewinkel
820ee07f72
doc/lua-filters.md: re-add docs for helper functions
These docs are dropped, as the functions are no longer part of
data/pandoc.lua, from which this section is generated. This is only a
temporary fix: a proper fix will have to re-think how this section is
updated.
2017-12-29 09:04:21 +01:00
Albert Krewinkel
ec068f2318
data/pandoc.lua: fix documentation for global_filter 2017-12-29 09:02:25 +01:00
John MacFarlane
246e8f081a Update lua-filters.md and the tool that generates it. 2017-12-28 22:02:59 -08:00
John MacFarlane
346b10392f Update docs on filters. 2017-12-28 16:39:52 -08:00
John MacFarlane
ba4b9db16d Tweaks to lua-filters.md docs 2017-12-26 10:25:05 -08:00
Albert Krewinkel
59a4745457
Lua modules: add function pandoc.utils.hierarchicalize
Convert list of Pandoc blocks into (hierarchical) list of Elements.
2017-12-23 23:29:24 +01:00
Albert Krewinkel
2c66a42ab8
Lua modules: add function pandoc.utils.normalize_date
The function parses a date and converts it (if possible) to "YYYY-MM-DD"
format.
2017-12-23 13:43:22 +01:00
Albert Krewinkel
35f0567a8f
Lua modules: add function pandoc.utils.to_roman_numeral
The function allows conversion of numbers below 4000 into roman
numerals.
2017-12-23 13:42:35 +01:00
Albert Krewinkel
dd217f75e5
doc/lua-filter.md: document pandoc.utils.stringify
Change: minor
2017-12-22 20:29:00 +01:00
Albert Krewinkel
bd3ea72371
Lua modules: added pandoc.utils module
A new module `pandoc.utils` has been created. It holds utility functions
like `sha1`, which was moved from the main `pandoc` module.
2017-12-21 22:42:59 +01:00
John MacFarlane
b88cd9c2ed filters.md: say that Text.Pandoc.JSON comes form pandoc-types.
Closes jgm/pandoc-website#16.
2017-12-14 20:54:15 -08:00
Georger Araújo
ce73dec833 Delete removed -S option from command in epub.md (#4151)
Because `--smart/-S` has been removed.
Maybe ` -f markdown+smart` shoud also be added?
2017-12-13 11:28:16 -07:00
Albert Krewinkel
4066a385ac
Lua filters: use script to initialize the interpreter
The file `init.lua` is used to initialize the Lua interpreter which is
used in Lua filters. This gives users the option to require libraries
which they want to use in all of their filters, and to extend default
modules.
2017-12-06 22:50:56 +01:00
Albert Krewinkel
6640506ddc
Lua/StackInstances: push Pandoc and Meta via constructor
Pandoc and Meta elements are now pushed by calling the respective
constructor functions of the pandoc Lua module. This makes serialization
consistent with the way blocks and inlines are pushed to lua and allows
to use List methods with the `blocks` value.
2017-12-01 17:58:12 +01:00
Albert Krewinkel
5026dfaedf
lua-filters.md: add documentation for pandoc.List 2017-12-01 17:14:28 +01:00
John MacFarlane
d070424b94 lua-filters.md - added tikz filter example. 2017-11-21 12:20:28 -08:00
John MacFarlane
1c85a158f3 Added epub.md, getting-started.md to docs.
These used to live in the website repo.
2017-11-21 08:45:43 -08:00
John MacFarlane
f28f34244a Update title and authors on lua-filters.md. 2017-11-20 16:51:45 -08:00
John MacFarlane
47e74742a8 Documented text module for lua-filters.
See #4077.
2017-11-18 13:40:47 -08:00
John MacFarlane
17f6621b21 Update man page lua filter to use text module. 2017-11-18 13:33:37 -08:00
John MacFarlane
e5e8350fcb More efficient wordcount.lua example. 2017-11-12 21:55:10 -08:00