|
Cookbook /
CurlyQuotesSummary: Display Curly Double/Single Quotes and M/N Dashes
Version:
Prerequisites: known to work in PmWiki 2.1
Status:
Maintainer:
Categories: Markup
Questions answered by this recipeHow can I turn straight quotes into curly quotes when a page is displayed, without interfering with other markup that involves quotes? How can I create m- and n-dashes with simple wiki markup? DescriptionAdd the following to your config.php:
if ($action != 'edit') {
# make curly quotes
Markup("\"",'_end',"/\"(.*?)\"/",'“$1”');
# make m-dash
Markup("---",'_end',"/---([^-])/",'—$1');
# make n-dash
Markup("--",'_end',"/--([^->])/",'–$1');
# curly single quote in contraction
Markup("a'a",'_end',"/([A-Za-z])'([A-Za-z][A-Za-z]?[^A-Za-z])/",'$1’$2');
}
NotesRelease Notes
CommentsFor me, the m-dash rule above didn't work because PmWiki tried to do the n-dash rule first (so I got -– instead of — for
if ($action != 'edit') {
# curly double quotes
Markup( "dquo", '_end', "/\"(.*?)\"/", '“$1”' );
# curly single quote in contraction
Markup( "squo", '_end', "/([A-Za-z])'([A-Za-z][A-Za-z]?[^A-Za-z])/", '$1’$2');
# m-dash
Markup( "mdash", '<ndash', "/---([^-])/", '—$1' );
# n-dash (beware [-- and --])
Markup( "ndash", 'inline', "/[^\\[]--([^-\\]])/", '–$1' );
# ellipsis
Markup( "...", 'inline', "/\.\.\./", '…' );
}
Tony Colley July 18, 2006, at 01:03 PM Note: if you use the "ndash" markup, beware that this will mess with any links you have with "--" in them (for example, Yahoo! 360 blog entry permalinks often have two dashes together). So, you must change "--" to "%2D%2D" (the corresponding URL encoding).
TonyColley July 23, 2006, at 11:09 AM Actually, this still didn't quite work because using " as a symbol for seconds or inches caused problems. Also, if you do a multiparagraph quote, it didn't handle the opening quote at the beginning of any but the last paragraph. So, I gave up on automatically determining where curly double quotes were appropriate and created a shorthand for entering left and right curly double quotes: # curly double quotes Markup( "ldquo", 'inline', "/\"-/", '“' ); Markup( "rdquo", 'inline', "/-\"/", '”' ); And I created a couple of directives to wrap text in curly quotes:
# [:dq text:] wraps text in curly double quotes
Markup( 'dquo', 'directives', '/\\[:dq (.*?):\\]/',
"“$1”" );
# [:sq text:] wraps text in curly single quotes
Markup( 'squo', 'directives', '/\\[:sq (.*?):\\]/',
"‘$1’" );
Finally, I did keep the markup for automatically converting ' to ’ in contractions and possessives (except possessives of words ending in "s", e.g. "James' dog"):
# curly single quote in contraction
Markup( "apostrophe", '_end', "/([A-Za-z])'([A-Za-z][A-Za-z]?[^A-Za-z])/",
'$1’$2');
TonyColley July 19, 2006, at 02:04 PM If you're pasting text into the wiki from another program, including html2wiki, you may find that perfectly valid curly quotes get turned into high-ASCII characters by your operating system. I guess the ideal way to handle this would be to intercept them when the form is submitted and save them as standard straight quotes, but as a stopgap I've extended this curly-quote recipe to turn the Windows high-ASCII characters into valid curly quotes when the page is rendered:
if ($action != 'edit') {
# make curly quotes
Markup("\"",'_end',"/\"(.*?)\"/",'“$1”');
Markup(chr(147),'_end',"/".chr(147)."/",'“');
Markup(chr(148),'_end',"/".chr(148)."/",'”');
# make m-dash
Markup("---",'_end',"/---([^-])/",'—$1');
Markup(chr(151),'_end',"/".chr(151)."/",'—');
# make n-dash
Markup("--",'_end',"/--([^-])/",'–$1');
Markup(chr(150),'_end',"/".chr(150)."/",'–$1');
# curly single quote in contraction
Markup("a'a",'_end',"/([A-Za-z])'([A-Za-z][A-Za-z]?[^A-Za-z])/",'$1’$2');
Markup(chr(146),'_end',"/".chr(146)."/",'’');
}
If you're using an OS other than Windows to do your editing, you may need to change the chr() numbers to match the characters your OS is serving up. I got these character numbers from the HTML Validator when I tried to validate my wiki pages! Ben Stallings July 18, 2006, at 11:17 AM This markup is not good with pmwikidraw!! The links/URLs are destroyed!!! See AlsoContributorsJohn Cooley, Ben Stallings |