Permalink
Browse files

add markdown editing mode

  • Loading branch information...
1 parent 1019cef commit 4ea0cc45f2bf9cf4b03906562538598bd1bb243d @jjallaire jjallaire committed Apr 5, 2012
Showing with 273 additions and 3 deletions.
  1. +6 −0 package/win32/CMakeLists.txt
  2. +14 −0 src/cpp/desktop/Info.plist.in
  3. BIN src/cpp/desktop/resources/freedesktop/icons/128x128/text-x-markdown.png
  4. BIN src/cpp/desktop/resources/freedesktop/icons/16x16/text-x-markdown.png
  5. BIN src/cpp/desktop/resources/freedesktop/icons/24x24/text-x-markdown.png
  6. BIN src/cpp/desktop/resources/freedesktop/icons/256x256/text-x-markdown.png
  7. BIN src/cpp/desktop/resources/freedesktop/icons/32x32/text-x-markdown.png
  8. BIN src/cpp/desktop/resources/freedesktop/icons/48x48/text-x-markdown.png
  9. BIN src/cpp/desktop/resources/freedesktop/icons/512x512/text-x-markdown.png
  10. BIN src/cpp/desktop/resources/freedesktop/icons/64x64/text-x-markdown.png
  11. +2 −1 src/cpp/desktop/resources/freedesktop/rstudio.desktop.in
  12. +47 −0 src/gwt/acesupport/acemode/markdown.js
  13. +134 −0 src/gwt/acesupport/acemode/markdown_highlight_rules.js
  14. +2 −0 src/gwt/build.xml
  15. +1 −0 src/gwt/src/org/rstudio/studio/client/common/filetypes/FileIconResources.java
  16. +1 −0 src/gwt/src/org/rstudio/studio/client/common/filetypes/FileTypeCommands.java
  17. +7 −0 src/gwt/src/org/rstudio/studio/client/common/filetypes/FileTypeRegistry.java
  18. +54 −0 src/gwt/src/org/rstudio/studio/client/common/filetypes/MarkdownFileType.java
  19. BIN src/gwt/src/org/rstudio/studio/client/common/filetypes/iconMarkdown.png
  20. +2 −0 src/gwt/src/org/rstudio/studio/client/common/reditor/EditorLanguage.java
  21. +3 −2 src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java
@@ -35,6 +35,9 @@ set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
WriteRegStr HKCR '.Rnw\\\\OpenWithList\\\\rstudio.exe' '' ''
WriteRegStr HKCR '.Rproj\\\\OpenWithList\\\\rstudio.exe' '' ''
WriteRegStr HKCR '.tex\\\\OpenWithList\\\\rstudio.exe' '' ''
+ WriteRegStr HKCR '.md\\\\OpenWithList\\\\rstudio.exe' '' ''
+ WriteRegStr HKCR '.mdtxt\\\\OpenWithList\\\\rstudio.exe' '' ''
+ WriteRegStr HKCR '.markdown\\\\OpenWithList\\\\rstudio.exe' '' ''
WriteRegStr HKCR '.Rproj' '' 'RStudio.Rproj'
WriteRegStr HKCR 'RStudio.Rproj' '' 'R Project'
@@ -54,6 +57,9 @@ set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
DeleteRegKey HKCR '.Rnw\\\\OpenWithList\\\\rstudio.exe'
DeleteRegKey HKCR '.Rproj\\\\OpenWithList\\\\rstudio.exe'
DeleteRegKey HKCR '.tex\\\\OpenWithList\\\\rstudio.exe'
+ DeleteRegKey HKCR '.md\\\\OpenWithList\\\\rstudio.exe'
+ DeleteRegKey HKCR '.mdtxt\\\\OpenWithList\\\\rstudio.exe'
+ DeleteRegKey HKCR '.markdown\\\\OpenWithList\\\\rstudio.exe'
DeleteRegKey HKCR 'RStudio.Rproj'
#")
@@ -101,6 +101,20 @@
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
+ <string>md</string>
+ <string>mdtxt</string>
+ <string>markdown</string>
+ </array>
+ <key>CFBundleTypeIconFile</key>
+ <string>Markdown.icns</string>
+ <key>CFBundleTypeName</key>
+ <string>Markdown File</string>
+ <key>CFBundleTypeRole</key>
+ <string>Editor</string>
+ </dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -5,5 +5,6 @@ Type=Application
Terminal=false
Name=RStudio
Categories=Development
-MimeType=text/x-r-source;text/x-r;text-x-R;text/x-r-doc;text/x-r-sweave;application/x-r-data;application/x-r-project;text/x-r-history;text/x-r-profile;text/x-tex
+MimeType=text/x-r-source;text/x-r;text-x-R;text/x-r-doc;text/x-r-sweave;application/x-r-data;application/x-r-project;text/x-r-history;text/x-r-profile;text/x-tex;text/x-markdown;
+
@@ -0,0 +1,47 @@
+/*
+ * markdown.js
+ *
+ * Copyright (C) 2009-11 by RStudio, Inc.
+ *
+ * The Initial Developer of the Original Code is
+ * Ajax.org B.V.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+
+define("mode/markdown", function(require, exports, module) {
+
+var oop = require("ace/lib/oop");
+var TextMode = require("ace/mode/text").Mode;
+var Tokenizer = require("ace/tokenizer").Tokenizer;
+var MarkdownHighlightRules = require("mode/markdown_highlight_rules").MarkdownHighlightRules;
+
+var Mode = function() {
+ this.$tokenizer = new Tokenizer(new MarkdownHighlightRules().getRules());
+};
+oop.inherits(Mode, TextMode);
+
+(function() {
+ this.getNextLineIndent = function(state, line, tab) {
+ if (state == "listblock") {
+ var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
+ if (match) {
+ return new Array(match[1].length + 1).join(" ") + match[2];
+ } else {
+ return "";
+ }
+ } else {
+ return this.$getIndent(line);
+ }
+ };
+}).call(Mode.prototype);
+
+exports.Mode = Mode;
+});
@@ -0,0 +1,134 @@
+/*
+ * markdown_highlight_rules.js
+ *
+ * Copyright (C) 2009-11 by RStudio, Inc.
+ *
+ * The Initial Developer of the Original Code is
+ * Ajax.org B.V.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+define("mode/markdown_highlight_rules", function(require, exports, module) {
+
+var oop = require("ace/lib/oop");
+var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
+
+var MarkdownHighlightRules = function() {
+
+ // regexp must not have capturing parentheses
+ // regexps are ordered -> the first match is used
+
+ this.$rules = {
+ "start" : [ {
+ token : "empty_line",
+ regex : '^$'
+ }, { // code span `
+ token : "support.function",
+ regex : "(`+)([^\\r]*?[^`])(\\1)"
+ }, { // code block
+ token : "support.function",
+ regex : "^[ ]{4}.+"
+ }, { // h1
+ token: "markup.heading.1",
+ regex: "^=+(?=\\s*$)"
+ }, { // h2
+ token: "markup.heading.1",
+ regex: "^\\-+(?=\\s*$)"
+ }, { // header
+ token : function(value) {
+ return "markup.heading." + value.length;
+ },
+ regex : "^#{1,6}"
+ },
+ { // Github style block
+ token : "support.function",
+ regex : "^```[a-zA-Z]+\\s*$",
+ next : "githubblock"
+ }, { // block quote
+ token : "string",
+ regex : "^>[ ].+$",
+ next : "blockquote"
+ }, { // reference
+ token : ["text", "constant", "text", "url", "string", "text"],
+ regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?\\s*)$"
+ }, { // link by reference
+ token : ["text", "string", "text", "constant", "text"],
+ regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])"
+ }, { // link by url
+ token : ["text", "string", "text", "markup.underline", "string", "text"],
+ regex : "(\\[)"+
+ "(\\[[^\\]]*\\]|[^\\[\\]]*)"+
+ "(\\]\\([ \\t]*)"+
+ "(<?(?:(?:[^\\(]*?\\([^\\)]*?\\)\\S*?)|(?:.*?))>?)"+
+ "((?:[ \t]*\"(?:.*?)\"[ \\t]*)?)"+
+ "(\\))"
+ }, { // HR *
+ token : "constant",
+ regex : "^[ ]{0,2}(?:[ ]?\\*[ ]?){3,}\\s*$"
+ }, { // HR -
+ token : "constant",
+ regex : "^[ ]{0,2}(?:[ ]?\\-[ ]?){3,}\\s*$"
+ }, { // HR _
+ token : "constant",
+ regex : "^[ ]{0,2}(?:[ ]?\\_[ ]?){3,}\\s*$"
+ }, { // list
+ token : "markup.list",
+ regex : "^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+",
+ next : "listblock"
+ }, { // strong ** __
+ token : "string",
+ regex : "([*]{2}|[_]{2}(?=\\S))([^\\r]*?\\S[*_]*)(\\1)"
+ }, { // emphasis * _
+ token : "string",
+ regex : "([*]|[_](?=\\S))([^\\r]*?\\S[*_]*)(\\1)"
+ }, { //
+ token : ["text", "url", "text"],
+ regex : "(<)("+
+ "(?:https?|ftp|dict):[^'\">\\s]+"+
+ "|"+
+ "(?:mailto:)?[-.\\w]+\\@[-a-z0-9]+(?:\\.[-a-z0-9]+)*\\.[a-z]+"+
+ ")(>)"
+ }, {
+ token : "text",
+ regex : "[^\\*_%$`\\[#<>]+"
+ } ],
+
+ "listblock" : [ { // Lists only escape on completely blank lines.
+ token : "empty_line",
+ regex : "^$",
+ next : "start"
+ }, {
+ token : "markup.list",
+ regex : ".+"
+ } ],
+
+ "blockquote" : [ { // BLockquotes only escape on blank lines.
+ token : "empty_line",
+ regex : "^\\s*$",
+ next : "start"
+ }, {
+ token : "string",
+ regex : ".+"
+ } ],
+
+ "githubblock" : [ {
+ token : "support.function",
+ regex : "^```",
+ next : "start"
+ }, {
+ token : "support.function",
+ regex : ".+"
+ } ]
+ };
+};
+oop.inherits(MarkdownHighlightRules, TextHighlightRules);
+
+exports.MarkdownHighlightRules = MarkdownHighlightRules;
+});
View
@@ -56,6 +56,8 @@
<file name="sweave.js"/>
<file name="rdoc_highlight_rules.js"/>
<file name="rdoc.js"/>
+ <file name="markdown_highlight_rules.js"/>
+ <file name="markdown.js"/>
</sources>
<sources dir="acesupport/acetheme">
<file name="default.js"/>
@@ -34,6 +34,7 @@
ImageResource iconRprofile();
ImageResource iconTex();
ImageResource iconText();
+ ImageResource iconMarkdown();
ImageResource iconRsweave();
ImageResource iconRd();
ImageResource iconSourceViewer();
@@ -45,6 +45,7 @@ public FileTypeCommands(EventBus eventBus, Commands commands)
commands_ = commands;
addType(FileTypeRegistry.TEXT, "_Text File");
+ addType(FileTypeRegistry.MARKDOWN, "_Markdown File");
addType(FileTypeRegistry.TEX, "Te_X Document");
addType(FileTypeRegistry.RD, "R _Documentation");
}
@@ -60,6 +60,10 @@
ICONS.iconRhistory(),
true);
+ public static final MarkdownFileType MARKDOWN =
+ new MarkdownFileType("markdown", "Markdown", EditorLanguage.LANG_MARKDOWN,
+ ".md", ICONS.iconMarkdown());
+
public static final RDataType RDATA = new RDataType();
public static final RProjectType RPROJECT = new RProjectType();
@@ -98,6 +102,9 @@ public FileTypeRegistry(EventBus eventBus,
register("*.sty", TEX, icons.iconTex());
register("*.cls", TEX, icons.iconTex());
register("*.bbl", TEX, icons.iconTex());
+ register("*.md", MARKDOWN, icons.iconMarkdown());
+ register("*.mdtxt", MARKDOWN, icons.iconMarkdown());
+ register("*.markdown", MARKDOWN, icons.iconMarkdown());
register("*.bib", TEXT, icons.iconText());
register("*.c", TEXT, icons.iconText());
register("*.cpp", TEXT, icons.iconText());
@@ -0,0 +1,54 @@
+/*
+ * MarkdownFileType.java
+ *
+ * Copyright (C) 2009-11 by RStudio, Inc.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+package org.rstudio.studio.client.common.filetypes;
+
+import com.google.gwt.resources.client.ImageResource;
+import org.rstudio.core.client.command.AppCommand;
+import org.rstudio.studio.client.common.reditor.EditorLanguage;
+import org.rstudio.studio.client.workbench.commands.Commands;
+
+import java.util.HashSet;
+
+public class MarkdownFileType extends TextFileType
+{
+ MarkdownFileType(String id,
+ String label,
+ EditorLanguage editorLanguage,
+ String defaultExtension,
+ ImageResource icon)
+ {
+ super(id,
+ label,
+ editorLanguage,
+ defaultExtension,
+ icon,
+ true, // word-wrap
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false);
+ }
+
+
+ @Override
+ public HashSet<AppCommand> getSupportedCommands(Commands commands)
+ {
+ HashSet<AppCommand> result = super.getSupportedCommands(commands);
+
+ return result;
+ }
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -37,6 +37,8 @@
"mode/sweave", true);
public static final EditorLanguage LANG_PLAIN = new EditorLanguage(
"ace/mode/text", false);
+ public static final EditorLanguage LANG_MARKDOWN = new EditorLanguage(
+ "mode/markdown", false);
/**
*
@@ -502,10 +502,11 @@ public void onCursorChanged(CursorChangedEvent event)
statusBarFileTypes_ = new TextFileType[] {
FileTypeRegistry.R,
- FileTypeRegistry.TEXT,
FileTypeRegistry.SWEAVE,
- FileTypeRegistry.RD,
+ FileTypeRegistry.TEXT,
+ FileTypeRegistry.MARKDOWN,
FileTypeRegistry.TEX,
+ FileTypeRegistry.RD
};
for (TextFileType fileType : statusBarFileTypes_)

0 comments on commit 4ea0cc4

Please sign in to comment.