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

I438 implement smartypants #439

Merged
merged 3 commits into from
Oct 30, 2021
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
8 changes: 7 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# 1.4.17 2021-10-27
## 1.4.18 2021-10-30

- [Remove SmartyPants option for Parser](https://github.com/robertdober/earmark_parser/issues/438)

- Updated dependency to [EarmarkParser v1.4.17](https://github.com/RobertDober/earmark_parser/blob/v1.4.17/RELEASE.md)

## 1.4.17 2021-10-27

- [436 Better EEx integration into CLI with recursive includes of markdown files](https://github.com/pragdave/earmark/pull/436)

Expand Down
5 changes: 3 additions & 2 deletions lib/earmark.ex
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ defmodule Earmark do
"""

alias Earmark.{Internal, Options, Transform}
alias Earmark.EarmarkParserProxy, as: Proxy

defdelegate as_ast!(markdown, options \\ []), to: Internal
defdelegate as_html(lines, options \\ []), to: Internal
Expand Down Expand Up @@ -265,11 +266,11 @@ defmodule Earmark do
defp _as_ast(lines, options)

defp _as_ast(lines, %Options{} = options) do
EarmarkParser.as_ast(lines, options |> Map.delete(:__struct__) |> Enum.into([]))
Proxy.as_ast(lines, options |> Map.delete(:__struct__) |> Enum.into([]))
end

defp _as_ast(lines, options) do
EarmarkParser.as_ast(lines, options)
Proxy.as_ast(lines, options)
end
end
# SPDX-License-Identifier: Apache-2.0
26 changes: 26 additions & 0 deletions lib/earmark/earmark_parser_proxy.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule Earmark.EarmarkParserProxy do
@moduledoc ~S"""
This acts as a proxy to adapt to changes in `EarmarkParser`'s API

If no changes are needed it can delegate `as_ast` to `EarmarkParser`

If changes are needed they will be realised in this modules `as_ast`
function.

For that reason `EarmarkParser.as_ast/*` **SHALL NOT** be invoked
anywhere else in this code base
"""

@doc ~S"""
An adapter to `EarmarkParser.as_ast/*`
"""
def as_ast(input, options)
def as_ast(input, options) when is_list(options) do
EarmarkParser.as_ast(input, Keyword.delete(options, :smartypants))
end
def as_ast(input, options) when is_map(options) do
EarmarkParser.as_ast(input, Map.delete(options, :smartypants))
end

end
# SPDX-License-Identifier: Apache-2.0
3 changes: 2 additions & 1 deletion lib/earmark/internal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Earmark.Internal do
"""

alias Earmark.{Error, Message, Options, SysInterface, Transform}
alias Earmark.EarmarkParserProxy, as: Proxy
import Message, only: [emit_messages: 2]

@doc ~S"""
Expand All @@ -21,7 +22,7 @@ defmodule Earmark.Internal do
"""
def as_ast!(markdown, options \\ [])
def as_ast!(markdown, options) do
case EarmarkParser.as_ast(markdown, options) do
case Proxy.as_ast(markdown, options) do
{:ok, result, _} -> result
{:error, _, messages} -> raise Earmark.Error, inspect(messages)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/earmark/options.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ defmodule Earmark.Options do
- `eex`: Allows usage of an `EEx` template to be expanded to markdown before conversion
- `file`: Name of file passed in from the CLI
- `line`: 1 but might be set to an offset for better error messages in some integration cases
- `smartypants`: boolean use [Smarty Pants](https://daringfireball.net/projects/smartypants/) in the output
- `ignore_strings`, `postprocessor` and `registered_processors`: processors that modify the AST returned from

EarmarkParser.as_ast/`2` before rendering (`post` because preprocessing is done on the markdown, e.g. `eex`)
Refer to the moduledoc of Earmark.`Transform` for details

Expand Down
5 changes: 3 additions & 2 deletions lib/earmark/transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

alias Earmark.Options
alias Earmark.TagSpecificProcessors, as: TSP
alias Earmark.EarmarkParserProxy, as: Proxy

@compact_tags ~w[a code em strong del]

Expand Down Expand Up @@ -183,9 +184,9 @@
def postprocessed_ast(lines, options) when is_binary(lines), do: lines |> String.split(@line_end) |> postprocessed_ast(options)
# This is an optimisation (buuuuuh) but we want a minimal impact of postprocessing code when it is not required
# It is also a case of the mantra "Handle the simple case first" (yeeeeah)
def postprocessed_ast(lines, %Options{registered_processors: [], postprocessor: nil}=options), do: EarmarkParser.as_ast(lines, options)
def postprocessed_ast(lines, %Options{registered_processors: [], postprocessor: nil}=options), do: Proxy.as_ast(lines, options)
def postprocessed_ast(lines, %Options{}=options) do
{status, ast, messages} = EarmarkParser.as_ast(lines, options)
{status, ast, messages} = Proxy.as_ast(lines, options)
prep = make_postprocessor(options)
ast1 = map_ast(ast, prep, Map.get(options, :ignore_strings))
{status, ast1, messages}
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule Earmark.Mixfile do
use Mix.Project

@version "1.4.17"
@version "1.4.18"

@url "https://github.com/pragdave/earmark"


@deps [
{:earmark_parser, ">= 1.4.16"},
{:earmark_parser, ">= 1.4.17"},
{:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false},
{:benchfella, "~> 0.3.0", only: [:dev]},
{:earmark_ast_dsl, "~> 0.2.5", only: [:test]},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_ast_dsl": {:hex, :earmark_ast_dsl, "0.2.5", "e44146944eebe83b33e3597da27fb9b37af7287c55e8cc3bd014cfcd5e57c355", [:mix], [], "hexpm", "da14595fcc283fa8d3ada8adb0b934cab791917b82cc5149cc4c404545cdc2b1"},
"earmark_parser": {:hex, :earmark_parser, "1.4.16", "607709303e1d4e3e02f1444df0c821529af1c03b8578dfc81bb9cf64553d02b9", [:mix], [], "hexpm", "69fcf696168f5a274dd012e3e305027010658b2d1630cef68421d6baaeaccead"},
"earmark_parser": {:hex, :earmark_parser, "1.4.17", "6f3c7e94170377ba45241d394389e800fb15adc5de51d0a3cd52ae766aafd63f", [:mix], [], "hexpm", "f93ac89c9feca61c165b264b5837bf82344d13bebc634cd575cb711e2e342023"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"},
"extractly": {:hex, :extractly, "0.5.3", "ca6afc3430e63cc9017d50eb03bdf1a3499c7e888037d2279b0ec0ea393af390", [:mix], [], "hexpm", "858f7a285ffb767937e75bb8866f03fecb3b7e5b42728a9677d2ebb6ea885503"},
Expand Down
14 changes: 0 additions & 14 deletions test/acceptance/parser_api_test.exs

This file was deleted.