about summary refs log tree commit diff
path: root/doc/pages/demo/pygments/index.xml
blob: 361c6abeba8d31af1baf404f81f4e40ba4032640 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<page xmlns="https://rub.parody">
<title>Pygments demo</title>
<description>Code snippets to demonstrate syntax highlighting</description>
<date>2022-12-26</date>
<category>demo</category>
<category>aoc</category>
<markdown>
Syntax highlighting for D using Pygments:

<highlight lang="d"><![CDATA[
import core.stdc.stdio : getchar, printf;

extern(C) void main()
{
    slide: for (auto q = 0u, i = 1u; q & 0xffu ^ '\n'; ++i)
    {
        q <<= 8u;
        q |= getchar();
        if (i < 4)
            continue;

        auto p = cast(ubyte*) &q;
        for (auto s = 0u, j = 0u; j < 4u; ++j)
        {
            auto b = 1u << (p[j] & 0x1fu);
            if (s & b)
                continue slide;
            s |= b;
        }

        printf("%d\n", i);
        break;
    }
}
]]></highlight>

The same but let Pygments guess the language:

<highlight><![CDATA[
import core.stdc.stdio : getchar, printf;

extern(C) void main()
{
    slide: for (auto q = 0u, i = 1u; q & 0xffu ^ '\n'; ++i)
    {
        q <<= 8u;
        q |= getchar();
        if (i < 4)
            continue;

        auto p = cast(ubyte*) &q;
        for (auto s = 0u, j = 0u; j < 4u; ++j)
        {
            auto b = 1u << (p[j] & 0x1fu);
            if (s & b)
                continue slide;
            s |= b;
        }

        printf("%d\n", i);
        break;
    }
}
]]></highlight>
</markdown>
</page>