Smart quotes in TiddlyWiki

210 views
Skip to first unread message

Soren Bjornstad

unread,
Dec 6, 2020, 9:01:51 PM12/6/20
to TiddlyWiki
I'm starting to get sick of using a four-button compose-key sequence to get “curly quotes” in my tiddlers. Has anyone thought about or tried integrating a library like smartquotes.js into TiddlyWiki to automatically curl "straight quotes" in output? TiddlyWiki automatically upgrades hyphens to dashes, and if anything straight quotes are an even more egregious typographical mistake, so it feels like something TiddlyWiki should handle for me.

I don't believe CodeMirror has any options related to upgrading the characters on insertion, but I do use CodeMirror so that would be an acceptable way too.

Suzanne McHale

unread,
Dec 6, 2020, 9:47:16 PM12/6/20
to TiddlyWiki
I would like this too! I use curly quotes as they are proper punctuation (straight quotes look ugly), and it seems odd that they are not an option.


coda coder

unread,
Dec 7, 2020, 2:50:18 PM12/7/20
to TiddlyWiki
FWIW, I use AutoHotKey. I've wired up Ctrl+' and Ctrl+Shift+' to issue curlies “like this”

;Pretty quotes
^':: SendInput
^+':: SendInput

On a US DT keyboard, at least, they're conveniently located. On UK keyboards I know they're not so convenient. Android... no idea.

Anjar

unread,
Dec 7, 2020, 4:19:29 PM12/7/20
to TiddlyWiki
Hi,

I think you can use the parser to create your own shorthand notation, eg. to render ;;test;; as “curly quotes”, or you can probably also use a parser rule to replace straight quotes as well (altough I don't know if you risk quotes within code being replaced as well). See https://groups.google.com/g/tiddlywiki/c/IN46zvv4nCw

You can probably use $:/core/modules/parsers/wikiparser/rules/emphasis/superscript.js for inspiration (to "encapsule" something):

exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\^\^/mg;
};

exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;

// Parse the run including the terminator
var tree = this.parser.parseInlineRun(/\^\^/mg,{eatTerminator: true});

// Return the classed span
return [{
type: "element",
tag: "sup",
children: tree
}];
};

in combination with $:/core/modules/parsers/wikiparser/rules/dash.js (to replace the shorthand/straight quotes with a HTML entity):

exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /-{2,3}(?!-)/mg;
};

exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
var dash = this.match[0].length === 2 ? "–" : "—";
return [{
type: "entity",
entity: dash
}];
};


Best,
Anders

Anjar

unread,
Dec 9, 2020, 5:27:52 PM12/9/20
to TiddlyWiki
Hi again Soren,

It may not be the most elegant solution, but import the two attached tiddlers (you may have to remove the .txt ending) to your tiddlywiki and reload it. Then all you "test" will be replaced by  “test” (the difference is hard to spot with the default font though). Actually, you can choose any character or string to replace the quotes with in $:/me/smartquote.css. However, we add them by using ::before and ::after in css, so you will not be able to select or copy the quotes themselves..

Best,
Anders

$__core_modules_parsers_wikiparser_rules_emphasis_quote.js.tid.txt
$__me_smartquote.css.tid.txt

springer

unread,
Dec 9, 2020, 6:16:29 PM12/9/20
to TiddlyWiki
Soren, I surmise you're on Windows…

But if Mac-users find this thread: 
opt-[ gets you an opening curly-double-quote 
opt-shift-[ gets you a closing curly-double-quote
(for single-quote variants, it's the same as above but with end-bracket: opt-] and opt-shift-] )

There are good reasons not to want tiddlywiki to replace automatically, at least for anyone who makes use of various quote-delimited parameters in macros, etc. For example, Shiraz's <<alert src:"Alert text here">> can work with complex text only when I can type something like: 

<<alert src:"Don‘t yell “Fire!” in a crowded theater!">> 

;) -Springer

TW Tones

unread,
Dec 9, 2020, 6:23:52 PM12/9/20
to TiddlyWiki
Surely these work and not your example?

<<alert src:'Don‘t yell “Fire!” in a crowded theater!'>>

<<alert src:"""Don‘t yell “Fire!” in a crowded theater!""">>    

Tones

History Buff

unread,
Dec 9, 2020, 6:25:47 PM12/9/20
to TiddlyWiki
Here's what I use that I think it simplest:

springer

unread,
Dec 9, 2020, 6:40:35 PM12/9/20
to TiddlyWiki
Tones, I did type too hastily, but what I meant was: <<alert src:"Don‘t yell “Fire!” in a crowded theater!">>
But for anyone who really cares about curly quotes, you might be amused by this: 

Eric Shulman

unread,
Dec 9, 2020, 6:56:07 PM12/9/20
to TiddlyWiki
On Wednesday, December 9, 2020 at 3:40:35 PM UTC-8 springer wrote:
<<alert src:"Don‘t yell “Fire!” in a crowded theater!">>

But can you yell "Theater!" in a crowded firehouse?   :-)

-e

Soren Bjornstad

unread,
Dec 9, 2020, 7:40:10 PM12/9/20
to TiddlyWiki
Thanks everyone. I evidently wasn't clear enough on where I'm at and what I was hoping for.

I know how to insert real curly quote characters into TiddlyWiki using my preferred input method (I'm on Linux actually, @springer), and I regularly do this. However, as with any input method that I'm aware of, it requires extra keypresses on top of straight quotes, which would be nice to avoid if possible. All of my other editing environments, from word processors to text editors to document preparation systems, support one of two ways of allowing you to type straight quotes but display curly quotes:
  • automatically upgrading straight quotes when typing them
  • automatically upgrading straight quotes when rendering them from source, either during a compilation phase or when displaying the document
The first solution probably isn't too practical for TiddlyWiki, since as others have mentioned there is often need to type straight quotes. (In vim I can press ^V " for a straight quote with curly-quotes on, but that's not supported in CodeMirror.)

smartquotes.js and similar tools work at render time, and they have no difficulty avoiding accidentally curling quotation marks that are part of code. They automatically skip anything within HTML tags, scripts, <pre> blocks, and so on. They dynamically replace the quotation marks within the DOM after the page loads, so that the real characters are there afterwards. Another set of tools (used in tools like XeTeX, Sphinx, Jekyll, and some Markdown renderers) replace at compile time (in TiddlyWiki, this would presumably be during parsing).

@Anjar, that's a pretty slick solution with ::before and ::after, but not being able to copy the quotation marks is more annoying to me than having to spend a bit longer typing them at the start.

I think a solution that's better than what I'm currently doing needs to:
  • understand the semantic role of the quotation mark in the text so that it knows not to replace quotes that are part of code;
  • work completely automatically, converting " characters to the appropriate curly versions when a tiddler or other wikitext is wikified (if it screws up occasionally, I can go back and put a raw quote that goes the right direction in)
  • actually place the new character within the DOM so that it copies correctly.
If we don't know of anything that exists and adding some feature that does this to TiddlyWiki doesn't seem workable, that's a fine answer. It just seems a little odd to me that TiddlyWiki is the only serious modern document tool I use that doesn't use a library like this.

Ton Gerner

unread,
Dec 10, 2020, 12:33:00 PM12/10/20
to TiddlyWiki

Cheers,

Ton

springer

unread,
Dec 10, 2020, 2:12:11 PM12/10/20
to TiddlyWiki
Ton, thanks! sk's plugin failed on only ONE case: getting century-clipped year references to use the curly apostrophe 
But it's generally awesome, and in particular recognized the need to convert to prime and double-prime marks, rather than curly quotes for feet and inches (!)

-Springer

springer

unread,
Dec 10, 2020, 2:17:06 PM12/10/20
to TiddlyWiki
Side note: I wonder how many plugins and other solutions depend on tiddlyspot for their demo sites. Authors (like Stephen K) who set things up there may not even realize that its days (even as read-only host) may be numbered. 

-Springer

Reply all
Reply to author
Forward
0 new messages