diff --git a/Context.sublime-menu b/Context.sublime-menu
new file mode 100644
index 00000000..c9417f12
--- /dev/null
+++ b/Context.sublime-menu
@@ -0,0 +1,14 @@
+[
+{
+ "caption": "MDE: Fold Section",
+ "command": "fold_section_context"
+},
+{
+ "caption": "MDE: Unfold Section",
+ "command": "unfold_section_context"
+},
+{
+ "caption": "MDE: Jump Reference",
+ "command": "reference_jump_context"
+}
+]
\ No newline at end of file
diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap
index b14bcde6..929ee5ca 100644
--- a/Default (Linux).sublime-keymap
+++ b/Default (Linux).sublime-keymap
@@ -393,9 +393,10 @@
// inline image insertion
{ "keys": ["super+shift+k"], "command": "reference_new_inline_image", "context":
- [
- { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
- ]
+ [
+ { "key": "setting.mde.keymap_disable.reference_new_inline_image", "operator": "not_equal", "operand": true },
+ { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
+ ]
},
// modify [] pairing so that selection is removed after pairing, ready for [] or ()
{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[$SELECTION]$0"}, "context":
@@ -408,16 +409,19 @@
// run paste as link command on selected text
{ "keys": ["ctrl+super+v"], "command": "reference_new_inline_link", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_inline_link", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+super+r"], "command": "reference_new_reference", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_reference", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+alt+g"], "command": "reference_jump", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_jump", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -580,6 +584,7 @@
},
{ "keys": ["alt+shift+6"], "command": "reference_new_footnote", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_footnote", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -596,6 +601,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^\\s+", "match_all": true },
{ "key": "following_text", "operator": "not_regex_match", "operand": "^$", "match_all": true },
@@ -604,6 +610,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^\\s+", "match_all": true },
{ "key": "selector", "operator": "not_equal", "operand": "markup.list", "match_all": true },
@@ -612,6 +619,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
{ "key": "text", "operator": "regex_contains", "operand": "^(#{1,6}(?!#))|^(-{3,}|={3,})$"},
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
@@ -619,26 +627,31 @@
},
{ "keys": ["ctrl+shift+tab"], "command": "show_fold_all_sections", "context":
[
+ { "key": "setting.mde.keymap_disable.show_fold_all_sections", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+alt+pageup"], "command": "goto_previous_heading", "args": {"same_level": true}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_previous_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+alt+pagedown"], "command": "goto_next_heading", "args": {"same_level": true}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_next_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+pageup"], "command": "goto_previous_heading", "args": {"same_level": false}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_previous_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+pagedown"], "command": "goto_next_heading", "args": {"same_level": false}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_next_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
}
diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap
index df2f8fdc..f8ddd95e 100644
--- a/Default (OSX).sublime-keymap
+++ b/Default (OSX).sublime-keymap
@@ -394,6 +394,7 @@
// inline image insertion
{ "keys": ["super+shift+k"], "command": "reference_new_inline_image", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_inline_image", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -408,16 +409,19 @@
// run paste as link command on selected text
{ "keys": ["super+alt+v"], "command": "reference_new_inline_link", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_inline_link", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["super+alt+r"], "command": "reference_new_reference", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_reference", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["super+ctrl+shift+l"], "command": "reference_jump", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_jump", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -580,6 +584,7 @@
},
{ "keys": ["alt+shift+6"], "command": "reference_new_footnote", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_footnote", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -601,6 +606,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^\\s+", "match_all": true },
{ "key": "following_text", "operator": "not_regex_match", "operand": "^$", "match_all": true },
@@ -609,6 +615,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^\\s+", "match_all": true },
{ "key": "selector", "operator": "not_equal", "operand": "markup.list", "match_all": true },
@@ -617,6 +624,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
{ "key": "text", "operator": "regex_contains", "operand": "^(#{1,6}(?!#))|^(-{3,}|={3,})$"},
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
@@ -624,26 +632,31 @@
},
{ "keys": ["ctrl+shift+tab"], "command": "show_fold_all_sections", "context":
[
+ { "key": "setting.mde.keymap_disable.show_fold_all_sections", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["super+ctrl+pageup"], "command": "goto_previous_heading", "args": {"same_level": true}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_previous_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["super+ctrl+pagedown"], "command": "goto_next_heading", "args": {"same_level": true}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_next_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["super+shift+pageup"], "command": "goto_previous_heading", "args": {"same_level": false}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_previous_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["super+shift+pagedown"], "command": "goto_next_heading", "args": {"same_level": false}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_next_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
}
diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap
index 66a82baa..929ee5ca 100644
--- a/Default (Windows).sublime-keymap
+++ b/Default (Windows).sublime-keymap
@@ -394,6 +394,7 @@
// inline image insertion
{ "keys": ["super+shift+k"], "command": "reference_new_inline_image", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_inline_image", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -408,16 +409,19 @@
// run paste as link command on selected text
{ "keys": ["ctrl+super+v"], "command": "reference_new_inline_link", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_inline_link", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+super+r"], "command": "reference_new_reference", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_reference", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+alt+g"], "command": "reference_jump", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_jump", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -580,6 +584,7 @@
},
{ "keys": ["alt+shift+6"], "command": "reference_new_footnote", "context":
[
+ { "key": "setting.mde.keymap_disable.reference_new_footnote", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
@@ -596,6 +601,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^\\s+", "match_all": true },
{ "key": "following_text", "operator": "not_regex_match", "operand": "^$", "match_all": true },
@@ -604,6 +610,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "^\\s+", "match_all": true },
{ "key": "selector", "operator": "not_equal", "operand": "markup.list", "match_all": true },
@@ -612,6 +619,7 @@
},
{ "keys": ["shift+tab"], "command": "fold_section", "context":
[
+ { "key": "setting.mde.keymap_disable.fold_section", "operator": "not_equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
{ "key": "text", "operator": "regex_contains", "operand": "^(#{1,6}(?!#))|^(-{3,}|={3,})$"},
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
@@ -619,26 +627,31 @@
},
{ "keys": ["ctrl+shift+tab"], "command": "show_fold_all_sections", "context":
[
+ { "key": "setting.mde.keymap_disable.show_fold_all_sections", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+alt+pageup"], "command": "goto_previous_heading", "args": {"same_level": true}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_previous_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+alt+pagedown"], "command": "goto_next_heading", "args": {"same_level": true}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_next_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+pageup"], "command": "goto_previous_heading", "args": {"same_level": false}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_previous_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["ctrl+shift+pagedown"], "command": "goto_next_heading", "args": {"same_level": false}, "context":
[
+ { "key": "setting.mde.keymap_disable.goto_next_heading", "operator": "not_equal", "operand": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
}
diff --git a/Default.sublime-commands b/Default.sublime-commands
index a5b694ef..f9f2e5c6 100644
--- a/Default.sublime-commands
+++ b/Default.sublime-commands
@@ -140,5 +140,9 @@
{
"same_level" : false
}
+ },
+ {
+ "caption": "MarkdownEditing: Change color scheme...",
+ "command": "mde_color_activate"
}
]
diff --git a/Main.sublime-menu b/Main.sublime-menu
index c6586934..ba27d0e6 100644
--- a/Main.sublime-menu
+++ b/Main.sublime-menu
@@ -15,6 +15,10 @@
"caption": "README",
"command": "open_file"
},
+ {
+ "caption": "Change color scheme...",
+ "command": "mde_color_activate"
+ },
{
"caption": "-"
},
diff --git a/Markdown (Standard).sublime-settings b/Markdown (Standard).sublime-settings
index 4a7403dd..f06efa17 100644
--- a/Markdown (Standard).sublime-settings
+++ b/Markdown (Standard).sublime-settings
@@ -90,5 +90,35 @@
// optionaly, 2
"ol_multi": 1
}
- }
+ },
+
+ // 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
+ // Default keys: (OSX)super+ctrl+shift+l (Linux/Win)ctrl+alt+g
+ "mde.keymap_disable_reference_jump": false,
+ // Add a new link
+ // Default keys: (OSX)super+alt+r (Linux/Win)ctrl+super+r
+ "mde.keymap_disable_reference_new_reference": false,
+ // Add a new inline link
+ // Default keys: (OSX)super+alt+v (Linux/Win)ctrl+super+v
+ "mde.keymap_disable_reference_new_inline_link": false,
+ // Add a new inline image
+ // Default keys: (OSX/Linux/Win)super+shift+k
+ "mde.keymap_disable_reference_new_inline_image": false,
+ // Add a new footnote
+ // Default keys: (OSX/Linux/Win)alt+shift+6
+ "mde.keymap_disable_reference_new_footnote": false,
+ // Fold current section
+ // Default keys: (OSX/Linux/Win)shift+tab
+ "mde.keymap_disable_fold_section": false,
+ // Open a panel showing all functions related to folding
+ // Default keys: (OSX/Linux/Win)ctrl+shift+tab
+ "mde.keymap_disable_show_fold_all_sections": false,
+ // Jump to the next heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pagedown (Linux/Win)ctrl+shift(+alt)+pagedown
+ "mde.keymap_disable_goto_next_heading": false,
+ // Jump to the previous heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pageup (Linux/Win)ctrl+shift(+alt)+pageup
+ "mde.keymap_disable_goto_previous_heading": false
}
diff --git a/Markdown.sublime-settings b/Markdown.sublime-settings
index 909944b2..1e037d6e 100644
--- a/Markdown.sublime-settings
+++ b/Markdown.sublime-settings
@@ -102,5 +102,35 @@
// optionally, 2
"ol_multi": 1
}
- }
+ },
+
+ // 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
+ // Default keys: (OSX)super+ctrl+shift+l (Linux/Win)ctrl+alt+g
+ "mde.keymap_disable.reference_jump": false,
+ // Add a new link
+ // Default keys: (OSX)super+alt+r (Linux/Win)ctrl+super+r
+ "mde.keymap_disable.reference_new_reference": false,
+ // Add a new inline link
+ // Default keys: (OSX)super+alt+v (Linux/Win)ctrl+super+v
+ "mde.keymap_disable.reference_new_inline_link": false,
+ // Add a new inline image
+ // Default keys: (OSX/Linux/Win)super+shift+k
+ "mde.keymap_disable.reference_new_inline_image": false,
+ // Add a new footnote
+ // Default keys: (OSX/Linux/Win)alt+shift+6
+ "mde.keymap_disable.reference_new_footnote": false,
+ // Fold current section
+ // Default keys: (OSX/Linux/Win)shift+tab
+ "mde.keymap_disable.fold_section": false,
+ // Open a panel showing all functions related to folding
+ // Default keys: (OSX/Linux/Win)ctrl+shift+tab
+ "mde.keymap_disable.show_fold_all_sections": false,
+ // Jump to the next heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pagedown (Linux/Win)ctrl+shift(+alt)+pagedown
+ "mde.keymap_disable.goto_next_heading": false,
+ // Jump to the previous heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pageup (Linux/Win)ctrl+shift(+alt)+pageup
+ "mde.keymap_disable.goto_previous_heading": false
}
diff --git a/Markdown.tmLanguage b/Markdown.tmLanguage
index 6e9a78be..d8ea3786 100644
--- a/Markdown.tmLanguage
+++ b/Markdown.tmLanguage
@@ -4,10 +4,10 @@
fileTypes
+ md
mdown
markdown
markdn
- md
foldingStartMarker
(?x)
@@ -591,11 +591,11 @@
include
- #link-ref-literal
+ #link-ref
include
- #link-ref
+ #link-ref-literal
include
@@ -730,11 +730,11 @@
include
- #link-ref-literal
+ #link-ref
include
- #link-ref
+ #link-ref-literal
include
@@ -868,11 +868,11 @@
include
- #link-ref-literal
+ #link-ref
include
- #link-ref
+ #link-ref-literal
include
@@ -1046,7 +1046,7 @@
5
name
- punctuation.definition.constant.markdown
+ punctuation.definition.constant.begin.markdown
6
@@ -1056,7 +1056,7 @@
7
name
- punctuation.definition.constant.markdown
+ punctuation.definition.constant.end.markdown
match
@@ -1126,11 +1126,11 @@
include
- #link-ref-literal
+ #link-ref
include
- #link-ref
+ #link-ref-literal
include
@@ -1274,11 +1274,11 @@
include
- #link-ref-literal
+ #link-ref
include
- #link-ref
+ #link-ref-literal
include
@@ -1537,7 +1537,7 @@
match
- (\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(\[)(\])
+ (\[)((?<square>[^\[\]\\]|\\.|\[\g<square>*+\])*+)(\])[ ]?(?:(\[)(\]))?
name
meta.link.reference.literal.markdown
@@ -2062,6 +2062,22 @@
+ fenced-clojure
+
+ begin
+ ^(\s*[`~]{3,})\s*(clojure)\s*$
+ end
+ ^(\1)\n
+ name
+ markup.raw.block.markdown markup.raw.block.fenced.markdown
+ patterns
+
+
+ include
+ source.clojure
+
+
+
fenced-undefined
begin
@@ -2187,6 +2203,10 @@
include
#fenced-swift
+
+ include
+ #fenced-clojure
+
include
#fenced-undefined
diff --git a/MultiMarkdown.sublime-settings b/MultiMarkdown.sublime-settings
index 8a098913..03755611 100644
--- a/MultiMarkdown.sublime-settings
+++ b/MultiMarkdown.sublime-settings
@@ -95,5 +95,35 @@
// optionaly, 2
"ol_multi": 1
}
- }
+ },
+
+ // 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
+ // Default keys: (OSX)super+ctrl+shift+l (Linux/Win)ctrl+alt+g
+ "mde.keymap_disable_reference_jump": false,
+ // Add a new link
+ // Default keys: (OSX)super+alt+r (Linux/Win)ctrl+super+r
+ "mde.keymap_disable_reference_new_reference": false,
+ // Add a new inline link
+ // Default keys: (OSX)super+alt+v (Linux/Win)ctrl+super+v
+ "mde.keymap_disable_reference_new_inline_link": false,
+ // Add a new inline image
+ // Default keys: (OSX/Linux/Win)super+shift+k
+ "mde.keymap_disable_reference_new_inline_image": false,
+ // Add a new footnote
+ // Default keys: (OSX/Linux/Win)alt+shift+6
+ "mde.keymap_disable_reference_new_footnote": false,
+ // Fold current section
+ // Default keys: (OSX/Linux/Win)shift+tab
+ "mde.keymap_disable_fold_section": false,
+ // Open a panel showing all functions related to folding
+ // Default keys: (OSX/Linux/Win)ctrl+shift+tab
+ "mde.keymap_disable_show_fold_all_sections": false,
+ // Jump to the next heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pagedown (Linux/Win)ctrl+shift(+alt)+pagedown
+ "mde.keymap_disable_goto_next_heading": false,
+ // Jump to the previous heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pageup (Linux/Win)ctrl+shift(+alt)+pageup
+ "mde.keymap_disable_goto_previous_heading": false
}
diff --git a/README.md b/README.md
index 6a91b4d7..3f8b1b1d 100644
--- a/README.md
+++ b/README.md
@@ -264,33 +264,28 @@ You can support [contributors](https://github.com/SublimeText-Markdown/MarkdownE
MarkdownEditing is released under the [MIT License][opensource].
-[TableEditor]: https://github.com/vkocubinsky/SublimeTableEditor
-[Knockdown]: https://github.com/aziz/knockdown/
-[Sublime Markdown Extended]: https://github.com/jonschlinkert/sublime-markdown-extended
-[SmartMarkdown]: https://github.com/demon386/SmartMarkdown
-[Typewriter]: https://github.com/alehandrof/Typewriter
-[OpenUrl]: https://github.com/noahcoad/open-url
-[brettterpstra]: http://brettterpstra.com
-[geekabouttown]: http://geekabouttown.com/posts/sublime-text-2-markdown-footnote-goodness
[github]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/light.png
[github 2]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/dark.png
[github 3]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/yellow.png
-[github 4]: https://github.com/jngeist
+[wbond]: http://wbond.net/sublime_packages/package_control
+[wbond 2]: http://wbond.net/sublime_packages/package_control/installation
+[GFM]: https://help.github.com/articles/github-flavored-markdown
[github 5]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/underscore-in-words.png
[github 6]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/fenced-code-block.png
[github 7]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/keyboard-shortcut.png
[github 8]: https://raw.github.com/SublimeText-Markdown/MarkdownEditing/master/screenshots/strikethrough.png
-[github 9]: https://github.com/maliayas
-[github 10]: https://github.com/felixhao28
-[opensource]: http://www.opensource.org/licenses/MIT
-[wbond]: http://wbond.net/sublime_packages/package_control
-[wbond 2]: http://wbond.net/sublime_packages/package_control/installation
-[FullScreenStatus]: https://github.com/maliayas/SublimeText_FullScreenStatus
-[macstories]: http://www.macstories.net/roundups/sublime-text-2-and-markdown-tips-tricks-and-links/
-[tips]: https://github.com/SublimeText-Markdown/MarkdownEditing/wiki/Tips
-[Wiki]: https://github.com/SublimeText-Markdown/MarkdownEditing/wiki
-[GFM]: https://help.github.com/articles/github-flavored-markdown
-[#158]: https://github.com/SublimeText-Markdown/MarkdownEditing/issues/158
[linkBlackboardTheme]: https://github.com/mdesantis/MarkdownEditing/blob/blackboard-theme/MarkdownEditor-Blackboard.tmTheme
[mdesantis]: https://github.com/mdesantis
[avivace]: https://github.com/avivace
+[tips]: https://github.com/SublimeText-Markdown/MarkdownEditing/wiki/Tips
+[Wiki]: https://github.com/SublimeText-Markdown/MarkdownEditing/wiki
+[Knockdown]: https://github.com/aziz/knockdown/
+[Sublime Markdown Extended]: https://github.com/jonschlinkert/sublime-markdown-extended
+[SmartMarkdown]: https://github.com/demon386/SmartMarkdown
+[#158]: https://github.com/SublimeText-Markdown/MarkdownEditing/issues/158
+[brettterpstra]: http://brettterpstra.com
+[github 9]: https://github.com/maliayas
+[github 10]: https://github.com/felixhao28
+[github 4]: https://github.com/jngeist
+[geekabouttown]: http://geekabouttown.com/posts/sublime-text-2-markdown-footnote-goodness
+[opensource]: http://www.opensource.org/licenses/MIT
diff --git a/bootstrap.py b/bootstrap.py
index 91fbbfa5..f4411593 100644
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -1,4 +1,11 @@
import sys
+import sublime
+import sublime_plugin
+import re
+try:
+ from MarkdownEditing.mdeutils import *
+except ImportError:
+ from mdeutils import *
package_name = 'MarkdownEditing'
@@ -27,12 +34,99 @@ def enable_native_markdown_package():
save_ingored_packages(ignored_packages)
+def choose_color_theme(window):
+ window = window or sublime.active_window()
+ view = window.new_file()
+ view.run_command('append', {'characters': '''# A sample Markdown document
+
+This is a sample document so you can preview the color themes.
+
+## I am a second-level header
+
+Markdown supports _italics_, __bold__, and ___bold italics___ style.
+
+There are also inline styles like `inline code in monospace font` and ~~strikethrough style~~. __There may be ~~strikethroughed text~~ or `code text` inside bold text.__ _And There may be ~~strikethroughed text~~ or `code text` inside italic text._
+
+To reference something from a URL, [Named Links][links] and [Inline links](https://example.com/index.html) are of great help. Sometimes ![A picture][sample image] is worth a thousand words.
+
+There are two types of lists, numbered and unnumbered.
+
+1. Item 1
+2. Item 2
+3. Item 3
+
+* Item A
+ - Sub list
+ + Sub sub list
+ + Sub sub list 2
+ - Sub list 2
+* Item B
+* Item C
+
+## Fenced code
+
+You can write fenced code inside three backticks.
+
+```javascript
+function fibo(n) {
+ fibo.mem = fibo.mem || []; // I am some comment
+ return fibo.mem[n] || fibo.mem[n] = n <= 1 ? 1 : fibo(n - 1) + fibo(n - 2);
+}
+```
+
+## The following section is used to define named links
+
+[links]: https://example.com/index.html
+[sample image]: https://example.com/sample.png
+'''})
+ 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'
+ print(default_mde_scheme)
+ view.settings().set('color_scheme', default_mde_scheme)
+ view.set_read_only(True)
+ view.set_scratch(True)
+
+ global_scheme = sublime.load_settings('Preferences.sublime-settings').get('color_scheme')
+ themes = ['Packages/MarkdownEditing/MarkdownEditor.tmTheme',
+ 'Packages/MarkdownEditing/MarkdownEditor-Focus.tmTheme',
+ 'Packages/MarkdownEditing/MarkdownEditor-Yellow.tmTheme',
+ 'Packages/MarkdownEditing/MarkdownEditor-Dark.tmTheme',
+ 'Packages/MarkdownEditing/MarkdownEditor-ArcDark.tmTheme',
+ global_scheme]
+
+ themes_display = [re.search('[^/]+(?=\.tmTheme$)', s).group(0) + (' (Current)' if s == default_mde_scheme else '') + (' (Global)' if s == global_scheme else '') for s in themes]
+
+ def set_scheme(scheme):
+ view.settings().set('color_scheme', scheme)
+ sublime.load_settings('Markdown.sublime-settings').set('color_scheme', scheme)
+
+ def on_done(index):
+ if index == -1:
+ set_scheme(default_mde_scheme)
+ elif index == len(themes) - 1:
+ set_scheme(global_scheme)
+ else:
+ set_scheme(themes[index])
+ sublime.save_settings('Markdown.sublime-settings')
+ view.close()
+
+ def on_highlighted(index):
+ if index == len(themes) - 1:
+ set_scheme(global_scheme)
+ else:
+ set_scheme(themes[index])
+
+ window.show_quick_panel(themes_display, on_done, flags=sublime.KEEP_OPEN_ON_FOCUS_LOST, on_highlight=on_highlighted)
+
+
def plugin_loaded():
from package_control import events
if events.install(package_name):
# Native package causes some conflicts.
disable_native_markdown_package()
+ # Prmopts to select a color theme
+ choose_color_theme()
def plugin_unloaded():
@@ -46,3 +140,9 @@ def plugin_unloaded():
if sys.version_info < (3,):
plugin_loaded()
unload_handler = plugin_unloaded
+
+
+class MdeColorActivateCommand(MDETextCommand):
+
+ def run(self, edit):
+ choose_color_theme(self.view.window())
diff --git a/folding.py b/folding.py
index ce637128..8c6270c1 100644
--- a/folding.py
+++ b/folding.py
@@ -28,7 +28,8 @@ def all_headings(view):
title_end = re.search('(' + m.group() + ')?(\n|$)', text[title_begin:]).start() + title_begin
title_begin = m.start()
level = m.end() - m.start()
- yield (title_begin, title_end, level)
+ if 'markup.raw.block.markdown' not in view.scope_name(title_begin).split(' '):
+ yield (title_begin, title_end, level)
def get_current_level(view, p):
@@ -44,6 +45,9 @@ def get_current_level(view, p):
class FoldSectionCommand(MDETextCommand):
+ def description(self):
+ return 'Toggle fold/unfold on current section'
+
def run(self, edit):
view = self.view
sections = []
@@ -75,6 +79,59 @@ def run(self, edit):
view.fold(reg)
sublime.status_message('%d region%s %sfolded' % (len(sections), 's' if len(sections) > 1 else '', 'un' if shouldUnfold else ''))
+class FoldSectionContextCommand(FoldSectionCommand):
+
+ def is_visible(self):
+ if not FoldSectionCommand.is_visible(self):
+ return False
+ view = self.view
+ hasSection = False
+ for sel in view.sel():
+ section_start = -1
+ section_end = view.size()
+ section_level = 0
+ for (title_begin, title_end, level) in all_headings(view):
+ if title_begin <= sel.a:
+ section_start = title_end
+ section_level = level
+ elif section_level >= level:
+ section_end = title_begin - 1
+ break
+ if section_start >= 0 and section_end >= section_start:
+ reg = sublime.Region(section_start, section_end)
+ folded = getFoldedRegion(view, reg)
+ if folded != None:
+ return False
+ else:
+ hasSection = True
+ return hasSection
+
+class UnfoldSectionContextCommand(FoldSectionCommand):
+
+ def is_visible(self):
+ if not FoldSectionCommand.is_visible(self):
+ return False
+ view = self.view
+ hasSection = False
+ for sel in view.sel():
+ section_start = -1
+ section_end = view.size()
+ section_level = 0
+ for (title_begin, title_end, level) in all_headings(view):
+ if title_begin <= sel.a:
+ section_start = title_end
+ section_level = level
+ elif section_level >= level:
+ section_end = title_begin - 1
+ break
+ if section_start >= 0 and section_end >= section_start:
+ reg = sublime.Region(section_start, section_end)
+ folded = getFoldedRegion(view, reg)
+ if folded != None:
+ hasSection = True
+ else:
+ return False
+ return hasSection
class ShowFoldAllSectionsCommand(MDETextCommand):
@@ -113,12 +170,14 @@ def run(self, edit, target_level=0):
view.show(sublime.Region(0, 0))
sublime.status_message('%d region%s folded' % (n_sections, 's' if n_sections > 1 else ''))
+
class UnfoldAllSectionsCommand(MDETextCommand):
def run(self, edit):
view = self.view
view.run_command('unfold_all')
+
class GotoNextHeadingCommand(MDETextCommand):
def run(self, edit, same_level=True):
diff --git a/mdeutils.py b/mdeutils.py
index 9d6d6809..8bbf27be 100644
--- a/mdeutils.py
+++ b/mdeutils.py
@@ -13,3 +13,6 @@ class MDETextCommand(sublime_plugin.TextCommand):
def is_enabled(self):
return view_is_markdown(self.view)
+
+ def is_visible(self):
+ return view_is_markdown(self.view)
diff --git a/messages.json b/messages.json
index e1f466f9..f45e2820 100644
--- a/messages.json
+++ b/messages.json
@@ -15,5 +15,13 @@
"2.1.2": "messages/2.1.2.md",
"2.1.3": "messages/2.1.3.md",
"2.1.4": "messages/2.1.4.md",
- "2.1.5": "messages/2.1.5.md"
+ "2.1.5": "messages/2.1.5.md",
+ "2.1.6": "messages/2.1.6.md",
+ "2.1.7": "messages/2.1.7.md",
+ "2.1.8": "messages/2.1.8.md",
+ "2.1.9": "messages/2.1.9.md",
+ "2.2.0": "messages/2.2.0.md",
+ "2.2.1": "messages/2.2.1.md",
+ "2.2.2": "messages/2.2.2.md",
+ "2.2.3": "messages/2.2.3.md"
}
diff --git a/messages/2.2.3.md b/messages/2.2.3.md
new file mode 100644
index 00000000..e24dc2a9
--- /dev/null
+++ b/messages/2.2.3.md
@@ -0,0 +1,56 @@
+# MarkdownEditing 2.2.3 Changelog
+
+Your _MarkdownEditing_ plugin is updated. Enjoy new version. For any type of
+feedback you can use [GitHub issues][issues].
+
+## Bug Fixes
+
+* Link references commands (Jump/Delete/Organize) now work correctly with no-link `[link text]` style and ignore cases.
+* `[link text]` is now highlighted correctly.
+* Folding correctly ignores fake titles in code blocks.
+
+## New Features
+
+* You can now disable some of the key bindings through configuration. For example, if you want to disable the "shift+tab" => "fold current section" key binding, add `"mde.keymap_disable.fold_section": true` to your user config. For a full list of such key bindings, check the list below.
+* Organize References command now sorts references by referencing order rather than alphebetic order.
+* Code block highlight for clojure.
+* You can use `MarkdownEditing: Change color scheme...` command in command palette to preview and change the color scheme you are using for markdown.
+* Added `MDE: (Un)Fold Section` and `MDE: Jump Reference` to context menu (only appear if applicable based on the cursor's location).
+
+### Configurable Key Bindings
+
+```json
+{
+ // Jump between link/image/footnote reference and definition
+ // Default keys: (OSX)super+ctrl+shift+l (Linux/Win)ctrl+alt+g
+ "mde.keymap_disable.reference_jump": false,
+ // Add a new link
+ // Default keys: (OSX)super+alt+r (Linux/Win)ctrl+super+r
+ "mde.keymap_disable.reference_new_reference": false,
+ // Add a new inline link
+ // Default keys: (OSX)super+alt+v (Linux/Win)ctrl+super+v
+ "mde.keymap_disable.reference_new_inline_link": false,
+ // Add a new inline image
+ // Default keys: (OSX/Linux/Win)super+shift+k
+ "mde.keymap_disable.reference_new_inline_image": false,
+ // Add a new footnote
+ // Default keys: (OSX/Linux/Win)alt+shift+6
+ "mde.keymap_disable.reference_new_footnote": false,
+ // Fold current section
+ // Default keys: (OSX/Linux/Win)shift+tab
+ "mde.keymap_disable.fold_section": false,
+ // Open a panel showing all functions related to folding
+ // Default keys: (OSX/Linux/Win)ctrl+shift+tab
+ "mde.keymap_disable.show_fold_all_sections": false,
+ // Jump to the next heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pagedown (Linux/Win)ctrl+shift(+alt)+pagedown
+ "mde.keymap_disable.goto_next_heading": false,
+ // Jump to the previous heading (any level/same or higher level)
+ // Default keys: (OSX)super+ctrl/shift+pageup (Linux/Win)ctrl+shift(+alt)+pageup
+ "mde.keymap_disable.goto_previous_heading": false
+}
+```
+
+## Changes
+
+[issues]: https://github.com/SublimeText-Markdown/MarkdownEditing/issues
diff --git a/references.py b/references.py
index a4d7504f..11e2ec85 100644
--- a/references.py
+++ b/references.py
@@ -1,6 +1,7 @@
import sublime
import sublime_plugin
import re
+import operator
try:
from MarkdownEditing.mdeutils import *
except ImportError:
@@ -10,6 +11,7 @@
definition_scope_name = "meta.link.reference.def.markdown"
footnote_scope_name = "meta.link.reference.footnote.markdown"
marker_scope_name = "meta.link.reference.markdown"
+marker_literal_scope_name = "meta.link.reference.literal.markdown"
marker_image_scope_name = "meta.image.reference.markdown"
ref_link_scope_name = "markup.underline.link.markdown"
marker_begin_scope_name = "punctuation.definition.string.begin.markdown"
@@ -23,6 +25,12 @@ def hasScope(scope_name, to_find):
return to_find in scope_name.split(" ")
+class Obj(object):
+
+ def __init__(self, **kwargs):
+ self.__dict__.update(kwargs)
+
+
def getMarkers(view, name=''):
# returns {name -> Region}
markers = []
@@ -31,10 +39,12 @@ def getMarkers(view, name=''):
markers.extend(view.find_all(r"(?<=\]\[)([^\]]+)(?=\])", 0)) # ][???]
markers.extend(view.find_all(r"(?<=\[)([^\]]*)(?=\]\[\])", 0)) # [???][]
markers.extend(view.find_all(r"(?<=\[)(\^[^\]]+)(?=\])(?!\s*\]:)", 0)) # [^???]
+ markers.extend(view.find_all(r"(?= 0 and view.substr(sublime.Region(pos, pos + 1)) in '[]':
+ pos -= 1
+ if not (marker_scope_name in scope or marker_image_scope_name in scope or marker_literal_scope_name in scope):
+ return (False, None, None)
+ marker_text_end = findScopeFrom(view, pos, marker_text_end_scope_name) + 1
+ if hasScope(view.scope_name(marker_text_end), refname_start_scope_name) and not hasScope(view.scope_name(marker_text_end + 1), marker_end_scope_name):
+ # of [Text][name] struct
+ marker_pt = marker_text_end + 1
+ marker_pt_end = findScopeFrom(view, marker_pt, marker_end_scope_name)
+ defname = view.substr(sublime.Region(marker_pt, marker_pt_end))
+ else:
+ # of [Text] struct or [Text][] struct
+ defname = view.substr(getCurrentScopeRegion(view, pos))
+ return (True, False, defname)
+ else:
+ return (False, None, None)
+
+
class ReferenceJumpCommand(MDETextCommand):
# reference_jump command
+ def description(self):
+ return 'Jump between definition and reference'
+
def run(self, edit):
view = self.view
edit_regions = []
@@ -112,34 +167,19 @@ def run(self, edit):
missingMarkers = []
missingRefs = []
for sel in view.sel():
- scope = view.scope_name(sel.begin()).split(" ")
- if definition_scope_name in scope or footnote_scope_name in scope:
- if refname_scope_name in scope:
- # Definition name
- defname = view.substr(getCurrentScopeRegion(view, sel.begin()))
- elif refname_start_scope_name in scope:
- # Starting "["
- defname = view.substr(getCurrentScopeRegion(view, sel.begin()+1))
- else:
- # URL or footnote
- marker_pt = findScopeFrom(view, sel.begin(), refname_scope_name, True)
- defname = view.substr(getCurrentScopeRegion(view, marker_pt))
- if defname in markers:
- edit_regions.extend(markers[defname])
- else:
- missingMarkers.append(defname)
- elif marker_scope_name in scope or marker_image_scope_name in scope:
- if refname_scope_name in scope:
- # defname name
- defname = view.substr(getCurrentScopeRegion(view, sel.begin()))
- else:
- # Text
- marker_pt = findScopeFrom(view, sel.begin(), refname_scope_name)
- defname = view.substr(getCurrentScopeRegion(view, marker_pt))
- if defname in refs:
- edit_regions.extend(refs[defname])
+ matched, is_definition, defname = get_reference(view, sel.begin())
+ if matched:
+ defname_key = defname.lower()
+ if is_definition:
+ if defname_key in markers:
+ edit_regions.extend(markers[defname_key].regions)
+ else:
+ missingMarkers.append(defname)
else:
- missingRefs.append(defname)
+ if defname_key in refs:
+ edit_regions.extend(refs[defname_key].regions)
+ else:
+ missingRefs.append(defname)
if len(edit_regions) > 0:
sels = view.sel()
sels.clear()
@@ -155,6 +195,12 @@ def run(self, edit):
sublime.status_message("The definition%s of %s and the marker%s of %s cannot be found." % ("" if len(missingRefs) == 1 else "s", ", ".join(missingRefs), "" if len(missingMarkers) == 1 else "s", ", ".join(missingMarkers)))
+class ReferenceJumpContextCommand(ReferenceJumpCommand):
+
+ def is_visible(self):
+ return ReferenceJumpCommand.is_visible(self) and any(get_reference(self.view, sel.begin())[0] for sel in self.view.sel())
+
+
def is_url(contents):
# Returns if contents contains an URL
re_match_urls = re.compile(r"""((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))*))+(?:(([^\s()<>]+|(([^\s()<>]+)))*)|[^\s`!()[]{};:'".,<>?«»“”‘’]))""", re.DOTALL)
@@ -325,43 +371,34 @@ def run(self, edit):
markers = getMarkers(view)
refs = getReferences(view)
for sel in view.sel():
- scope = view.scope_name(sel.begin()).split(" ")
- if definition_scope_name in scope:
- if refname_scope_name in scope:
- # Definition name
- defname = view.substr(getCurrentScopeRegion(view, sel.begin()))
- elif refname_start_scope_name in scope:
- # Starting "["
- defname = view.substr(getCurrentScopeRegion(view, sel.begin()+1))
- else:
- # URL
- marker_pt = findScopeFrom(view, sel.begin(), refname_scope_name, True)
- defname = view.substr(getCurrentScopeRegion(view, marker_pt))
- elif marker_scope_name in scope or marker_image_scope_name in scope:
- if refname_scope_name in scope:
- # defname name
- defname = view.substr(getCurrentScopeRegion(view, sel.begin()))
- else:
- # Text
- marker_pt = findScopeFrom(view, sel.begin(), refname_scope_name)
- defname = view.substr(getCurrentScopeRegion(view, marker_pt))
- else:
- defname = None
- if defname and defname in markers:
- for marker in markers[defname]:
- if defname[0] == "^":
- edit_regions.append(sublime.Region(marker.begin()-1, marker.end()+1))
- else:
- l = findScopeFrom(view, marker.begin(), marker_begin_scope_name, True)
- if l > 0 and view.substr(sublime.Region(l-1, l)) == "!":
- edit_regions.append(sublime.Region(l-1, l+1))
+ matched, is_definition, defname = get_reference(view, sel.begin())
+ if matched:
+ defname_key = defname.lower()
+ if defname_key in markers:
+ for marker in markers[defname_key].regions:
+ if defname[0] == "^":
+ edit_regions.append(sublime.Region(marker.begin()-1, marker.end()+1))
else:
- edit_regions.append(sublime.Region(l, l+1))
- r = findScopeFrom(view, marker.begin(), marker_text_end_scope_name, True)
- edit_regions.append(sublime.Region(r, marker.end()+1))
- if defname in refs:
- for ref in refs[defname]:
- edit_regions.append(view.full_line(ref.begin()))
+ l = findScopeFrom(view, marker.begin(), marker_begin_scope_name, True)
+ if l > 0 and view.substr(sublime.Region(l-1, l)) == "!":
+ edit_regions.append(sublime.Region(l-1, l+1))
+ else:
+ edit_regions.append(sublime.Region(l, l+1))
+ if hasScope(view.scope_name(marker.end()), marker_text_end_scope_name):
+ if view.substr(sublime.Region(marker.end()+1, marker.end()+2)) == '[':
+ # [Text][]
+ r = findScopeFrom(view, marker.end(), marker_end_scope_name, False)
+ edit_regions.append(sublime.Region(marker.end(), r+1))
+ else:
+ # [Text]
+ edit_regions.append(sublime.Region(marker.end(), marker.end()+1))
+ else:
+ # [Text][name]
+ r = findScopeFrom(view, marker.begin(), marker_text_end_scope_name, True)
+ edit_regions.append(sublime.Region(r, marker.end()+1))
+ if defname_key in refs:
+ for ref in refs[defname_key].regions:
+ edit_regions.append(view.full_line(ref.begin()))
if len(edit_regions) > 0:
sel = view.sel()
@@ -381,29 +418,38 @@ def run(self, edit):
view = self.view
# reorder
+ markers = getMarkers(view)
+ marker_order = sorted(markers.keys(), key=lambda marker: min(markers[marker].regions, key=lambda reg: reg.a).a)
+ marker_order = dict(zip(marker_order, range(0, len(marker_order))))
+
refs = getReferences(view)
flatrefs = []
flatfns = []
sel = view.sel()
sel.clear()
for name in refs:
- for link_reg in refs[name]:
+ for link_reg in refs[name].regions:
line_reg = view.full_line(link_reg)
if name[0] == "^":
- flatfns.append((name, view.substr(line_reg)))
+ flatfns.append((name, view.substr(line_reg).strip("\n")))
else:
- flatrefs.append((name, view.substr(line_reg)))
+ flatrefs.append((name, view.substr(line_reg).strip("\n")))
sel.add(line_reg)
- flatfns.sort(key=lambda r: r[0])
- flatrefs.sort(key=lambda r: r[0])
+
+ flatfns.sort(key=operator.itemgetter(0))
+ flatrefs.sort(key=lambda x: marker_order[x[0].lower()] if x[0].lower() in marker_order else 9999)
+
view.run_command("left_delete")
if view.size() >= 2 and view.substr(sublime.Region(view.size()-2, view.size())) == "\n\n":
view.erase(edit, sublime.Region(view.size()-1, view.size()))
for fn_tuple in flatfns:
view.insert(edit, view.size(), fn_tuple[1])
+ view.insert(edit, view.size(), "\n")
view.insert(edit, view.size(), "\n")
+
for ref_tuple in flatrefs:
view.insert(edit, view.size(), ref_tuple[1])
+ view.insert(edit, view.size(), "\n")
# delete duplicate / report conflict
sel.clear()
@@ -415,14 +461,14 @@ def run(self, edit):
for name in refs:
if name[0] == '^':
continue
- n_links = len(refs[name])
+ n_links = len(refs[name].regions)
if n_links > 1:
- for ref in refs[name]:
+ for ref in refs[name].regions:
link_begin = findScopeFrom(view, ref.end(), ref_link_scope_name)
link = view.substr(getCurrentScopeRegion(view, link_begin))
if name in unique_links:
if link == unique_links[name]:
- output += "%s has duplicate value of %s\n" % (name, link)
+ output += "%s has duplicate value of %s\n" % (refs[name].label, link)
sel.add(view.full_line(ref.begin()))
elif name in conflicts:
conflicts[name].append(link)
@@ -434,28 +480,40 @@ def run(self, edit):
# view.run_command("left_delete")
for name in conflicts:
- output += "%s has conflict values: %s with %s\n" % (name, unique_links[name], ", ".join(conflicts[name]))
+ output += "%s has conflict values: %s with %s\n" % (refs[name].label, unique_links[name], ", ".join(conflicts[name]))
# report missing
refs = getReferences(view)
- markers = getMarkers(view)
+ lower_refs = [ref.lower() for ref in refs]
missings = []
for ref in refs:
- if ref not in markers:
- missings.append(ref)
+ if ref not in marker_order:
+ missings.append(refs[ref].label)
if len(missings) > 0:
- output += "definition [%s] %s no reference\n" % (", ".join(missings), "have" if len(missings) > 1 else "has")
+ output += "Error: Definition [%s] %s no reference\n" % (", ".join(missings), "have" if len(missings) > 1 else "has")
missings = []
for marker in markers:
- if marker not in refs:
- missings.append(marker)
+ if marker not in lower_refs:
+ missings.append(markers[marker].label)
if len(missings) > 0:
- output += "[%s] %s no definition\n" % (", ".join(missings), "have" if len(missings) > 1 else "has")
+ output += "Error: [%s] %s no definition\n" % (", ".join(missings), "have" if len(missings) > 1 else "has")
# sel.clear()
if len(output) == 0:
- output = "All references are well defined:\n" + "\n".join(('[%s]' % m) for m in markers)
+ output = "All references are well defined :)\n"
+
+ output += "===================\n"
+
+ def get_times_string(n):
+ if n == 0:
+ return "0 time"
+ elif n == 1:
+ return "1 time"
+ else:
+ return "%i times" % n
+
+ output += "\n".join(('[%s] is referenced %s' % (markers[m].label, get_times_string(len(markers[m].regions)))) for m in markers)
window = view.window()
output_panel = window.create_output_panel("mde")
@@ -474,8 +532,6 @@ def run(self, edit):
for marker in markers:
if marker not in refs:
missings.append(marker)
- print(refs)
- print(markers)
if len(missings):
# Remove all whitespace at the end of the file
whitespace_at_end = view.find(r'\s*\z', 0)
diff --git a/tests/GFM.md b/tests/GFM.md
index 8c8dc67b..b5ae217d 100644
--- a/tests/GFM.md
+++ b/tests/GFM.md
@@ -140,4 +140,19 @@ Paragraph
}
```
+# Links
+
+[I'm an inline link](http://fakewebsite.com/fakepage)
+![I'm an inline image](http://fakewebsite.com/fakeimg.png)
+[I'm a link][testLink]
+![I'm an image][imageLink]
+[I'm a link literal][]
+[I'm a link literal too]
+[i'm a CASE INSENSITIVE link]
+
[GFM]: https://help.github.com/articles/github-flavored-markdown
+[testLink]: http://fakewebsite.com/fakepage
+[imageLink]: http://fakewebsite.com/fakeimg.png
+[I'm a link literal]: http://fakewebsite.com/fakepage
+[I'm a link literal too]: http://fakewebsite.com/fakepage
+[I'M A case insensitive LINK]: http://fakewebsite.com/fakepage