Aaron-Bopp / obsidian-smarter-md-hotkeys

Markdown hotkeys that automatically select words before applying markup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🧠 Smarter Markdown Hotkeys

A plugin for Obsidian providing hotkeys that select words and lines in a smart way before applying markup. Multiple cursors are supported as well.

Demo Video

Table of Contents

Markup Commands added

  • Smarter Bold
  • Smarter Italics
  • Smarter Underscore Bold (__foobar__)
  • Smarter Underscore Italics (_foobar_)
  • Smarter Comment*
  • Smarter HTML Comment*
  • Smarter Inline/Fenced Code*
  • Smarter Highlight
  • Smarter Strikethrough
  • Smarter Markdown/Image Link
  • Smarter Wikilink (Internal Link)
  • Smarter Mathjax*

All commands also support multiple cursors, smart inclusion/exclusion of special characters, and undoing markup by triggering the same hotkey.

The four commands marked with * wrap whole blocks instead of wrapping each line when the hotkey is triggered on a multi-line selection. They also switch to the appropriate syntax, for example from inline code syntax to fenced code syntax. See below for details.

Command-Specific Details

The following commands have some special features:

Smarter Markdown/Image Link

  • Auto-Insert URLs: When you use Smarter Markdown Link and have an URL in your clipboard, the URL will automatically get inserted as well.
  • Automatic Switch to Image Syntax When the URL in the clipboard ends with an image extension like .png,1 the command will also prepend the ! for image links.

Smarter Inline/Fenced Code

  • Terms instead of Words: Smarter Code will not consider punctuation or brackets as delimiters. This means that a cursor anywhere in "object.method" will select the whole term and result in "object.method" instead of "object.method".
  • Automatic Switch to Fenced Code Syntax: When more than one line is selected, Smarter Code will wrap the selected lines in fenced code syntax instead. Furthermore, the cursor is moved to the beginning of the fenced code block so you can conveniently enter the code language.

Smarter Comment

  • Automatic Switch to Block Comments: When more than one line is selected, the Smarter Comment commands will expand the selection to whole blocks and than wrap all of them together into the comment syntax.

Smarter Wikilink

  • Auto-Suggest: When turning text into a wikilink, Smarter Wikilinks will automatically trigger the suggester afterwards.

Smarter Mathjax

  • Automatic Switch to Blocks: When more than one line is selected, the Smarter MathJax command will also expand the selection to whole blocks and switch from $ to $$. (I do not use Mathjax myself, so feel free to open an issue when the Mathjax command can be improved somehow.)

Smarter Punctuation & Delete Commands

While strictly speaking quotation marks and brackets are not a form of markup, I found it quite useful to be able to set them in the same way. Similarly, it is useful to delete text in a smart way, too. Therefore, the following commands have been added as well:

  • Smarter Quotation Marks
  • Smarter Round Brackets
  • Smarter Square Brackets
  • Smarter Delete

How it works in detail

| is a cursor without selection. Selection signifies the part of the text being selected. This table serves as a reference for the precise mechanics of this plugin.

Normal Hotkeys Smarter Hotkeys
foo|bar foo****bar **foobar**
foobar f**oo**bar **foobar**
Lorem Ipsum Lor**em Ips**um **Lorem Ipsum**
- [ ] foobar ^123 **- [ ] foobar ^123** - [ ] **foobar** ^123
## foobar-heading ==## Lorem Ipsum== ## ==Lorem Ipsum==
- Lorem
- Ipsum
- Lor**em
    - Ips
**um
- **Lorem**
    - **Ipsum**
**foo|bar** (Undo) **foo****bar** foobar
**Lorem Ipsum** (Undo) **Lor**em Ips**um** Lorem Ipsum

You can take a look which characters exactly are included or excluded by taking a look at the const.ts file.

Setting the Hotkeys

If you want to replace the default commands from Obsidian, remember to remove their hotkey binding before changing the hotkeys from this plugin. Example for Smarter Bold:

  1. Remove the hotkey cmd/ctrl + B2 for the default command Toggle Bold.
  2. Assign cmd/ctrl + B as the hotkey for the command Smarter Bold.

πŸ’‘ For the smarter punctuation commands, you can also use a hotkey with shift like for example shift + 2 for Smarter Quotation Marks. Curiously, Obsidian accepts such hotkeys, so you can basically "overwrite" normal punctuation typing if you want to. (However, note that this comes at the cost of losing the ability to type punctuation normally.)

Installation

The plugin is available in Obsidian's Community Plugin Browser via: Settings β†’ Community Plugins β†’ Browse β†’ Search for "Smarter Markdown Hotkeys"

Contribute

The easiest way to make contributions is to make changes to const.st, since the constants there determine commands and what to include/exclude.

Please use the .eslintrc configuration located in the repository and run eslint before doing a pull request, and do not use prettier. πŸ™‚

# Run eslint fixing most common mistakes
eslint --fix *.ts

Credits

Thanks to @SkepticMystic for his support!

Donations are welcome via PayPal or Ko-Fi. πŸ™

About me In my day job, I am a sociologist studying the social mechanisms underlying the digital economy. For my PhD project, I investigate the governance of the app economy and how software ecosystems manage the tension between innovation and compatibility. If you are interested in this subject, feel free to visit my academic homepage and get in touch.


⬆️ Go Back to Top

Footnotes

  1. The supported image extensions are listed here. ↩

  2. macOS uses cmd, Windows and Linux use ctrl. ↩

About

Markdown hotkeys that automatically select words before applying markup

License:MIT License


Languages

Language:TypeScript 87.5%Language:Shell 9.4%Language:JavaScript 3.1%