[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-bugs] #32627 [Core Tor]: deploy torspec as HTML to GitLab Pages



#32627: deploy torspec as HTML to GitLab Pages
-----------------------+------------------------------
 Reporter:  eighthave  |          Owner:  (none)
     Type:  defect     |         Status:  needs_review
 Priority:  Medium     |      Milestone:
Component:  Core Tor   |        Version:
 Severity:  Normal     |     Resolution:
 Keywords:  torspec    |  Actual Points:
Parent ID:             |         Points:
 Reviewer:             |        Sponsor:
-----------------------+------------------------------

Comment (by eighthave):

 Here's a Python version of the same script, for anyone who wants it.
 {{{
 #!/usr/bin/env python3

 import glob
 import os
 import re

 if not os.path.exists('public'):
     os.mkdir('public')

 titles = dict()
 for f in glob.glob('*.txt'):
     with open(f) as fp:
         contents = fp.read()
     contents = re.sub(r'^\n +', r'# ', contents)
     contents = re.sub(r'\n {1,3}([^ ])', r'\n\1', contents)
     contents = re.sub(r'\n([0-9]+\. (?!http))', r'\n## \1', contents)
     contents = re.sub(r'\n([0-9]+\.[0-9]+\. )', r'\n### \1', contents)
     contents = re.sub(r'\n([0-9]+\.[0-9]+\.[0-9]+\. )', r'\n#### \1',
 contents)
     contents = re.sub(r'\n([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\. )', r'\n#####
 \1', contents)
     with open(f, 'w') as fp:
         fp.write(contents)
     m = re.match(r'\s*# (.*)\n', contents)
     titles[re.sub(r'\.txt$', r'', f)] = m.group(1)

 with open('public/index.html', 'w') as fp:
     fp.write('<!DOCTYPE html>\n\n<html><body><h1>%s</h1><ul>' %
 os.getenv('CI_PROJECT_PATH'))
     for k, v in sorted(titles.items()):
         fp.write('<li><a href="%s.html"><tt>%s</tt>: %s</a></li>' % (k, k,
 v))
     fp.write('</ul></body></html>')
 }}}

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/32627#comment:3>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs