View Source FancyFences.Processors (fancy_fences v0.3.0)

Common fence processors.

Link to this section Summary

Functions

A fence processor for documenting fence processors usage.

Formats the given code block.

Embeds the original code and the evaluated result.

Link to this section Functions

Link to this function

fence_processor_doc(code)

View Source

A fence processor for documenting fence processors usage.

This can be used for documenting fence processors. It return an admonition block containing both the sample code and the output of the fence processor.

usage

Usage

It expects a map with the following key-value pairs:

  • block - the code block to use as an example
  • processor - an anonymous function with the processor that will be used.

For example:

```fence-processor
%{
  block: "Enum.map([1, 2, 3], fn x -> 2*x end)",
  processor: fn block -> FancyFences.Processors.inspect_code(block) end
}
```

Embedded code

A fenced code block of the form:

```lang
%{
   block: "1 + 1",
   processor: fn block ->
     "**Code:** `"<> block <> "`"
   end
}

```

will be transformed to:

Embedded code

A fenced code block of the form:

```lang
1 + 1
```

will be transformed to:

Code: 1 + 1

where lang the defined code language for this fence processor in your mix.exs.

where lang the defined code language for this fence processor in your mix.exs.

Notice that above we used fence_processor_doc/1 to document itself, that's why we have the nested admonition block.

Formats the given code block.

Embedded code

A fenced code block of the form:

```lang
for x <- [1, 2, 3] do
2 * x
end

```

will be transformed to:

for x <- [1, 2, 3] do
  2 * x
end

where lang the defined code language for this fence processor in your mix.exs.

Link to this function

inspect_code(code, opts \\ [])

View Source

Embeds the original code and the evaluated result.

options

Options

  • :format (boolean) - If set to true the code blocks will be formatted before inection. Defaults to false.

Embedded code

A fenced code block of the form:

```lang
Enum.map([1, 2, 3, 4], fn x -> 2*x end)
```

will be transformed to:

Enum.map([1, 2, 3, 4], fn x -> 2*x end)
[2, 4, 6, 8]

where lang the defined code language for this fence processor in your mix.exs.