From 72ebc18f45cd3e96f2208ca494615b09fce5df63 Mon Sep 17 00:00:00 2001
From: Lubomir Prda <lubomir.prda@vsb.cz>
Date: Thu, 26 Jan 2017 08:56:25 +0100
Subject: [PATCH] Created script for header capitalization

---
 .gitlab-ci.yml          |  7 ++++++
 scripts/titlemd.py      | 40 +++++++++++++++++++++++++++++++++
 scripts/titlemd_test.py | 50 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+)
 create mode 100755 scripts/titlemd.py
 create mode 100755 scripts/titlemd_test.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 91877db56..25167bd3e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,6 +19,13 @@ two spaces:
   - echo "== Files having more than one space betwee two characters =="
   - find docs.it4i/ -name '*.md' -exec grep "[[:alpha:]]  [[:alpha:]]" -l {} +
 
+capitalize:
+  stage: test
+  image: davidhrbac/docker-mkdocscheck:latest
+  allow_failure: true
+  script:
+  - find docs.it4i/ -name '*.md' -print0 | xargs -0 -n1 scripts/titlemd_test.py
+
 spell check:
   stage: test
   image: davidhrbac/docker-npmcheck:latest
diff --git a/scripts/titlemd.py b/scripts/titlemd.py
new file mode 100755
index 000000000..905a67d2a
--- /dev/null
+++ b/scripts/titlemd.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import fnmatch
+import os
+import sys
+
+try:
+  from titlecase import titlecase
+except ImportError:
+  print("Please install titlecase")
+
+def main(location):
+      # Open the file and read the lines as a list
+      with open(location) as f:
+          lines = f.readlines()
+
+      with open(location, 'w') as f:
+          # Loop through the list of lines and titlecase
+          # any line beginning with '#'.
+          prev_line = lines.pop(0)
+          disabled = 0
+          for line in lines:
+              if line.startswith("``") and disabled == 0:
+                  disabled = 1
+              else:
+                  if line.startswith("``") and disabled == 1:
+                      disabled = 0
+              if line.startswith('#') and disabled == 0:
+                  line = titlecase(line[:(line.find("]"))])+line[(line.find("]")):] 
+              if line.startswith('---') or line.startswith('==='):
+                  prev_line = titlecase(prev_line[:(prev_line.find("]"))])+prev_line[(prev_line.find("]")):]
+              f.write(prev_line)
+              prev_line = line
+          f.write(prev_line)
+
+if __name__ == "__main__":
+  try:
+      main(sys.argv[1])
+  except IndexError:
+      main('.')
diff --git a/scripts/titlemd_test.py b/scripts/titlemd_test.py
new file mode 100755
index 000000000..d89f21446
--- /dev/null
+++ b/scripts/titlemd_test.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+from __future__ import print_function
+
+import fnmatch
+import os
+import sys
+
+try:
+  from titlecase import titlecase
+except ImportError:
+  print("Please install titlecase")
+
+def main(location):
+      # Open the file and read the lines as a list
+      with open(location) as f:
+          lines = f.readlines()
+
+      # Loop through the list of lines and titlecase
+      # any line beginning with '#'.
+      return_value = 0
+      prev_line = lines.pop(0)
+      disabled = 0
+      print(`location`)
+      for line in lines:
+          if line.startswith("``") and disabled == 0:
+              disabled = 1
+          else:
+              if line.startswith("``") and disabled == 1:
+                  disabled = 0
+          if line.startswith('#') and disabled == 0:
+            if line != titlecase(line):
+              print()
+              print("-"+line,end="") 
+              print("+"+titlecase(line[:(line.find("]"))])+line[(line.find("]")):],end="") 
+              return_value = 1
+          if line.startswith('---') or line.startswith('==='):
+            if prev_line != titlecase(prev_line):
+              print()
+              print("-"+prev_line,end="")
+              print("+"+titlecase(prev_line[:(prev_line.find("]"))])+prev_line[(prev_line.find("]")):],end="") 
+              return_value = 1
+          prev_line = line
+      if return_value == 0:
+          print("==Ok==")
+      exit(return_value)
+if __name__ == "__main__":
+  try:
+      main(sys.argv[1])
+  except IndexError:
+      main('.')
-- 
GitLab