Make my syntax even more wikitext-like
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Wed, 17 Aug 2011 14:44:17 -0600
changeset 536 7b22f518099b
parent 535 6b6855ea679c
child 537 604b0ea1165a
Make my syntax even more wikitext-like

This adds {{code|...}} for easy HTML-escaping.
editing.html
preprocess
source.html
--- a/editing.html	Wed Aug 17 14:36:07 2011 -0600
+++ b/editing.html	Wed Aug 17 14:44:17 2011 -0600
@@ -239,9 +239,10 @@
   was actually modified.
 
   <li>But if we are already changing around something's style, convert existing
-  styles to the preferred format.  For instance, we use <code title="">&lt;b&gt;</code> for bold (if the CSS styling flag is false), and convert
-  <code title="">&lt;strong&gt;</code> and <code title="">&lt;span style="font-weight:
-  bold"&gt;</code> if we happen to be modifying that node anyway.
+  styles to the preferred format.  For instance, we use <code title="">&lt;b&gt;</code> for bold
+  (if the CSS styling flag is false), and convert <code title="">&lt;strong&gt;</code> and
+  <code title="">&lt;span style="font-weight: bold"&gt;</code> if we happen to be modifying
+  that node anyway.
 
   <li>Try not to make the document less conforming than it originally was.  If
   we happen to make it more conforming, good, although we don't have to go out
--- a/preprocess	Wed Aug 17 14:36:07 2011 -0600
+++ b/preprocess	Wed Aug 17 14:44:17 2011 -0600
@@ -152,6 +152,17 @@
 if "[[" in s:
     raise Exception("Unrecognized macro: " + s[s.find("[["):s.find("]]") + 2])
 
+# {{code|<foo>}} -> <code title>&lt;foo></code>.  Also, to avoid things like
+# {{code|<b>}} messing up syntax highlighting, {{code<|b>}} is also supported
+# with the same effect as {{code|<b>}}.
+def codesub(matchobj):
+    return "<code title>" \
+        + matchobj.group(1).replace("<", "&lt;") \
+        + matchobj.group(2).replace("&", "&amp;").replace("<", "&lt;") \
+        + "</code>"
+
+s = re.sub(r"\{\{code(<?)\|(.*?)\}\}", codesub, s)
+
 s = s.replace("<var>", "<var title>")
 
 s = s.replace("<!-- @{ -->", "")
--- a/source.html	Wed Aug 17 14:36:07 2011 -0600
+++ b/source.html	Wed Aug 17 14:44:17 2011 -0600
@@ -162,10 +162,10 @@
   was actually modified.
 
   <li>But if we are already changing around something's style, convert existing
-  styles to the preferred format.  For instance, we use <code
-  title>&lt;b></code> for bold (if the CSS styling flag is false), and convert
-  <code title>&lt;strong></code> and <code title>&lt;span style="font-weight:
-  bold"></code> if we happen to be modifying that node anyway.
+  styles to the preferred format.  For instance, we use {{code<|b>}} for bold
+  (if the CSS styling flag is false), and convert {{code<|strong>}} and
+  {{code|<span style="font-weight: bold">}} if we happen to be modifying
+  that node anyway.
 
   <li>Try not to make the document less conforming than it originally was.  If
   we happen to make it more conforming, good, although we don't have to go out