Skip to content

Commit 430e45b

Browse files
Format admonitions (#2327)
Format admonitions to adhere to Exercism standards (four tildes)
1 parent 988eafc commit 430e45b

File tree

14 files changed

+35
-25
lines changed

14 files changed

+35
-25
lines changed

.github/workflows/action-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
run: yarn format-json && ruby bin/format-array.rb
9191

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

9595
- name: 'Commit formatted code'
9696
run: |

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ jobs:
134134

135135
- name: Verify that markdown files are formatted correctly
136136
run: |
137-
yarn format-md
137+
yarn format-md && ruby bin/format-admonition-fences.rb
138138
if ! git diff --quiet --exit-code; then
139-
echo "please format the files with prettier, or apply the following changes:"
139+
echo "please format the files using 'yarn format-md && ruby bin/format-admonition-fences.rb', or apply the following changes:"
140140
git diff
141141
exit 1
142142
fi

bin/format-admonition-fences.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env ruby
2+
3+
BACKTICK_MATCH_REGEX = /(?<fence>[`~]{3,})(?<type>exercism\/[a-z]+)(?<admonition>.*?)(?<end>\k<fence>)/m.freeze
4+
TILDE_REPLACE = '~~~~\k<type>\k<admonition>~~~~'.freeze
5+
6+
Dir.glob('exercises/**/*.md') do |filepath|
7+
contents = File.read(filepath)
8+
contents.gsub!(BACKTICK_MATCH_REGEX, TILDE_REPLACE)
9+
File.write(filepath, contents)
10+
end

exercises/binary-search/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Your task is to implement a binary search algorithm.
55
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.
66
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.
77

8-
```exercism/caution
8+
~~~~exercism/caution
99
Binary search only works when a list has been sorted.
10-
```
10+
~~~~
1111

1212
The algorithm looks like this:
1313

exercises/etl/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ This needs to be changed to store each individual letter with its score in a one
2222

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

25-
```exercism/note
25+
~~~~exercism/note
2626
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.
27-
```
27+
~~~~

exercises/gigasecond/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Then we can use metric system prefixes for writing large numbers of seconds in m
1313
- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds).
1414
- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary.
1515

16-
```exercism/note
16+
~~~~exercism/note
1717
If we ever colonize Mars or some other planet, measuring time is going to get even messier.
1818
If someone says "year" do they mean a year on Earth or a year on Mars?
1919
2020
The idea for this exercise came from the science fiction novel ["A Deepness in the Sky"][vinge-novel] by author Vernor Vinge.
2121
In it the author uses the metric system as the basis for time measurements.
2222
2323
[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/
24-
```
24+
~~~~

exercises/linked-list/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Sometimes a station gets closed down, and in that case the station needs to be r
1313

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

16-
```exercism/note
16+
~~~~exercism/note
1717
The linked list is a fundamental data structure in computer science, often used in the implementation of other data structures.
1818
As the name suggests, it is a list of nodes that are linked together.
1919
It is a list of "nodes", where each node links to its neighbor or neighbors.
@@ -23,4 +23,4 @@ In a **doubly linked list** each node links to both the node that comes before,
2323
If you want to dig deeper into linked lists, check out [this article][intro-linked-list] that explains it using nice drawings.
2424
2525
[intro-linked-list]: https://medium.com/basecs/whats-a-linked-list-anyway-part-1-d8b7e6508b9d
26-
```
26+
~~~~

exercises/pangram/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ To give a comprehensive sense of the font, the random sentences should use **all
77
They're running a competition to get suggestions for sentences that they can use.
88
You're in charge of checking the submissions to see if they are valid.
99

10-
```exercism/note
10+
~~~~exercism/note
1111
Pangram comes from Greek, παν γράμμα, pan gramma, which means "every letter".
1212
1313
The best known English pangram is:
1414
1515
> The quick brown fox jumps over the lazy dog.
16-
```
16+
~~~~

exercises/rational-numbers/description.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

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

5-
```exercism/note
5+
~~~~exercism/note
66
Note that mathematically, the denominator can't be zero.
77
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.
88
In those cases, the denominator and numerator generally still can't both be zero at once.
9-
```
9+
~~~~
1010

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

exercises/rna-transcription/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Given a DNA strand, its transcribed RNA strand is formed by replacing each nucle
1515
- `T` -> `A`
1616
- `A` -> `U`
1717

18-
```exercism/note
18+
~~~~exercism/note
1919
If you want to look at how the inputs and outputs are structured, take a look at the examples in the test suite.
20-
```
20+
~~~~

0 commit comments

Comments
 (0)