Skip to content

Commit

Permalink
Format admonitions (#2327)
Browse files Browse the repository at this point in the history
Format admonitions to adhere to Exercism standards (four tildes)
  • Loading branch information
ErikSchierboom authored Sep 27, 2023
1 parent 988eafc commit 430e45b
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
run: yarn format-json && ruby bin/format-array.rb

- name: Format Markdown files
run: yarn format-md
run: yarn format-md && ruby bin/format-admonition-fences.rb

- name: 'Commit formatted code'
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ jobs:

- name: Verify that markdown files are formatted correctly
run: |
yarn format-md
yarn format-md && ruby bin/format-admonition-fences.rb
if ! git diff --quiet --exit-code; then
echo "please format the files with prettier, or apply the following changes:"
echo "please format the files using 'yarn format-md && ruby bin/format-admonition-fences.rb', or apply the following changes:"
git diff
exit 1
fi
Expand Down
10 changes: 10 additions & 0 deletions bin/format-admonition-fences.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby

BACKTICK_MATCH_REGEX = /(?<fence>[`~]{3,})(?<type>exercism\/[a-z]+)(?<admonition>.*?)(?<end>\k<fence>)/m.freeze
TILDE_REPLACE = '~~~~\k<type>\k<admonition>~~~~'.freeze

Dir.glob('exercises/**/*.md') do |filepath|
contents = File.read(filepath)
contents.gsub!(BACKTICK_MATCH_REGEX, TILDE_REPLACE)
File.write(filepath, contents)
end
4 changes: 2 additions & 2 deletions exercises/binary-search/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Your task is to implement a binary search algorithm.
A binary search algorithm finds an item in a list by repeatedly splitting it in half, only keeping the half which contains the item we're looking for.
It allows us to quickly narrow down the possible locations of our item until we find it, or until we've eliminated all possible locations.

```exercism/caution
~~~~exercism/caution
Binary search only works when a list has been sorted.
```
~~~~

The algorithm looks like this:

Expand Down
4 changes: 2 additions & 2 deletions exercises/etl/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ This needs to be changed to store each individual letter with its score in a one

As part of this change, the team has also decided to change the letters to be lower-case rather than upper-case.

```exercism/note
~~~~exercism/note
If you want to look at how the data was previously structured and how it needs to change, take a look at the examples in the test suite.
```
~~~~
4 changes: 2 additions & 2 deletions exercises/gigasecond/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Then we can use metric system prefixes for writing large numbers of seconds in m
- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds).
- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary.

```exercism/note
~~~~exercism/note
If we ever colonize Mars or some other planet, measuring time is going to get even messier.
If someone says "year" do they mean a year on Earth or a year on Mars?
The idea for this exercise came from the science fiction novel ["A Deepness in the Sky"][vinge-novel] by author Vernor Vinge.
In it the author uses the metric system as the basis for time measurements.
[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/
```
~~~~
4 changes: 2 additions & 2 deletions exercises/linked-list/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Sometimes a station gets closed down, and in that case the station needs to be r

The size of a route is measured not by how far the train travels, but by how many stations it stops at.

```exercism/note
~~~~exercism/note
The linked list is a fundamental data structure in computer science, often used in the implementation of other data structures.
As the name suggests, it is a list of nodes that are linked together.
It is a list of "nodes", where each node links to its neighbor or neighbors.
Expand All @@ -23,4 +23,4 @@ In a **doubly linked list** each node links to both the node that comes before,
If you want to dig deeper into linked lists, check out [this article][intro-linked-list] that explains it using nice drawings.
[intro-linked-list]: https://medium.com/basecs/whats-a-linked-list-anyway-part-1-d8b7e6508b9d
```
~~~~
4 changes: 2 additions & 2 deletions exercises/pangram/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ To give a comprehensive sense of the font, the random sentences should use **all
They're running a competition to get suggestions for sentences that they can use.
You're in charge of checking the submissions to see if they are valid.

```exercism/note
~~~~exercism/note
Pangram comes from Greek, παν γράμμα, pan gramma, which means "every letter".
The best known English pangram is:
> The quick brown fox jumps over the lazy dog.
```
~~~~
4 changes: 2 additions & 2 deletions exercises/rational-numbers/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

A rational number is defined as the quotient of two integers `a` and `b`, called the numerator and denominator, respectively, where `b != 0`.

```exercism/note
~~~~exercism/note
Note that mathematically, the denominator can't be zero.
However in many implementations of rational numbers, you will find that the denominator is allowed to be zero with behaviour similar to positive or negative infinity in floating point numbers.
In those cases, the denominator and numerator generally still can't both be zero at once.
```
~~~~

The absolute value `|r|` of the rational number `r = a/b` is equal to `|a|/|b|`.

Expand Down
4 changes: 2 additions & 2 deletions exercises/rna-transcription/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Given a DNA strand, its transcribed RNA strand is formed by replacing each nucle
- `T` -> `A`
- `A` -> `U`

```exercism/note
~~~~exercism/note
If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite.
```
~~~~
4 changes: 2 additions & 2 deletions exercises/rna-transcription/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You work for a bioengineering company that specializes in developing therapeutic

Your team has just been given a new project to develop a targeted therapy for a rare type of cancer.

```exercism/note
~~~~exercism/note
It's all very complicated, but the basic idea is that sometimes people's bodies produce too much of a given protein.
That can cause all sorts of havoc.
Expand All @@ -13,4 +13,4 @@ But if you can create a very specific molecule (called a micro-RNA), it can prev
This technique is called [RNA Interference][rnai].
[rnai]: https://admin.acceleratingscience.com/ask-a-scientist/what-is-rnai/
```
~~~~
4 changes: 2 additions & 2 deletions exercises/secret-handshake/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ The secret handshake for 26 is therefore:
jump, double blink
```

```exercism/note
~~~~exercism/note
If you aren't sure what binary is or how it works, check out [this binary tutorial][intro-to-binary].
[intro-to-binary]: https://medium.com/basecs/bits-bytes-building-with-binary-13cb4289aafa
```
~~~~
4 changes: 2 additions & 2 deletions exercises/sieve/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Then you repeat the following steps:
You keep repeating these steps until you've gone through every number in your list.
At the end, all the unmarked numbers are prime.

```exercism/note
~~~~exercism/note
[Wikipedia's Sieve of Eratosthenes article][eratosthenes] has a useful graphic that explains the algorithm.
The tests don't check that you've implemented the algorithm, only that you've come up with the correct list of primes.
A good first test is to check that you do not use division or remainder operations.
[eratosthenes]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
```
~~~~
4 changes: 2 additions & 2 deletions exercises/simple-linked-list/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Given a range of numbers (the song IDs), create a singly linked list.

Given a singly linked list, you should be able to reverse the list to play the songs in the opposite order.

```exercism/note
~~~~exercism/note
The linked list is a fundamental data structure in computer science, often used in the implementation of other data structures.
The simplest kind of linked list is a **singly** linked list.
Expand All @@ -16,4 +16,4 @@ That means that each element (or "node") contains data, along with something tha
If you want to dig deeper into linked lists, check out [this article][intro-linked-list] that explains it using nice drawings.
[intro-linked-list]: https://medium.com/basecs/whats-a-linked-list-anyway-part-1-d8b7e6508b9d
```
~~~~

0 comments on commit 430e45b

Please sign in to comment.