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

Set up MarkdownCodeBlockFormatter #1419

Merged
merged 5 commits into from
Jan 22, 2024
Merged

Conversation

angelikatyborska
Copy link
Member

I wrote an Elixir formatter plugin that is able to format Elixir code in Markdown files. @jiegillet @neenjaw what do you think?

(I'll publish it to hex before merging)

Copy link
Contributor

Thank you for contributing to exercism/elixir 💜 🎉. This is an automated PR comment 🤖 for the maintainers of this repository that helps with the PR review process. You can safely ignore it and wait for a maintainer to review your changes.

Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:

  • General steps

    • 🏆 Does this PR need to receive a label with a reputation modifier (x:size/{tiny,small,medium,large,massive})? (A medium reputation amount is awarded by default, see docs)
  • Any exercise changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <exercise>/.meta/config.json (see docs)?
    • 🔬 Do the analyzer and the analyzer comments exist for this exercise? Do they need to be changed?
    • 📜 Does the design file (<exercise>/.meta/design.md) need to be updated to document new implementation decisions?
  • Practice exercise changed

    • 🌲 Do prerequisites, practices, and difficulty in config.json need to be updated?
    • 🧑‍🏫 Are the changes in accordance with the community-wide problem specifiations?
  • Concept exercise changed

    • 🌲 Do prerequisites and practices in config.json need to be updated?
    • 📖 Does the concept introduction provide all necessary information to solve this exercise?
  • Concept changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <concept>/.meta/config.json (see docs)?
    • 📖 Does the concept introduction provide all necessary information to solve this exercise?

Automated comment created by PR Commenter 🤖.

@@ -173,7 +176,7 @@ and Erlang types. To create a plt with sensible defaults run:
$ mix dialyzer --plt
```

Finally it can be run with:
Finally, it can be run with:
Copy link
Member Author

Choose a reason for hiding this comment

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

Not a formatter feature 😛

@@ -59,6 +61,8 @@ if age >= 16, do: "beer", else: "no beer"

This may look like `if` accepts two arguments, but the `do:` and `else:` pair is actually a single argument - a keyword list. The same code could be written as:

[]: # (elixir-formatter-disable-next-block)
Copy link
Member Author

Choose a reason for hiding this comment

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

Where desired, formatting can be turned off. For example here we want to show off a non-standard way to format this code to prove a point.

mix.lock Outdated Show resolved Hide resolved
Copy link
Contributor

@neenjaw neenjaw left a comment

Choose a reason for hiding this comment

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

Nice, this looks pretty good!

My only thought is I don't know what is standard in the markdown standard for those formatter directives to ignore some blocks. But it works for me!

@angelikatyborska
Copy link
Member Author

angelikatyborska commented Jan 20, 2024

Part of the problem is that there is no one Markdown standard 😞 This syntax:

[]: # (elixir-formatter-disable-next-block)

It's an abused reference-style link. More generically, it's:

[reference-name]: https://example.com (Some link title)

Now, I don't know if all Markdown implementations support reference-style links, but Exercism definitely depends on them. I'm pretty sure that # must be a valid link href, and elixir-formatter-disable-next-block is a valid link title. The only thing I'm unsure about is an empty reference name. I didn't see any problems so far. It could also be non-empty (could be anything), but configlet generate moves all non-empty link references to the bottom of the markdown file which messes up with my intended use 😁

Copy link
Contributor

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

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

Outstanding! I love formatters :)

I left a couple of questions.

@@ -46,7 +49,8 @@ We can achieve the same result by prepending an element to the reversed list, an
[1, 2, 3] ++ [4] ++ [5] ++ [6]

# Prepend to the start of a list (faster, due to the nature of linked lists)
[6 | [5 | [4 | [3, 2, 1]]]] # then reverse!
[6 | [5 | [4 | [3, 2, 1]]]]
# then reverse!
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this comment go at the bottom?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved it manually because the "reverse" part is not part of this code. The code only shows list creation, and then it's implied that you need to reverse later. Hence the comment should be last.

@@ -27,7 +27,7 @@ However, if `left` is *false*, `right` has to be evaluated to determine the outc

Another thing to consider when using Boolean operators is their precedence.
```elixir
true or false and false
true or (false and false)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a specific point about what this evaluate to just below, maybe those shouldn't be formatted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well spotted

@angelikatyborska angelikatyborska merged commit 4df8276 into main Jan 22, 2024
10 checks passed
@angelikatyborska angelikatyborska deleted the markdown-code-block-formatter branch January 22, 2024 17:40
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.

3 participants