Skip to content

Commit

Permalink
Added configuration for wikilinks page extension and home page name
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Ellis committed Nov 19, 2017
1 parent 3232333 commit 6419e52
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
2 changes: 0 additions & 2 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@
]
},



// Unbold on Alt + B if already bold
{ "keys": ["alt+b"], "command": "insert_snippet", "args": {"contents": "${SELECTION/(^[\\*_]{2}|[\\*_]{2}$)//g}"}, "context":
[
Expand Down
5 changes: 4 additions & 1 deletion Markdown (Standard).sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
}
},

"mde.wikilinks.markdown_extension": ".md",
"mde.wikilinks.homepage": "HomePage",

// You can opt out some keybinds by setting the corresponding value from 'false' to 'true' (without single-quotes).
// Super key references to a key next to left Alt key. It usually has a Windows logo or "win" or "Command" on it.
// Jump between link/image/footnote reference and definition
Expand Down Expand Up @@ -132,5 +135,5 @@
// Open the link referenced
"mde.keymap_disable.open_reference": false,
// Make page reference
"mde.keymap_disable..make_page_reference": false
"mde.keymap_disable.make_page_reference": false
}
7 changes: 6 additions & 1 deletion Markdown.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
}
},

"mde.wikilinks.markdown_extension": ".md",
"mde.wikilinks.homepage": "HomePage",

// You can opt out some keybinds by setting the corresponding value from 'false' to 'true' (without single-quotes).
// Super key references to a key next to left Alt key. It usually has a Windows logo or "win" or "Command" on it.
// Jump between link/image/footnote reference and definition
Expand Down Expand Up @@ -142,5 +145,7 @@
// Open the page referenced
"mde.keymap_disable.open_page": false,
// Open the link referenced
"mde.keymap_disable.open_reference": false
"mde.keymap_disable.open_reference": false,
// Make page reference
"mde.keymap_disable.make_page_reference": false
}
9 changes: 8 additions & 1 deletion MultiMarkdown.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
}
},

"mde.wikilinks.markdown_extension": ".md",
"mde.wikilinks.homepage": "HomePage",

// You can opt out some keybinds by setting the corresponding value from 'false' to 'true' (without single-quotes).
// Super key references to a key next to left Alt key. It usually has a Windows logo or "win" or "Command" on it.
// Jump between link/image/footnote reference and definition
Expand Down Expand Up @@ -130,8 +133,12 @@
"mde.keymap_disable.list_back_links": false,
// Open the home page
"mde.keymap_disable.open_home_page": false,
// Open the journal
"mde.keymap_disable.open_journal": false,
// Open the page referenced
"mde.keymap_disable.open_page": false,
// Open the link referenced
"mde.keymap_disable.open_reference": false
"mde.keymap_disable.open_reference": false,
// Make page reference
"mde.keymap_disable.make_page_reference": false
}
7 changes: 7 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def choose_color_theme(window):
[links]: https://example.com/index.html
[sample image]: https://example.com/sample.png
## Wiki links
This [[SamplePage]] is a wiki link
---
'''})
view.set_syntax_file('Packages/MarkdownEditing/Markdown.tmLanguage')
default_mde_scheme = sublime.load_settings('Markdown.sublime-settings').get('color_scheme') or 'Packages/MarkdownEditing/MarkdownEditor.tmTheme'
Expand Down
4 changes: 3 additions & 1 deletion open_home_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@

class OpenHomePageCommand(sublime_plugin.TextCommand):
def run(self, edit):
home_page = self.view.settings().get("mde.wikilinks.homepage", DEFAULT_HOME_PAGE)

wiki_page = WikiPage(self.view)
wiki_page.select_page(HOME_PAGE)
wiki_page.select_page(home_page)
24 changes: 15 additions & 9 deletions wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import re


MARKDOWN_EXTENSION = '.md'
DEFAULT_MARKDOWN_EXTENSION = '.md'
PAGE_REF_FORMAT = '[[%s]]'
HOME_PAGE = "HomePage"
DEFAULT_HOME_PAGE = "HomePage"


class WikiPage:
Expand Down Expand Up @@ -42,12 +42,13 @@ def find_files_with_name(self, pagename):
pagename = pagename.replace('\\', os.sep).replace(os.sep+os.sep, os.sep).strip()

self.current_file = self.view.file_name()
_, current_extension = os.path.splitext(self.current_file)
self.current_dir = os.path.dirname(self.current_file)

print("Locating page '%s' in: %s" % (pagename, self.current_dir) )

search_pattern = "^%s%s$" % (pagename, current_extension)
markdown_extension = self.view.settings().get("mde.wikilinks.markdown_extension", DEFAULT_MARKDOWN_EXTENSION)

search_pattern = "^%s%s$" % (pagename, markdown_extension)
results = []
for dirname, _, files in self.list_dir_tree(self.current_dir):
for file in files:
Expand All @@ -60,14 +61,16 @@ def find_files_with_name(self, pagename):
def find_files_with_ref(self):
self.current_file = self.view.file_name()
self.current_dir, current_base = os.path.split(self.current_file)
self.current_name, current_extension = os.path.splitext(current_base)
self.current_name, _ = os.path.splitext(current_base)

markdown_extension = self.view.settings().get("mde.wikilinks.markdown_extension", DEFAULT_MARKDOWN_EXTENSION)

results = []
for dirname, _, files in self.list_dir_tree(self.current_dir):
for file in files:
page_name, extension = os.path.splitext(file)
filename = os.path.join(dirname, file)
if extension == MARKDOWN_EXTENSION and self.contains_ref(filename, self.current_name):
if extension == markdown_extension and self.contains_ref(filename, self.current_name):
results.append([page_name, filename])

return results
Expand All @@ -93,10 +96,11 @@ def select_backlink(self, file_list):
def open_new_file(self, pagename):
current_syntax = self.view.settings().get('syntax')
current_file = self.view.file_name()
_, current_extension = os.path.splitext(current_file)
current_dir = os.path.dirname(current_file)

filename = os.path.join(current_dir, pagename + current_extension)
markdown_extension = self.view.settings().get("mde.wikilinks.markdown_extension", DEFAULT_MARKDOWN_EXTENSION)

filename = os.path.join(current_dir, pagename + markdown_extension)

new_view = self.view.window().new_file()
new_view.retarget(filename)
Expand Down Expand Up @@ -168,13 +172,15 @@ def find_matching_files(self, word_region):
current_file = self.view.file_name()
current_dir, current_base = os.path.split(current_file)

markdown_extension = self.view.settings().get("mde.wikilinks.markdown_extension", DEFAULT_MARKDOWN_EXTENSION)

results = []
for dirname, _, files in self.list_dir_tree(current_dir):
for file in files:
page_name, extension = os.path.splitext(file)
filename = os.path.join(dirname, file)

if extension == MARKDOWN_EXTENSION and (not word or word in page_name):
if extension == markdown_extension and (not word or word in page_name):
results.append([page_name, filename])

return results
Expand Down

0 comments on commit 6419e52

Please sign in to comment.