Add strike through and glyph substitution
[geekigeeki.git] / geekigeeki.py
index 5b98397af612e174205412d723ed251dfa82ed39..a0dc72ca0629280be7792e5c57d3dee60c5b2525 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,6 +337,7 @@ 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">
@@ -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,8 +539,9 @@ 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<glyph> --)
             | (?P<tit>   \={2,6})
             | (?P<br>    \\\\)
             | (?P<rule>  ^-{3,})
@@ -546,7 +552,7 @@ class WikiFormatter:
             | (?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):