mgmeyers / obsidian-smart-typography

Converts quotes to curly quotes, dashes to em dashes, and periods to ellipses
GNU General Public License v3.0
250 stars 11 forks source link

Conflict between Templater и Smart-Typography #39

Open Xallt opened 2 years ago

Xallt commented 2 years ago

One of the features of the Smart-Typography plugin is automatically turning standard double quotes into curly double quotes ("" → ““). This is a very subtle change that is hard to notice, and I didn't even know about this until I discovered my issue (I initially downloaded the plugin just for em-dashes).

At some point I started setting up the plugin Templater and encountered an issue where, when creating simple templates (for example, just inserting the creation date <% tp.file.creation_date(“D MMMM YYYY“)%>), while processing the template, Templater crashed with a parsing error

Templater Error: Template parsing error, aborting. 
 Bad template syntax

and an error message in the console that is not interpretable

Invalid or unexpected token
===========================
var tR='',__l,__lP,include=E.include.bind(E),includeFile=E.includeFile.bind(E)
function layout(p,d){__l=p;__lP=d}
const _prs = [];
_prs.push(tp.file.creation_date(“D MMMM YYYY“));
tR+='rJ2KqXzxQg'
tR+='\n\n'
const _rst = await Promise.all(_prs);
tR = tR.replace(/rJ2KqXzxQg/g, () => _rst.shift());
if(__l)tR=await includeFile(__l,Object.assign(tp,{body:tR},__lP))
if(cb){cb(null,tR)} return tR

After some digging around, I finally discovered that the issue was in Templater not being able to parse the curly quotes, and everything was, of course, fixed by using the standard quotes.

Preventive measures?

Would it make sense to implement a check for whether currently the cursor is located inside brackets like <\%\%> or other variations, and turn off the quote conversion when that is true? I understand that the user might start typing the Templater command outside of the <\%\%> brackets and add them afterwards. But still, some countermeasures might prevent baffled users like me.

Xallt commented 2 years ago

I see there is another similar issue https://github.com/mgmeyers/obsidian-smart-typography/issues/12 about another framework suffering from not being able to parse the curly quotes correctly Maybe the quote conversion feature should be turned off by default? Because of how many conflicts it can cause with other frameworks, and how the user may have a bad time figuring the problem out.

mgmeyers commented 2 years ago

The issue here seems to be that templater syntax highlighting does not work with obsidian's new editor: https://github.com/SilentVoid13/Templater/issues/491

Smart typography checks to see if the cursor is inside a templater block before executing, but this is not currently possible because templater blocks are no longer highlighted.

It's not the best solution, but you can undo smart typography's character conversion by pressing delete/backspace immediately after typing a quote.