Skip to content

Commit

Permalink
Add simple shell lexer (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Jul 13, 2021
1 parent 0fb23da commit c308c99
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ You can ExDoc via the command line as follows:

1. Install ExDoc as an escript:

```bash
$ mix escript.install hex ex_doc
```
```bash
$ mix escript.install hex ex_doc
```

2. Then you are ready to use it in your projects. First, move into your project directory and make sure it is already compiled:

```bash
$ cd PATH_TO_YOUR_PROJECT
$ mix compile
```
```bash
$ cd PATH_TO_YOUR_PROJECT
$ mix compile
```

3. Next invoke the ex_doc executable from your project:
3. Next invoke the `ex_doc` executable from your project:

```bash
$ ex_doc "PROJECT_NAME" "PROJECT_VERSION" path/to/project/ebin -m "PROJECT_MODULE" -u "https://github.com/GITHUB_USER/GITHUB_REPO" -l path/to/logo.png
```
```bash
$ ex_doc "PROJECT_NAME" "PROJECT_VERSION" path/to/project/ebin -m "PROJECT_MODULE" -u "https://github.com/GITHUB_USER/GITHUB_REPO" -l path/to/logo.png
```

For example, here are some acceptable values:

Expand Down
6 changes: 6 additions & 0 deletions lib/ex_doc/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ defmodule ExDoc.Application do
use Application

def start(_type, _args) do
Makeup.Registry.register_lexer(ExDoc.ShellLexer,
options: [],
names: ["shell", "sh", "bash", "zsh"],
extensions: []
)

Enum.each([:eex, :ex_unit, :iex, :logger, :mix], &Application.load/1)
Supervisor.start_link([ExDoc.Refs], strategy: :one_for_one)
end
Expand Down
43 changes: 43 additions & 0 deletions lib/ex_doc/shell_lexer.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule ExDoc.ShellLexer do
# Makeup lexer for sh, bash, etc commands.
# The only thing it does is making the `$ ` prompt not selectable.
@moduledoc false

@behaviour Makeup.Lexer

@impl true
def lex(text, _opts) do
text
|> String.split("\n")
|> Enum.flat_map(fn
"$ " <> rest ->
[
{:generic_prompt, %{selectable: false}, "$ "},
{:text, %{}, rest <> "\n"}
]

text ->
[{:text, %{}, text <> "\n"}]
end)
end

@impl true
def match_groups(_arg0, _arg1) do
raise "not implemented yet"
end

@impl true
def postprocess(_arg0, _arg1) do
raise "not implemented yet"
end

@impl true
def root(_arg0) do
raise "not implemented yet"
end

@impl true
def root_element(_arg0) do
raise "not implemented yet"
end
end

0 comments on commit c308c99

Please sign in to comment.