Smart quotes etc

How can smart quotes and other live-replacements of strings of choice be implemented in Logseq? config.edn doesn’t seem to have an option for it, apart from :macro {} that inserts a block to substitute for {{{}}} rather than directly replacing a normal inline string with another.

I found this Javascript:

$(document).ready(function() {
    $('div').focus();
});

$('div').blur(function() {
    text = replace($(this).html());
    $(this).html(text);
});

// replaces straight quotes to curly and double hyphens to em-dashes
function replace(a) {
    console.log(a);
  return a.replace(/'\b/g, "\u2018")  // Opening singles
     .replace(/\b'/g, "\u2019")  // Closing singles
     .replace(/"\b/g, "\u201c")  // Opening doubles
     .replace(/\b"/g, "\u201d")  // Closing doubles
     .replace(/--/g,  "\u2014"); // em-dashes
};

, but I don’t know how to adapt it to Logseq in custom.js. I tried textarea instead of div, it didn’t work (it would render textarea unresponsive to typing).

2 Likes