/*
 * 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/rmarkdown", function(require, exports, module) {

var oop = require("ace/lib/oop");
var MarkdownMode = require("ace/mode/markdown").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var SweaveBackgroundHighlighter = require("mode/sweave_background_highlighter").SweaveBackgroundHighlighter;
var RMarkdownHighlightRules = require("mode/rmarkdown_highlight_rules").RMarkdownHighlightRules;

var Mode = function(suppressHighlighting, doc, session) {
   this.$tokenizer = new Tokenizer(new RMarkdownHighlightRules().getRules());
   this.$sweaveBackgroundHighlighter = new SweaveBackgroundHighlighter(
         session,
         /^`{3,}\s*\{r(?:.*)\}\s*$/,
         /^`{3,}\s*$/);
};
oop.inherits(Mode, MarkdownMode);

(function() {
}).call(Mode.prototype);

exports.Mode = Mode;
});

@@ -813,24 +813,121 @@
 .Tokenizer;%0A
+var RMarkdownHighlightRules = require(%22mode/rmarkdown_highlight_rules%22).RMarkdownHighlightRules;%0A
 var SweaveBa
@@ -1032,98 +1032,59 @@
 ar R
-MarkdownHighlightRules = require(%22mode/rmarkdown_highlight_rules%22).RMarkdownHighlightRules
+CodeModel = require(%22mode/r_code_model%22).RCodeModel
 ;%0A%0Av
@@ -1217,16 +1217,121 @@
 ules());
+%0A%0A   this.codeModel = new RCodeModel(doc, this.$tokenizer, /%5Er-/);%0A   this.foldingRules = this.codeModel;
 %0A   this

Add folding for markdown