summaryrefslogtreecommitdiffstats
path: root/Utilities/Scripts/rst-block-comments.bash
blob: 864f21f3a382d7763915ab1456569531e64e3331 (plain)
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
#!/bin/bash

files="$(git ls-files Modules | grep -v ' ' | xargs grep -l '^#.rst:$')"

perl -i -e '
  use strict;
  use warnings;

  my $rst = 0;
  while (<>) {
    if ($rst) {
      if (/^# (.*)$/) {
        print "$1\n";
      } elsif (/^#$/) {
        print "\n";
      } else {
        $rst = 0;
        print "#]=======================================================================]\n";
        print $_;
      }
    } elsif (/^#\.rst:$/) {
      $rst = 1;
      print "#[=======================================================================[.rst:\n";
    } else {
      print $_;
    }

    if ($rst && eof) {
      $rst = 0;
      print "#]=======================================================================]\n";
    }
  }
' $files