-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local function convertMarkdownToConfluence() | ||
local originalClipboardContents = hs.pasteboard.getContents() | ||
|
||
hs.alert.show("Converting from Markdown...") | ||
|
||
-- Select all | ||
hs.eventtap.keyStroke({'cmd'}, 'a', 0) | ||
|
||
-- Get the current change count of the clipboard | ||
local changeCount = hs.pasteboard.changeCount() | ||
|
||
-- Cut to clipboard | ||
hs.eventtap.keyStroke({'cmd'}, 'c', 0) | ||
|
||
-- Wait for the clipboard to have the <textarea> contents. | ||
clipboardHasUpdated = function() | ||
return changeCount ~= hs.pasteboard.changeCount() | ||
end | ||
|
||
local clipboardTimer = hs.timer.waitUntil(clipboardHasUpdated, function() | ||
-- Get the markdown out of the clipboard | ||
local markdown = hs.pasteboard.getContents() | ||
|
||
-- Write it to a file | ||
local file = io.open("/tmp/jira.md", "w+") | ||
io.output(file) | ||
io.write(markdown) | ||
io.close(file) | ||
|
||
-- Run it through md2confl | ||
local binPath = os.getenv('HOME') .. "/go/bin/md2confl" | ||
local result = hs.execute("cat /tmp/jira.md | " .. binPath) | ||
|
||
-- Trim whitespace | ||
result = string.gsub(result, '^%s*(.-)%s*$', '%1') | ||
|
||
local lines = hs.fnutils.split(result, "\n", nil, true) | ||
|
||
for index, line in ipairs(lines) do | ||
hs.eventtap.keyStrokes(line) | ||
|
||
if index < #lines then | ||
hs.eventtap.keyStroke({}, "return", 0) | ||
end | ||
end | ||
|
||
hs.alert.show("Done!") | ||
|
||
-- Restore clipboard | ||
hs.pasteboard.setContents(originalClipboardContents) | ||
end) | ||
|
||
hs.timer.doAfter(3, function() | ||
-- Give up if the clipboard doesn't update after 3 seconds. | ||
clipboardTimer:stop() | ||
end) | ||
end | ||
|
||
hyperKey:bind('x'):toFunction("Markdown -> JIRA", convertMarkdownToConfluence) |