Edited – 2023/02/11 06:40 CDT
Improvements made to: Paste Clipboard as Markdown – Fenced Code Block v1.01
- 2023/02/10 06:33
- Added variable “local_CodeType”, so users can change it if they wish.
- 2023/02/11 05:56
- Added Browser-Find to select the script type text.
- Should work in all modern web browsers.
- If problems occur disable the orange group at the bottom of the macro.
- Added Browser-Find to select the script type text.
- 2023/02/11 06:18
- Added delete past system clipboard to remove markdown from the clipboard.
Hey Folks,
Many people posting AppleScripts and other code-blocks (see list below) on the forum don't know the best way to format it is like so:
```applescript set volumes_ to {"vol 1", "vol2"} -- volume names tell application "Finder" repeat with vol_ in volumes_ eject disk vol_ end repeat end tell ```
** The ` character is commonly known as a Back quote or Backtick and usually shares the Tilde key on U.S. Keyboards.
The forum's software understands the “applescript” (and other) tag names along with the backtick fencing format and produces nicely rendered output like so:
set volumes_ to {"vol 1", "vol2"} -- volume names
tell application "Finder"
repeat with vol_ in volumes_
eject disk vol_
end repeat
end tell
Unfortunately the syntax-lexer plugin produces overly wide tabs and frequently makes the code more difficult to read, so my macro replaces each leading tab with 2 spaces to make the code a little more compact and readable and then wraps it with the appropriate AppleScript tags (the user may change the tag as needed).
When compiled in the Applescript Editor or in Keyboard Maestro Execute an AppleScript action those spaces are transformed back to tabs.
Since I paste a lot of AppleScripts into the forum I have this macro bound to ⌘⇧V
-Chris
Programming Language Syntaxes Supported on the Forum:
Language syntax modules
applescript
awk
bash
cpp
css
diff
http
javascript
json
makefile
markdown
objectivec
perl
plaintext or text
python
ruby
sql
swift
xml
[List Edited – 2019/03/06 15:28 CST]
How To Use
- Select and copy the script/text you want to post.
- Switch to the KM Forum post you are editing, and position the cursor where you want the script to be pasted.
- Trigger this macro.
- Edit the script-type text as needed.
* Note – this macro should not be used where exact formatting of the pasted text is critical.
Download: Paste Clipboard as Markdown – Fenced Code Block v1.01.kmmacros (18 KB)
Keep in mind that you can also use the forum editor's toolbar when appropriate: