Run swift format.swift
after copying text from VS Code.
Last active
September 8, 2020 09:00
-
-
Save znck/d11533f4029eb41bde904a610a15a026 to your computer and use it in GitHub Desktop.
Format VS Code copied code snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
let pasteboard = NSPasteboard.general | |
let re1 = try! NSRegularExpression(pattern: "background-color:.*?;") | |
let re2 = try! NSRegularExpression(pattern: "font-size:.*?;") | |
let re3 = try! NSRegularExpression(pattern: "font-family:.*?;") | |
let htmlType = NSPasteboard.PasteboardType(rawValue: "public.html") | |
for element in pasteboard.pasteboardItems! { | |
let str = element.string(forType: htmlType) | |
let mstr = NSMutableString(string: str!) | |
re1.replaceMatches( | |
in: mstr, | |
range: NSRange(location: 0,length: mstr.length), | |
withTemplate: " ") | |
re2.replaceMatches( | |
in: mstr, | |
range: NSRange(location: 0,length: mstr.length), | |
withTemplate: "font-size: 32px; ") | |
re3.replaceMatches( | |
in: mstr, | |
range: NSRange(location: 0,length: mstr.length), | |
withTemplate: "font-family: 'Fira Code'; ") | |
pasteboard.clearContents() | |
pasteboard.setString(mstr as String, forType: htmlType) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sh | |
paste_as_html () { | |
osascript -e 'the clipboard as «class HTML»' | perl -ne 'print chr foreach unpack("C*", pack("H*", substr($_, 11, -3)))' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment