pandocfilters

package module
v0.0.0-...-277a35a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2017 License: BSD-3-Clause Imports: 6 Imported by: 2

README

Pandoc filters for Go

Description

pandocfilters for Go. This Go package provides filters for Pandoc. This is a port of the pandocfilters package from Python to Go. See documentation for using Pandoc filters.

Documentation

Overview

Author: Oleg Tolmatcev <oleg.tolmatcev@gmail.com> Copyright: (C) 2013-2017 Oleg Tolmatcev

Author: John MacFarlane <jgm@berkeley.edu> Copyright: (C) 2013 John MacFarlane License: BSD3

Functions to aid writing python scripts that process the pandoc AST serialized as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attributes

func Attributes(attrs map[string]interface{}) []interface{}

Returns an attribute list, constructed from the dictionary attrs.

func BlockQuote

func BlockQuote(blocks []interface{}) map[string]interface{}

func BulletList

func BulletList(listOfItems [][]interface{}) map[string]interface{}

func Caps

func Caps(key string, value interface{}, format string, meta interface{}) interface{}

func Cite

func Cite(citations []interface{}, inlines []interface{}) map[string]interface{}

func Code

func Code(attrs []interface{}, str string) map[string]interface{}

func CodeBlock

func CodeBlock(attrs []interface{}, str string) map[string]interface{}

func DefinitionList

func DefinitionList(defList []interface{}) map[string]interface{}

func Div

func Div(attrs []interface{}, blocks []interface{}) map[string]interface{}

func Emph

func Emph(inlines []interface{}) map[string]interface{}

func GetCaption

func GetCaption(kv []interface{}) ([]interface{}, string, []interface{})

get caption from the keyvalues (options)

Example:

if key == 'CodeBlock':
  [[ident, classes, keyvals], code] = value
  caption, typef, keyvals = get_caption(keyvals)
  ...
  return Para([Image([ident, [], keyvals], caption, [filename, typef])])

func GetExtension

func GetExtension(format string, def string, alternates ...map[string]string) string

get the extension for the result, needs a default and some specialisations

Example:

filetype = get_extension(format, "png", html="svg", latex="eps")

func GetFilename4code

func GetFilename4code(module string, content string, exts ...string) string

Generate filename based on content

The function ensures that the (temporary) directory exists, so that the file can be written.

Example:

filename = get_filename4code("myfilter", code)

func GetValue

func GetValue(keyvalues []interface{}, key string, values ...string) (interface{}, []interface{})

get value from the keyvalues (options)

func Header(level int, attrs []interface{}, inlines []interface{}) map[string]interface{}

func HorizontalRule

func HorizontalRule() map[string]interface{}

func Image

func Image(attrs []interface{}, inlines []interface{}, target []string) map[string]interface{}

func LineBreak

func LineBreak() map[string]interface{}
func Link(attrs []interface{}, inlines []interface{}, target []interface{}) map[string]interface{}

func Math

func Math(mathType interface{}, str string) map[string]interface{}

func Note

func Note(blocks []interface{}) map[string]interface{}

func Null

func Null() map[string]interface{}

func OrderedList

func OrderedList(attrs []interface{}, listOfItems [][]interface{}) map[string]interface{}

func Para

func Para(inlines []interface{}) map[string]interface{}

func Plain

func Plain(inlines []interface{}) map[string]interface{}

func Quoted

func Quoted(quoteType interface{}, inlines []interface{}) map[string]interface{}

func RawBlock

func RawBlock(format interface{}, str string) map[string]interface{}

func RawInline

func RawInline(format string, str string) map[string]interface{}

func SmallCaps

func SmallCaps(inlines []interface{}) map[string]interface{}

func SoftBreak

func SoftBreak() map[string]interface{}

func Space

func Space() map[string]interface{}

func Span

func Span(attrs []interface{}, inlines []interface{}) map[string]interface{}

func Str

func Str(text string) map[string]interface{}

func Strikeout

func Strikeout(inlines []interface{}) map[string]interface{}

func Stringify

func Stringify(x interface{}) string

Walks the tree x and returns concatenated string content, leaving out all formatting.

func Strong

func Strong(inlines []interface{}) map[string]interface{}

func Subscript

func Subscript(inlines []interface{}) map[string]interface{}

func Superscript

func Superscript(inlines []interface{}) map[string]interface{}

func Table

func Table(caption []interface{}, colAlign []interface{}, relColWidth []interface{},
	colHeader []interface{}, rows [][]interface{}) map[string]interface{}

func ToJSONFilter

func ToJSONFilter(action Action)

Like `toJSONFilters`, but takes a single action as argument.

func ToJSONFilters

func ToJSONFilters(actions []Action)

Generate a JSON-to-JSON filter from stdin to stdout The filter: * reads a JSON-formatted pandoc document from stdin * transforms it by walking the tree and performing the actions * returns a new JSON-formatted pandoc document to stdout The argument `actions` is a list of functions of the form `action(key, value, format, meta)`, as described in more detail under `walk`. This function calls `applyJSONFilters`, with the `format` argument provided by the first command-line argument, if present. (Pandoc sets this by default when calling filters.)

func Walk

func Walk(x interface{}, action Action, format string, meta interface{}) interface{}

Walk a tree, applying an action to every object. Returns a modified tree. An action is a function of the form `action(key, value, format, meta)`, where:

  • `key` is the type of the pandoc object (e.g. 'Str', 'Para') `value` is
  • the contents of the object (e.g. a string for 'Str', a list of inline elements for 'Para')
  • `format` is the target output format (as supplied by the `format` argument of `walk`)
  • `meta` is the document's metadata

The return of an action is either:

  • `None`: this means that the object should remain unchanged
  • a pandoc object: this will replace the original object
  • a list of pandoc objects: these will replace the original object; the list is merged with the neighbors of the orignal objects (spliced into the list the original object belongs to); returning an empty list deletes the object

Types

type Action

type Action func(string, interface{}, string, interface{}) interface{}

Directories

Path Synopsis
Pandoc filter to allow interpolation of metadata fields into a document.
Pandoc filter to allow interpolation of metadata fields into a document.
graphviz command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL