Skip to content

Commit 2489f76

Browse files
committed
language-specific syntax highlighting
1 parent ee97809 commit 2489f76

File tree

31 files changed

+242
-136
lines changed

31 files changed

+242
-136
lines changed

count-bytes/perl5.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
The core `length` function returns the number of bytes when called on a byte
44
string instead of a character string.
55

6-
$count = length $utf8;
6+
```perl
7+
$count = length $utf8;
8+
```

count-bytes/perl6.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
The `bytes` method is available for buffers (`Buf` objects).
44

5-
$count = $utf8.bytes;
5+
```perl
6+
$count = $utf8.bytes;
7+
```

count-characters/javascript.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
The [Punycode.js](https://github.com/bestiejs/punycode.js) library can be used
66
to count code points.
77

8-
var puny = require('punycode');
8+
```javascript
9+
var puny = require('punycode');
910

10-
$count = puny.ucs2.decode(str).length;
11+
$count = puny.ucs2.decode(str).length;
12+
```

count-characters/perl5.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,36 @@
55
The core `length` function returns the number of code points when called on a
66
character string (instead of a byte string).
77

8-
$count = length $str;
8+
```perl
9+
$count = length $str;
10+
```
911

1012
## Grapheme clusters
1113

1214
There is no core function to count the number of grapheme clusters; however,
1315
either of the following examples will perform the task.
1416

15-
$count = () = $str =~ /\X/g;
17+
```perl
18+
$count = () = $str =~ /\X/g;
1619

17-
$count++ while $str =~ /\X/g;
20+
$count++ while $str =~ /\X/g;
21+
```
1822

1923
The CPAN module
2024
[Unicode::GCString](https://metacpan.org/module/Unicode::GCString) can also be
2125
used on character strings.
2226

23-
use Unicode::GCString;
27+
```perl
28+
use Unicode::GCString;
2429

25-
$count = Unicode::GCString->new($str)->length;
30+
$count = Unicode::GCString->new($str)->length;
31+
```
2632

2733
As well as the CPAN module
2834
[Unicode::Util](Unicode::GCStrin://metacpan.org/module/Unicode::Util).
2935

30-
use Unicode::Util qw( grapheme_length );
36+
```perl
37+
use Unicode::Util qw( grapheme_length );
3138

32-
$count = grapheme_length($str);
39+
$count = grapheme_length($str);
40+
```

count-characters/perl6.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
The `codes` method is available for strings (`Str` objects).
66

7-
$count = $str.codes;
7+
```perl
8+
$count = $str.codes;
9+
```
810

911
## Grapheme clusters
1012

1113
The `graphemes` method is available for strings (`Str` objects).
1214

13-
$count = $str.graphemes;
15+
```perl
16+
$count = $str.graphemes;
17+
```

count-characters/php.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ The `mb_strlen` function is available for strings in PHP 4.0.6 and requires the
66
encoding of the string to either passed as the second argument or set in
77
`mbstring.internal_encoding`.
88

9-
$count = mb_strlen($str, 'UTF-8');
9+
```php
10+
$count = mb_strlen($str, 'UTF-8');
11+
```
1012

1113
## Grapheme clusters
1214

1315
The `grapheme_strlen` function is available for UTF-8 strings in PHP 5.3.0 or
1416
the PECL extension [intl](http://pecl.php.net/package/intl).
1517

16-
$count = grapheme_strlen($str);
18+
```php
19+
$count = grapheme_strlen($str);
20+
```

encode-decode/perl5.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Encode and decode in Perl 5
22

3-
use Encode;
3+
```perl
4+
use Encode;
45

5-
$utf8 = encode('UTF-8', $str);
6-
$str = decode('UTF-8', $utf8);
6+
$utf8 = encode('UTF-8', $str);
7+
$str = decode('UTF-8', $utf8);
8+
```

encode-decode/perl6.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
UTF-8 is the default.
44

5-
$utf8 = $str.encode;
6-
$str = $utf8.decode;
5+
```perl
6+
$utf8 = $str.encode;
7+
$str = $utf8.decode;
8+
```
79

810
Other encodings can be explicitly specified.
911

10-
$utf16 = $str.encode('UTF-16');
11-
$str = $utf16.decode('UTF-16');
12+
```perl
13+
$utf16 = $str.encode('UTF-16');
14+
$str = $utf16.decode('UTF-16');
15+
```

io/perl5.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,37 @@ and encode on output.
99
All standard streams and filehandles. This does not include command-line
1010
arguments.
1111

12-
use open qw( :encoding(UTF-8) :std );
12+
```perl
13+
use open qw( :encoding(UTF-8) :std );
14+
```
1315

1416
Alternately, individual streams and filehandles can be handled as follows.
1517

1618
## Standard streams
1719

18-
binmode STDIN, ':encoding(UTF-8)';
19-
binmode STDOUT, ':encoding(UTF-8)';
20-
binmode STDERR, ':encoding(UTF-8)';
20+
```perl
21+
binmode STDIN, ':encoding(UTF-8)';
22+
binmode STDOUT, ':encoding(UTF-8)';
23+
binmode STDERR, ':encoding(UTF-8)';
24+
```
2125

2226
## Existing filehandles
2327

24-
binmode $fh, ':encoding(UTF-8)';
28+
```perl
29+
binmode $fh, ':encoding(UTF-8)';
30+
```
2531

2632
## New filehandles
2733

28-
open my $in_fh, '<:encoding(UTF-8)', $path;
29-
open my $out_fh, '>:encoding(UTF-8)', $path;
34+
```perl
35+
open my $in_fh, '<:encoding(UTF-8)', $path;
36+
open my $out_fh, '>:encoding(UTF-8)', $path;
37+
```
3038

3139
## Command-line arguments
3240

33-
use Encode;
41+
```perl
42+
use Encode;
3443

35-
@args = map { decode('UTF-8', $_) } @ARGV;
44+
@args = map { decode('UTF-8', $_) } @ARGV;
45+
```

io/perl6.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ follows.
66

77
## Standard streams
88

9-
$*IN.encoding = 'UTF-16';
10-
$*OUT.encoding = 'UTF-16';
11-
$*ERR.encoding = 'UTF-16';
9+
```perl
10+
$*IN.encoding = 'UTF-16';
11+
$*OUT.encoding = 'UTF-16';
12+
$*ERR.encoding = 'UTF-16';
13+
```
1214

1315
## Existing filehandles
1416

15-
$fh.encoding = 'UTF-16';
17+
```perl
18+
$fh.encoding = 'UTF-16';
19+
```
1620

1721
## New filehandles
1822

19-
my $in_fh = open $path, :r, :enc<UTF-16>;
20-
my $out_fh = open $path, :w, :enc<UTF-16>;
23+
```perl
24+
my $in_fh = open $path, :r, :enc<UTF-16>;
25+
my $out_fh = open $path, :w, :enc<UTF-16>;
26+
```

0 commit comments

Comments
 (0)