Skip to content

Commit 41e24c2

Browse files
amomchilovhsbt
authored andcommitted
[ruby/strscan] [DOC] Add syntax highlighting to MarkDown code blocks
(ruby/strscan#126) Split off from ruby#12322 ruby/strscan@9bee37e0f5
1 parent 219c2ee commit 41e24c2

File tree

13 files changed

+74
-78
lines changed

13 files changed

+74
-78
lines changed

doc/strscan/helper_methods.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Display scanner's situation:
1010
- Character position (`#charpos`)
1111
- Target string (`#rest`) and size (`#rest_size`).
1212

13-
```
13+
```rb
1414
scanner = StringScanner.new('foobarbaz')
1515
scanner.scan(/foo/)
1616
put_situation(scanner)
@@ -25,7 +25,7 @@ put_situation(scanner)
2525

2626
Display the scanner's match values:
2727

28-
```
28+
```rb
2929
scanner = StringScanner.new('Fri Dec 12 1975 14:39')
3030
pattern = /(?<wday>\w+) (?<month>\w+) (?<day>\d+) /
3131
scanner.match?(pattern)
@@ -53,7 +53,7 @@ put_match_values(scanner)
5353

5454
Returns whether the scanner's match values are all properly cleared:
5555

56-
```
56+
```rb
5757
scanner = StringScanner.new('foobarbaz')
5858
match_values_cleared?(scanner) # => true
5959
put_match_values(scanner)
@@ -75,17 +75,15 @@ match_values_cleared?(scanner) # => false
7575

7676
## The Code
7777

78-
```
78+
```rb
7979
def put_situation(scanner)
8080
puts '# Situation:'
8181
puts "# pos: #{scanner.pos}"
8282
puts "# charpos: #{scanner.charpos}"
8383
puts "# rest: #{scanner.rest.inspect}"
8484
puts "# rest_size: #{scanner.rest_size}"
8585
end
86-
```
8786

88-
```
8987
def put_match_values(scanner)
9088
puts '# Basic match values:'
9189
puts "# matched?: #{scanner.matched?}"
@@ -109,9 +107,7 @@ def put_match_values(scanner)
109107
end
110108
end
111109
end
112-
```
113110

114-
```
115111
def match_values_cleared?(scanner)
116112
scanner.matched? == false &&
117113
scanner.matched_size.nil? &&

doc/strscan/methods/get_byte.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Returns the next byte, if available:
1010
- Increments the [byte position][2].
1111
- Adjusts the [character position][7].
1212

13-
```
13+
```rb
1414
scanner = StringScanner.new(HIRAGANA_TEXT)
1515
# => #<StringScanner 0/15 @ "\xE3\x81\x93\xE3\x82...">
1616
scanner.string # => "こんにちは"
@@ -24,7 +24,7 @@ Returns the next byte, if available:
2424

2525
- Otherwise, returns `nil`, and does not change the positions.
2626

27-
```
27+
```rb
2828
scanner.terminate
2929
[scanner.get_byte, scanner.pos, scanner.charpos] # => [nil, 15, 5]
3030
```

doc/strscan/methods/get_charpos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Returns the [character position][7] (initially zero),
55
which may be different from the [byte position][2]
66
given by method #pos:
77

8-
```
8+
```rb
99
scanner = StringScanner.new(HIRAGANA_TEXT)
1010
scanner.string # => "こんにちは"
1111
scanner.getch # => "こ" # 3-byte character.

doc/strscan/methods/get_pos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ call-seq:
44
Returns the integer [byte position][2],
55
which may be different from the [character position][7]:
66

7-
```
7+
```rb
88
scanner = StringScanner.new(HIRAGANA_TEXT)
99
scanner.string # => "こんにちは"
1010
scanner.pos # => 0

doc/strscan/methods/getch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if available:
1212
- Increments the [byte position][2]
1313
by the size (in bytes) of the character.
1414

15-
```
15+
```rb
1616
scanner = StringScanner.new(HIRAGANA_TEXT)
1717
scanner.string # => "こんにちは"
1818
[scanner.getch, scanner.pos, scanner.charpos] # => ["こ", 3, 1]
@@ -27,7 +27,7 @@ if available:
2727
(that is, not at its beginning),
2828
behaves like #get_byte (returns a 1-byte character):
2929

30-
```
30+
```rb
3131
scanner.pos = 1
3232
[scanner.getch, scanner.pos, scanner.charpos] # => ["\x81", 2, 2]
3333
[scanner.getch, scanner.pos, scanner.charpos] # => ["\x93", 3, 1]
@@ -37,7 +37,7 @@ if available:
3737
- If the [position][2] is at the end of the [stored string][1],
3838
returns `nil` and does not modify the positions:
3939

40-
```
40+
```rb
4141
scanner.terminate
4242
[scanner.getch, scanner.pos, scanner.charpos] # => [nil, 15, 5]
4343
```

doc/strscan/methods/scan.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If the match succeeds:
1111
and may increment the [character position][7].
1212
- Sets [match values][9].
1313

14-
```
14+
```rb
1515
scanner = StringScanner.new(HIRAGANA_TEXT)
1616
scanner.string # => "こんにちは"
1717
scanner.pos = 6
@@ -45,7 +45,7 @@ If the match fails:
4545
- Does not increment byte and character positions.
4646
- Clears match values.
4747

48-
```
48+
```rb
4949
scanner.scan(/nope/) # => nil
5050
match_values_cleared?(scanner) # => true
5151
```

doc/strscan/methods/scan_until.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If the match attempt succeeds:
1212
- Returns the matched substring.
1313

1414

15-
```
15+
```rb
1616
scanner = StringScanner.new(HIRAGANA_TEXT)
1717
scanner.string # => "こんにちは"
1818
scanner.pos = 6
@@ -46,7 +46,7 @@ If the match attempt fails:
4646
- Returns `nil`.
4747
- Does not update positions.
4848

49-
```
49+
```rb
5050
scanner.scan_until(/nope/) # => nil
5151
match_values_cleared?(scanner) # => true
5252
```

doc/strscan/methods/set_pos.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Does not affect [match values][9].
99

1010
For non-negative `n`, sets the position to `n`:
1111

12-
```
12+
```rb
1313
scanner = StringScanner.new(HIRAGANA_TEXT)
1414
scanner.string # => "こんにちは"
1515
scanner.pos = 3 # => 3
@@ -19,7 +19,7 @@ scanner.charpos # => 1
1919

2020
For negative `n`, counts from the end of the [stored string][1]:
2121

22-
```
22+
```rb
2323
scanner.pos = -9 # => -9
2424
scanner.pos # => 6
2525
scanner.rest # => "にちは"

doc/strscan/methods/skip.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If the match succeeds:
1111
- Sets [match values][9].
1212
- Returns the size (bytes) of the matched substring.
1313

14-
```
14+
```rb
1515
scanner = StringScanner.new(HIRAGANA_TEXT)
1616
scanner.string # => "こんにちは"
1717
scanner.pos = 6

doc/strscan/methods/skip_until.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If the match attempt succeeds:
1010
- Sets [match values][9].
1111
- Returns the size of the matched substring.
1212

13-
```
13+
```rb
1414
scanner = StringScanner.new(HIRAGANA_TEXT)
1515
scanner.string # => "こんにちは"
1616
scanner.pos = 6
@@ -43,7 +43,7 @@ If the match attempt fails:
4343
- Clears match values.
4444
- Returns `nil`.
4545

46-
```
46+
```rb
4747
scanner.skip_until(/nope/) # => nil
4848
match_values_cleared?(scanner) # => true
4949
```

0 commit comments

Comments
 (0)