Import latest gitweb
[geekigeeki.git] / geekigeeki.py
index 5b98397af612e174205412d723ed251dfa82ed39..5a401abde033bc06cd504fdb61c4e00fc41676e2 100755 (executable)
@@ -18,7 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-__version__ = '$Id$'[4:12]
+__version__ = '4.0-' + '$Id$'[4:11]
 
 from time import clock
 start_time = clock()
@@ -337,13 +337,14 @@ def send_footer(mod_string=None):
         cgi.print_arguments()
         cgi.print_form(form)
         cgi.print_environ()
+        #FIXME link_inline("sys/footer")
     print('''
 <div id="footer"><hr />
 <p class="copyright">
 <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img class="license" alt="Creative Commons License" src="%s" /></a>
 <span class="benchmark">generated in %0.3fs</span> by <a href="http://www.codewiz.org/wiki/GeekiGeeki">GeekiGeeki</a> version %s
 </p>
-''' % (relative_url('cc-by-sa.png'), clock() - start_time, __version__))
+''' % (relative_url('sys/cc-by-sa.png'), clock() - start_time, __version__))
     if mod_string:
         print('<p class="modified">last modified %s</p>' % mod_string)
     print('</div></body></html>')
@@ -367,6 +368,7 @@ class WikiFormatter:
             "**":  ["b",   False],
             "##":  ["tt",  False],
             "__":  ["u",   False],
+            "--":  ["del", False],
             "^^":  ["sup", False],
             ",,":  ["sub", False],
             "''":  ["em",  False], # LEGACY
@@ -379,6 +381,9 @@ class WikiFormatter:
         style[1] = not style[1]
         return ['</', '<'][style[1]] + style[0] + '>'
 
+    def _glyph_repl(self, word):
+        return '&mdash;'
+
     def _tit_repl(self, word):
         if self.h_level:
             result = '</h%d><p>\n' % self.h_level
@@ -534,19 +539,20 @@ class WikiFormatter:
         print('<div class="wiki"><p>')
 
         scan_re = re.compile(r"""(?:
-            # Styles and formatting
-              (?P<b>     \*\*|'''|//|''|\#\#|``|__|\^\^|,,)
+            # Styles and formatting ("--" must cling to a word to disambiguate it from the dash)
+              (?P<b>     \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' | `` )
             | (?P<tit>   \={2,6})
             | (?P<br>    \\\\)
             | (?P<rule>  ^-{3,})
             | (?P<hi>    \b( FIXME | TODO | DONE )\b )
+            | (?P<glyph> --)
 
             # Links
             | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
             | (?P<hurl>  \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
 
             # Inline HTML
-            | (?P<html>  <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
+            | (?P<html>             <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
             | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
             | (?P<ent>   [<>&] )
 
@@ -556,7 +562,7 @@ class WikiFormatter:
             | (?P<url>   (http|https|ftp|mailto)\:[^\s'\"]+\S)
             | (?P<email> [-\w._+]+\@[\w.-]+)
 
-            # Lists, divs, spans
+            # Lists, divs, spans and inline objects
             | (?P<li>    ^\s+[\*\#]\s+)
             | (?P<pre>   \{\{\{|\s*\}\}\})
             | (?P<inl>   \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
@@ -645,7 +651,7 @@ class Page:
     def format_dir(self):
         out = '== '
         pathname = ''
-        for dirname in self.page_name.split('/'):
+        for dirname in self.page_name.strip('/').split('/'):
             pathname = (pathname + '/' + dirname) if pathname else dirname
             out += '[[' + pathname + '|' + dirname + ']]/'
         out += ' ==\n'
@@ -795,6 +801,9 @@ class Page:
                 os.remove(name)
             except OSError, err:
                 if err.errno != errno.ENOENT: raise err
+        path = os.path.split(name)[0]
+        if not os.path.exists(path):
+            os.makedirs(path)
         os.rename(tmp_filename, name)
 
     def save(self, newdata, changelog):