mgmeyers / obsidian-smart-typography

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

Add command: Apply Quotation Topography #52

Open Vemahk opened 5 months ago

Vemahk commented 5 months ago

Howdy.

I've been using Obsidian for writing (not just note taking) for a little while before I stumbled upon this plugin. I wanted to go back and fix all my existing quotations to use the "correct" form. At first, I just got really good with the vim motions of replacing them all, but for some of my multi-ten-thousand word docs, that just wasn't viable. So I tinkered and came up with this.

I mainly did this for my own personal use, so I admit I haven't quite got all the kinks of how to retroactively apply topography to the single quotes (since it's difficult to distinguish apostrophes from single quotations for certain scenarios), but I thought I'd leave this here just in case someone else found it useful. Feel free to modify, critique, merge, or completely ignore this.

Vemahk commented 5 months ago

I do believe this would also solve the same problem the fellows in #29 where asking for. At least in part.

patrickchiang commented 3 months ago

A couple things:

  1. Is there an aversion to using another library? Because if this is only converting smartquotes, there is a smartquotes.js library that handles this in addition to primes and other edge cases.
  2. Would be nice if there was a command to apply this to the entire vault.
    this.addCommand({
      id: "smart-typography-apply-quotations-vault",
      name: "Apply Smart Quotes to Entire Vault",
      callback: () => {
        for (const file of this.app.vault.getMarkdownFiles()) {
          const view = this.app.vault.read(file)
          if (view) {
            view.then((text) => {
              return smartquotes.string(text);
            }).then((text) => {
              this.app.vault.modify(file, text);
            });
          }
        }
      }
    });

    That seemed to work for my naive use case. If not comfortable with using another library, can run through it line-by-line through your algo in apply-quotes.ts too.

Vemahk commented 3 months ago

Honestly it didn't occur to me that someone else may have written some js module for applying these quotations. Oh well.

I didn't add a full-vault command since I didn't need it. I guess you're welcome to open your own PR for that, but I doubt this one will ever get merged as it is, and I'm allergic to scope creep, so... shrug