Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparing ex_doc to switch to EarmarkParser #1209

Merged
merged 3 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

* [mix docs] Depend on earmark_parser `~> 1.4.0`

## v0.22.1 (2020-05-19)

* Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion bin/ex_doc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mix_env = System.get_env()["MIX_ENV"] || "dev"
Code.prepend_path Path.expand("../_build/#{mix_env}/lib/nimble_parsec/ebin", __DIR__)
Code.prepend_path Path.expand("../_build/#{mix_env}/lib/makeup/ebin", __DIR__)
Code.prepend_path Path.expand("../_build/#{mix_env}/lib/makeup_elixir/ebin", __DIR__)
Code.prepend_path Path.expand("../_build/#{mix_env}/lib/earmark/ebin", __DIR__)
Code.prepend_path Path.expand("../_build/#{mix_env}/lib/earmark_parser/ebin", __DIR__)
Code.prepend_path Path.expand("../_build/#{mix_env}/lib/ex_doc/ebin", __DIR__)

if Code.ensure_loaded?(ExDoc.CLI) do
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_doc/markdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ defmodule ExDoc.Markdown do

ExDoc supports the following Markdown parsers out of the box:

* [Earmark](http://github.com/pragdave/earmark)
* [EarmarkParser](http://github.com/robertdober/earmark_parser)

ExDoc uses Earmark by default.
ExDoc uses EarmarkParser by default.
"""

@doc """
Expand Down
28 changes: 14 additions & 14 deletions lib/ex_doc/markdown/earmark.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
defmodule ExDoc.Markdown.Earmark do
@moduledoc """
ExDoc extension for the Earmark MarkDown parser.
ExDoc extension for the EarmarkParser Markdown parser.
"""
@behaviour ExDoc.Markdown

@doc """
Check if the Earmark Markdown parser module is available.
Check if the EarmarkParser Markdown parser module is available.
"""
def available? do
match?({:ok, _}, Application.ensure_all_started(:earmark)) and Code.ensure_loaded?(Earmark)
match?({:ok, _}, Application.ensure_all_started(:earmark_parser)) and
Code.ensure_loaded?(EarmarkParser)
end

@doc """
Expand All @@ -27,17 +28,16 @@ defmodule ExDoc.Markdown.Earmark do
"""
@impl true
def to_ast(text, opts) do
options =
struct(Earmark.Options,
gfm: Keyword.get(opts, :gfm, true),
line: Keyword.get(opts, :line, 1),
file: Keyword.get(opts, :file, "nofile"),
breaks: Keyword.get(opts, :breaks, false),
smartypants: Keyword.get(opts, :smartypants, false),
pure_links: true
)

case Earmark.as_ast(text, options) do
options = [
gfm: Keyword.get(opts, :gfm, true),
line: Keyword.get(opts, :line, 1),
file: Keyword.get(opts, :file, "nofile"),
breaks: Keyword.get(opts, :breaks, false),
smartypants: Keyword.get(opts, :smartypants, false),
pure_links: true
]

case EarmarkParser.as_ast(text, options) do
{:ok, ast, messages} ->
print_messages(messages, options)
fixup(ast)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule ExDoc.Mixfile do

defp deps do
[
{:earmark, "~> 1.4.0"},
{:earmark_parser, "~> 1.4.0"},
{:makeup_elixir, "~> 0.14"},
{:excoveralls, "~> 0.3", only: :test},
{:jason, "~> 1.2", only: :test}
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"},
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
"earmark_parser": {:hex, :earmark_parser, "1.4.8", "1a823aec32df3f9423bdea0dc1fad2c1d4e24c054f60bfce97a49c9a36903794", [:mix], [], "hexpm", "0817aeeec25706700362b4578f58e42b573605a649d350d471364d1ee4e2295d"},
"excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "493daf5a2dd92d022a1c29e7edcc30f1bce1ffe10fb3690fac63889346d3af2f"},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "c2790c9f0f7205f4a362512192dee8179097394400e745e4d20bab7226a8eaad"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
Expand Down
8 changes: 4 additions & 4 deletions test/ex_doc/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ defmodule ExDoc.AutolinkTest do
end

test "sibling function" do
assert autolink("Earmark.as_ast/2", siblings: [:earmark]) ==
~m"[`Earmark.as_ast/2`](Earmark.html#as_ast/2)"
assert autolink("EarmarkParser.as_ast/2", siblings: [:earmark_parser]) ==
~m"[`EarmarkParser.as_ast/2`](EarmarkParser.html#as_ast/2)"
end

test "auto-imported function" do
Expand Down Expand Up @@ -194,8 +194,8 @@ defmodule ExDoc.AutolinkTest do
end

test "3rd party links" do
assert autolink("Earmark.as_ast/2") ==
~m"[`Earmark.as_ast/2`](https://hexdocs.pm/earmark/Earmark.html#as_ast/2)"
assert autolink("EarmarkParser.as_ast/2") ==
~m"[`EarmarkParser.as_ast/2`](https://hexdocs.pm/earmark_parser/EarmarkParser.html#as_ast/2)"

assert_unchanged(":test_module.foo/0")
end
Expand Down
12 changes: 6 additions & 6 deletions test/mix/tasks/docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ defmodule Mix.Tasks.DocsTest do
{"ex_doc", "dev", [formatter: "epub", deps: deps, source_beam: _, app: _]}
] = run([], app: :ex_doc, docs: [])

assert List.keyfind(deps, Application.app_dir(:earmark), 0) ==
{Application.app_dir(:earmark),
"https://hexdocs.pm/earmark/#{Application.spec(:earmark, :vsn)}/"}
assert List.keyfind(deps, Application.app_dir(:earmark_parser), 0) ==
{Application.app_dir(:earmark_parser),
"https://hexdocs.pm/earmark_parser/#{Application.spec(:earmark_parser, :vsn)}/"}
end

test "allows custom dependency paths" do
assert [
{"ex_doc", "dev", [formatter: "html", deps: deps, source_beam: _, app: _]},
{"ex_doc", "dev", [formatter: "epub", deps: deps, source_beam: _, app: _]}
] = run([], app: :ex_doc, docs: [deps: [earmark: "foo"]])
] = run([], app: :ex_doc, docs: [deps: [earmark_parser: "foo"]])

assert List.keyfind(deps, Application.app_dir(:earmark), 0) ==
{Application.app_dir(:earmark), "foo"}
assert List.keyfind(deps, Application.app_dir(:earmark_parser), 0) ==
{Application.app_dir(:earmark_parser), "foo"}
end

test "accepts lazy docs" do
Expand Down