From cf09e200a57a7487aab874ba706d9fe674e0d7d2 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 5 Mar 2013 14:33:27 -0500 Subject: [PATCH] Moved Markdown out of Discourse.Utilities -> Discourse.Markdown --- .../discourse/components/markdown.js | 188 ++++++++++++++++++ .../discourse/components/utilities.js | 117 +---------- .../discourse/views/composer_view.js | 2 +- .../discourse/views/pagedown_editor.js | 2 +- app/assets/javascripts/pagedown_custom.js | 28 ++- lib/pretty_text.rb | 3 +- spec/javascripts/components/markdown_spec.js | 124 ++++++++++++ spec/javascripts/components/utilities_spec.js | 119 ----------- .../assets/javascripts/discourse_emoji.js | 2 +- 9 files changed, 330 insertions(+), 255 deletions(-) create mode 100644 app/assets/javascripts/discourse/components/markdown.js create mode 100644 spec/javascripts/components/markdown_spec.js diff --git a/app/assets/javascripts/discourse/components/markdown.js b/app/assets/javascripts/discourse/components/markdown.js new file mode 100644 index 000000000..4ede5514c --- /dev/null +++ b/app/assets/javascripts/discourse/components/markdown.js @@ -0,0 +1,188 @@ +/*global sanitizeHtml:true Markdown:true */ + +/** + Contains methods to help us with markdown formatting. + + @class Markdown + @namespace Discourse + @module Discourse +**/ +Discourse.Markdown = { + + /** + Convert a raw string to a cooked markdown string. + + @method cook + @param {String} raw the raw string we want to apply markdown to + @param {Object} opts the options for the rendering + **/ + cook: function(raw, opts) { + if (!opts) opts = {}; + + // Make sure we've got a string + if (!raw) return ""; + if (raw.length === 0) return ""; + + this.converter = this.markdownConverter(opts); + return this.converter.makeHtml(raw); + }, + + /** + Creates a new markdown editor + + @method createNewMarkdownEditor + @param {Markdown.Converter} markdownConverter the converter object + @param {String} idPostfix + @param {Object} options the options for the markdown editor + **/ + createNewMarkdownEditor: function(markdownConverter, idPostfix, options) { + options = options || {}; + options.strings = { + bold: I18n.t("js.composer.bold_title") + " Ctrl+B", + boldexample: I18n.t("js.composer.bold_text"), + + italic: I18n.t("js.composer.italic_title") + " Ctrl+I", + italicexample: I18n.t("js.composer.italic_text"), + + link: I18n.t("js.composer.link_title") + " Ctrl+L", + linkdescription: "enter link description here", + linkdialog: "

" + I18n.t("js.composer.link_dialog_title") + "

http://example.com/ \"" + + I18n.t("js.composer.link_optional_text") + "\"

", + + quote: I18n.t("js.composer.quote_title") + "
Ctrl+Q", + quoteexample: I18n.t("js.composer.quote_text"), + + code: I18n.t("js.composer.code_title") + "
 Ctrl+K",
+      codeexample: I18n.t("js.composer.code_text"),
+
+      image: I18n.t("js.composer.image_title") + "  Ctrl+G",
+      imagedescription: I18n.t("js.composer.image_description"),
+      imagedialog: "

" + I18n.t("js.composer.image_dialog_title") + "

http://example.com/images/diagram.jpg \"" + + I18n.t("js.composer.image_optional_text") + "\"

" + I18n.t("js.composer.image_hosting_hint") + "

", + + olist: I18n.t("js.composer.olist_title") + "
    Ctrl+O", + ulist: I18n.t("js.composer.ulist_title") + "