BLOG:CMS :: Support Forum

Support Forum for BLOG:CMS

You are not logged in.

  • Index
  •  » Plugins
  •  » Patch for smartypants.php fixing em and en dash editing

#1 28.11.2005 23:56

ajmilne
BLOG:CMS Junior
Registered: 13.11.2005
Posts: 15

Patch for smartypants.php fixing em and en dash editing

The smartypants/smartypants.php that installs (the bit that does the work for the SmartyPants.php plugin during editing) ships with 'Old school' style (or LaTeX style) emdash/endash mapping on by default...

But the StupefyEntities function that maps the entities back to plaintext for editing maps Unicode entity 8211 to a single dash, and 8212 to a double dash...

All of which means: if you edit something containing either entity, you'll lose them when you update the post, even if you entered them correctly (as --- and --) originally.

The following patch fixes this. Apply with patch -p0 <patchfile to smartypants/smartypants.php:

--- smartypants.php    2005-11-28 17:40:46.243422400 -0500
+++ smartypants.php    2005-11-28 17:41:10.488284800 -0500
@@ -419,8 +419,8 @@
         '…',    // ellipsis
     );
     $outputs = array(
-        '-',
         '--',
+        '---',
         "'",
         "'",
         '"',
@@ -550,4 +550,4 @@
     
}

-?>
\ No newline at end of file
+?>

... the array when you're done should look like:

    $outputs = array(
        '--',
        '---',
        "'",
        "'",
        '"',
        '"',
        '...',
    );

... which you could also edit by hand. Note that if you've gone with 'inverted' old school em and en-dashes,k you'd just have to switch around the first two members of the outputs array. Like this:

    $outputs = array(
        '---',
        '--',
        "'",
        "'",
        '"',
        '"',
        '...',
    );

... this is a quick and dirty to get it working. A more complete Stupefication should check the mode, see what the mapping is. I'll leave that for someone else.

Offline

 

#2 02.12.2005 09:53

ajmilne
BLOG:CMS Junior
Registered: 13.11.2005
Posts: 15

Re: Patch for smartypants.php fixing em and en dash editing

Additional patch. I've also found double quotes translate wrong in the current version. I get a low quote on the left side, and a left high quote on the right side of quoted material.

This patch fixes it. Apply to admin/plugins/smartypants/smartypants.php with patch <p0 patchfilename. Note that this patch also rolls in the em-dash fix above, and thus should be applied to a fresh file from source:

Code:

--- smartypants.php    2005-12-01 22:42:38.000000000 -0500
+++ smartypants.php    2005-12-01 22:41:44.000000000 -0500
@@ -170,10 +170,10 @@
                     elseif ($t == '"') {
                         # Special case: single-character " token
                         if (preg_match("/\S/", $prev_token_last_char)) {
-                            $t = "“";
+                            $t = "”";
                         }
                         else {
-                            $t = "„";
+                            $t = "“";
                         }
                     }
                     else {
@@ -203,7 +203,7 @@
 #   Returns:    The string, with "educated" curly quote HTML entities.
 #
 #   Example input:  "Isn't this fun?"
-#   Example output: „Isn’t this fun?“
+#   Example output: “Isn’t this fun?”
 
     # Make our own "punctuation" character class, because the POSIX-style
     # [:PUNCT:] is only available in Perl 5.6 or later:
@@ -224,12 +224,12 @@
     # Special case if the very first character is a quote
     # followed by punctuation at a non-word-break. Close the quotes by brute force:
     $s = preg_replace("/^'(?=[$punct_class]\B)/", '’', $s);
-    $s = preg_replace("/^\"(?=[${punct_class}]\B)/", '“', $s);
+    $s = preg_replace("/^\"(?=[${punct_class}]\B)/", '”', $s);
 
     # Special case for double sets of quotes, e.g.:
     #   <p>He said, "'Quoted' words in a larger quote."</p>
-    $s = preg_replace("/\"'(?=\w)/", '„‘', $s);
-    $s = preg_replace("/'\"(?=\w)/", '‘„', $s);
+    $s = preg_replace("/\"'(?=\w)/", '“‘', $s);
+    $s = preg_replace("/'\"(?=\w)/", '‘“', $s);
 
     # Special case for decade abbreviations (the '80s):
     $s = preg_replace("/'(?=\d{2}s)/", '’', $s);
@@ -286,7 +286,7 @@
     (?=\w)              # followed by a word character
 }x
 REGEX;
-    $s = preg_replace($pattern, "$1„", $s);
+    $s = preg_replace($pattern, "$1“", $s);
 
     # Double closing quotes:
     $pattern = <<<REGEX
@@ -297,10 +297,10 @@
                     # if not, then make sure the next char is whitespace.
 }x
 REGEX;
-    $s = preg_replace($pattern, "$1“", $s);
+    $s = preg_replace($pattern, "$1”", $s);
     
     # Any remaining quotes should be opening ones.
-    $s = str_replace('"', '„', $s);
+    $s = str_replace('"', '“', $s);
 
     return $s;
 }
@@ -313,10 +313,10 @@
 #               translated into HTML curly quote entities.
 #
 #   Example input:  ``Isn't this fun?''
-#   Example output: „Isn't this fun?“
+#   Example output: “Isn't this fun?”
 
-    $s = str_replace("``",  '„', $s);
-    $s = str_replace("''",  '“', $s);
+    $s = str_replace("``",  '“', $s);
+    $s = str_replace("''",  '”', $s);
     return $s;
 }
 
@@ -405,7 +405,7 @@
 #   Returns:    The string, with each SmartyPants HTML entity translated to
 #               its ASCII counterpart.
 #
-#   Example input:  „Hello — world.“
+#   Example input:  “Hello — world.”
 #   Example output: "Hello -- world."
 #
 
@@ -414,13 +414,13 @@
         '—',    // em-dash
         '‘',    // open single quote
         '’',    // close single quote
-        '„',    // open double quote
-        '“',    // close double quote
+        '“',    // open double quote
+        '”',    // close double quote
         '…',    // ellipsis
     );
     $outputs = array(
-        '-',
         '--',
+        '---',
         "'",
         "'",
         '"',

Last edited by ajmilne (02.12.2005 23:19)

Offline

 

#3 02.12.2005 11:01

ajmilne
BLOG:CMS Junior
Registered: 13.11.2005
Posts: 15

Re: Patch for smartypants.php fixing em and en dash editing

Patches for this and other issues are now available at http://accidentalweblog.org/patches/blogcms/

Offline

 

#4 02.12.2005 13:50

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Patch for smartypants.php fixing em and en dash editing

Thanks, appreciate it.


--= BLOG:CMS developer =--

Offline

 

#5 02.12.2005 23:16

ajmilne
BLOG:CMS Junior
Registered: 13.11.2005
Posts: 15

Re: Patch for smartypants.php fixing em and en dash editing

You're most welcome. Good system you've built here.

Offline

 
  • Index
  •  » Plugins
  •  » Patch for smartypants.php fixing em and en dash editing

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson

TOPlist