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

Add support for custom markdown parsers #28

Merged
merged 7 commits into from
Jul 18, 2023
Merged

Add support for custom markdown parsers #28

merged 7 commits into from
Jul 18, 2023

Conversation

adriansalamon
Copy link
Contributor

Use case: I want to use a custom markdown parser (md) instead of Earmark, in order to use my own markdown format with support for HEEx inside of markdown.

Example usage:

  use NimblePublisher,
    ...
    markdown_parser: MarkdownParser,

defmodule MarkdownParser do
  def parse(body) do
     "<p>This is a custom markdown parser :)</p>\n"
  end
end

@josevalim
Copy link
Member

What if we call it html_converter? This could put us in a path to support other formats beyond markdown in the future. Also, should we pass the filename as argument? I can see matching on the extension being useful?

@josevalim
Copy link
Member

Actually, we should make it the same API as the convert_body function. Receive the extension, body, and opts.

@adriansalamon
Copy link
Contributor Author

Actually, we should make it the same API as the convert_body function. Receive the extension, body, and opts.

👍 This makes sense, since then users would be free to define what files to process without having to change the lib. Eg. maybe they want to use .mdx files or similar.

README.md Outdated
end

defp highlight(html, []), do: html
defp highlight(html, _), do: NimblePublisher.Highlighter.highlight(html)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky. This is private API we would need to expose it but I am not sure if we should. In particular, I am not sure if the regex it uses would match other engines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I did a basic test with md and the regex worked, but as you said there is no guarantee that it should work. Because this is a "custom" option, if using a engine which it is not compatible with, you can always implement your own highlighting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but how do you feel if you have to implement that module yourself? Maybe we make the Regex an argument to the highlight function and make it public?

README.md Outdated Show resolved Hide resolved
Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is looking great. I have suggested some nitpicks on the option name and API. :)

Comment on lines 69 to 72
for highlighter <- highlighters do
Application.ensure_all_started(highlighter)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we need this code? We already start all highlighters before, on __extract__, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone calls this function without having called use NimblePublisher ...?

@josevalim josevalim merged commit 2a93095 into dashbitco:master Jul 18, 2023
0 of 2 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@adriansalamon adriansalamon deleted the custom-md-parsers branch July 19, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants