Skip to content

Commit

Permalink
inception in fence_processor_doc self documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pnezis committed Oct 1, 2023
1 parent fba40c0 commit 6380204
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Package](https://img.shields.io/badge/-Package-important)](https://hex.pm/packages/fancy_fences)
[![Documentation](https://img.shields.io/badge/-Documentation-blueviolet)](https://hexdocs.pm/fancy_fences)

`FancyFences` is a markdown processor on top of [`Earmark`](https://github.com/pragdave/earmark)
`FancyFences` is a markdown processor on top of [`EarmarkParser`](https://github.com/pragdave/earmark)
(the default markdown processor user by [`ExDoc`](https://github.com/elixir-lang/ex_doc). You can
use it to conditionally post-process code blocks allowing you to:

Expand Down
23 changes: 20 additions & 3 deletions lib/fancy_fences/processors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule FancyFences.Processors do
Common fence processors.
"""

@doc """
@doc ~S'''
A fence processor for documenting fence processors usage.
This can be used for documenting fence processors. It return an admonition
Expand All @@ -19,14 +19,31 @@ defmodule FancyFences.Processors do
For example:
~~~
```fence-processor-docs
```fence-processor
%{
block: "Enum.map([1, 2, 3], fn x -> 2*x end)",
processor: fn block -> FancyFences.Processors.inspect_code(block) end
}
```
~~~
"""
```fence-processor
%{
block: """
%{
block: "1 + 1",
processor: fn block ->
"**Code:** `"<> block <> "`"
end
}
""",
processor: fn block -> FancyFences.Processors.fence_processor_doc(block) end
}
```
Notice that above we used `fence_processor_doc/1` to document itself, that's why
we have the nested admonition block.
'''
def fence_processor_doc(code) do
{result, _} = Code.eval_string(code, [], __ENV__)
%{block: block, processor: processor} = result
Expand Down

0 comments on commit 6380204

Please sign in to comment.