Skip to content

Commit

Permalink
footnote uses selected word as name
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhao28 committed Dec 16, 2015
1 parent 6a3c29d commit 6ce2fee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,33 @@ def run(self, edit):
def is_enabled(self):
return bool(self.view.score_selector(self.view.sel()[0].a, "text.html.markdown"))

def suggest_default_link_name(title):
# Camel case impl.
ret = ''
for word in title.split():
ret += word.capitalize()
if len(ret) > 30:
break
return ret

class InsertFootnoteCommand(sublime_plugin.TextCommand):
def run(self, edit):
startloc = self.view.sel()[-1].end()
markernum = get_next_footnote_marker(self.view)
if bool(self.view.size()):
targetloc = self.view.find('(\s|$)', startloc).begin()
view = self.view
sel = view.sel()[-1]
startloc = sel.end()
if len(sel) > 0:
markernum = suggest_default_link_name(view.substr(sel))
else:
markernum = get_next_footnote_marker(view)
if bool(view.size()):
targetloc = view.find('(\s|$)', startloc).begin()
else:
targetloc = 0
self.view.insert(edit, targetloc, '[^%s]' % markernum)
self.view.insert(edit, self.view.size(), '\n [^%s]: ' % markernum)
self.view.run_command('set_motion', {"inclusive": True, "motion": "move_to", "motion_args": {"extend": True, "to": "eof"}})
if self.view.settings().get('command_mode'):
self.view.run_command('enter_insert_mode', {"insert_command": "move", "insert_args": {"by": "characters", "forward": True}})
view.insert(edit, targetloc, '[^%s]' % markernum)
view.insert(edit, view.size(), '\n [^%s]: ' % markernum)
view.run_command('set_motion', {"inclusive": True, "motion": "move_to", "motion_args": {"extend": True, "to": "eof"}})
if view.settings().get('command_mode'):
view.run_command('enter_insert_mode', {"insert_command": "move", "insert_args": {"by": "characters", "forward": True}})

def is_enabled(self):
return bool(self.view.score_selector(self.view.sel()[0].a, "text.html.markdown"))
Expand Down Expand Up @@ -177,8 +190,6 @@ def is_enabled(self):
class SortFootnotesCommand(sublime_plugin.TextCommand):
def run(self, edit):
strip_trailing_whitespace(self.view, edit)
self.view.end_edit(edit)
edit = self.view.begin_edit()
defs = get_footnote_definition_markers(self.view)
notes = {}
erase = []
Expand Down
1 change: 1 addition & 0 deletions messages/2.1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ feedback you can use [GitHub issues][issues].
## Changes

* `Paste As Reference` works differently now. Depending on whether the clipboard content is a valid URL, `super+ctrl+r` generates a reference on your selection with clipboard content as URL link or link name.
* `Insert Footnote` (`alt+shift+6`) now uses selected words (if any) as footnote marker name instead of number.

[issues]: https://github.com/SublimeText-Markdown/MarkdownEditing/issues

0 comments on commit 6ce2fee

Please sign in to comment.