From: Marius Balteanu Date: Tue, 4 Jan 2022 18:57:00 +0000 (+0000) Subject: Makes Markdown and CommonMark formatters independent of each other (#32424). X-Git-Tag: 5.0.0~123 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2140b7c5a533b3125a9f31233432e4f600b6dee2;p=redmine.git Makes Markdown and CommonMark formatters independent of each other (#32424). git-svn-id: http://svn.redmine.org/redmine/trunk@21345 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/wiki_formatting/common_mark/helper.rb b/lib/redmine/wiki_formatting/common_mark/helper.rb index 555c5999a..5d3141c26 100644 --- a/lib/redmine/wiki_formatting/common_mark/helper.rb +++ b/lib/redmine/wiki_formatting/common_mark/helper.rb @@ -21,8 +21,6 @@ module Redmine module WikiFormatting module CommonMark module Helper - include Redmine::WikiFormatting::Markdown::Helper - def wikitoolbar_for(field_id, preview_url = preview_text_path) heads_for_wiki_formatter help_file = "/help/#{current_language.to_s.downcase}/wiki_syntax_common_mark.html" @@ -40,15 +38,30 @@ module Redmine ) end - # removes the 'underline' icon from the markdown toolbar since there - # is no such thing in CommonMark + def initial_page_content(page) + "# #{@page.pretty_title}" + end + def heads_for_wiki_formatter - unless @common_mark_heads_for_wiki_formatter_included - super + unless @heads_for_wiki_formatter_included + toolbar_language_options = User.current && User.current.pref.toolbar_language_options + lang = + if toolbar_language_options.nil? + UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS + else + toolbar_language_options.split(',') + end content_for :header_tags do - javascript_tag(%[delete jsToolBar.prototype.elements.ins;]) + javascript_include_tag('jstoolbar/jstoolbar') + + javascript_include_tag('jstoolbar/common_mark') + + javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") + + javascript_tag( + "var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" \ + "var userHlLanguages = #{lang.to_json};" + ) + + stylesheet_link_tag('jstoolbar') end - @common_mark_heads_for_wiki_formatter_included = true + @heads_for_wiki_formatter_included = true end end end diff --git a/public/javascripts/jstoolbar/common_mark.js b/public/javascripts/jstoolbar/common_mark.js new file mode 100644 index 000000000..a1b1fd599 --- /dev/null +++ b/public/javascripts/jstoolbar/common_mark.js @@ -0,0 +1,236 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * This file is part of DotClear. + * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All + * rights reserved. + * + * DotClear is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DotClear is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DotClear; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * ***** END LICENSE BLOCK ***** +*/ + +/* Modified by JP LANG for markdown formatting */ + +// strong +jsToolBar.prototype.elements.strong = { + type: 'button', + title: 'Strong', + shortcut: 'b', + fn: { + wiki: function() { this.singleTag('**') } + } +} + +// em +jsToolBar.prototype.elements.em = { + type: 'button', + title: 'Italic', + shortcut: 'i', + fn: { + wiki: function() { this.singleTag("*") } + } +} + +// del +jsToolBar.prototype.elements.del = { + type: 'button', + title: 'Deleted', + fn: { + wiki: function() { this.singleTag('~~') } + } +} + +// code +jsToolBar.prototype.elements.code = { + type: 'button', + title: 'Code', + fn: { + wiki: function() { this.singleTag('`') } + } +} + +// spacer +jsToolBar.prototype.elements.space1 = {type: 'space'} + +// headings +jsToolBar.prototype.elements.h1 = { + type: 'button', + title: 'Heading 1', + fn: { + wiki: function() { + this.encloseLineSelection('# ', '',function(str) { + str = str.replace(/^#+\s+/, '') + return str; + }); + } + } +} +jsToolBar.prototype.elements.h2 = { + type: 'button', + title: 'Heading 2', + fn: { + wiki: function() { + this.encloseLineSelection('## ', '',function(str) { + str = str.replace(/^#+\s+/, '') + return str; + }); + } + } +} +jsToolBar.prototype.elements.h3 = { + type: 'button', + title: 'Heading 3', + fn: { + wiki: function() { + this.encloseLineSelection('### ', '',function(str) { + str = str.replace(/^#+\s+/, '') + return str; + }); + } + } +} + +// spacer +jsToolBar.prototype.elements.space2 = {type: 'space'} + +// ul +jsToolBar.prototype.elements.ul = { + type: 'button', + title: 'Unordered list', + fn: { + wiki: function() { + this.encloseLineSelection('','',function(str) { + str = str.replace(/\r/g,''); + return str.replace(/(\n|^)[#-]?\s*/g,"$1* "); + }); + } + } +} + +// ol +jsToolBar.prototype.elements.ol = { + type: 'button', + title: 'Ordered list', + fn: { + wiki: function() { + this.encloseLineSelection('','',function(str) { + str = str.replace(/\r/g,''); + return str.replace(/(\n|^)[*-]?\s*/g,"$11. "); + }); + } + } +} + +// spacer +jsToolBar.prototype.elements.space3 = {type: 'space'} + +// bq +jsToolBar.prototype.elements.bq = { + type: 'button', + title: 'Quote', + fn: { + wiki: function() { + this.encloseLineSelection('','',function(str) { + str = str.replace(/\r/g,''); + return str.replace(/(\n|^)( *)([^\n]*)/g,"$1> $2$3"); + }); + } + } +} + +// unbq +jsToolBar.prototype.elements.unbq = { + type: 'button', + title: 'Unquote', + fn: { + wiki: function() { + this.encloseLineSelection('','',function(str) { + str = str.replace(/\r/g,''); + return str.replace(/(\n|^) *(> ?)?( *)([^\n]*)/g,"$1$3$4"); + }); + } + } +} + +// table +jsToolBar.prototype.elements.table = { + type: 'button', + title: 'Table', + fn: { + wiki: function() { + var This = this; + this.tableMenu(function(cols, rowCount){ + This.encloseLineSelection( + '|'+cols.join(' |')+' |\n' + // header + Array(cols.length+1).join('|--')+'|\n' + // second line + Array(rowCount+1).join(Array(cols.length+1).join('| ')+'|\n') // cells + ); + }); + } + } +} + +// pre +jsToolBar.prototype.elements.pre = { + type: 'button', + title: 'Preformatted text', + fn: { + wiki: function() { this.encloseLineSelection('```\n', '\n```') } + } +} + +// Code highlighting +jsToolBar.prototype.elements.precode = { + type: 'button', + title: 'Highlighted code', + fn: { + wiki: function() { + var This = this; + this.precodeMenu(function(lang){ + This.encloseLineSelection('``` ' + lang + '\n', '\n```\n'); + }); + } + } +} + +// spacer +jsToolBar.prototype.elements.space4 = {type: 'space'} + +// wiki page +jsToolBar.prototype.elements.link = { + type: 'button', + title: 'Wiki link', + fn: { + wiki: function() { this.encloseSelection("[[", "]]") } + } +} +// image +jsToolBar.prototype.elements.img = { + type: 'button', + title: 'Image', + fn: { + wiki: function() { this.encloseSelection("![](", ")") } + } +} + +// spacer +jsToolBar.prototype.elements.space5 = {type: 'space'} +// help +jsToolBar.prototype.elements.help = { + type: 'button', + title: 'Help', + fn: { + wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') } + } +}