Project

General

Profile

Actions

Feature #20620

closed

Add data-text-formatting attribute for selected markup language to body tag

Added by Felix Schäfer over 8 years ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Text formatting
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

(I looked in trunk for a solution and in the issues for a request but couldn't find anything, I'm sorry if this is a duplicate or already solved)

We (plan.io) currently add 2 buttons to the wiki toolbar, one as described in #14937 and another from a plugin, which insert markup-sensitive content to the edited text. Those buttons are added from included javascript files, there currently is no easy way to find out which markup is selected from the js.

Knowing the markup used in the js would allow setting the correct markup/function for the added buttons directly in the js.

While there are a few other possibilities to achieve this (load different js files from the plugins depending on the selected markup, this adds complexity on the js side either because of duplication, loading 2 files for the markup-specific and common code, and so on).

The simplest change we could come up with would be to add a line similar to:

javascript_tag("var wikiMarkup = 'textile';") +

to source:/tags/3.1.0/lib/redmine/wiki_formatting/textile/helper.rb#L35, the same for markdown.

Is this something that could be added to Redmine, or how should markup-dependent javascript be handled? Thanks.


Files

20620.patch (1.15 KB) 20620.patch Go MAEDA, 2023-11-17 01:58
Actions #1

Updated by Felix Schäfer over 8 years ago

Whoops, seems I used opening instead of closing tags at the end of the code line, sorry (which also shows how the code button proposed in #14937 could be helpful :-) )

Actions #2

Updated by Etienne Massip over 8 years ago

  • Description updated (diff)
Actions #3

Updated by Etienne Massip over 8 years ago

This should not be done in a specific markup helper.

This should not be a global variable, could be stored e.g. as a data-markup-language attribute on textarea component.

Actions #4

Updated by Felix Schäfer over 8 years ago

Thanks for correcting the description.

A data attribute on text areas would probably work too.

Actions #5

Updated by Go MAEDA 4 months ago

Since the text formatting is set at the application level, not per textarea, I think adding a new attribute to 'body' is enough.

diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index bcd6622a7..16a640267 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -17,7 +17,7 @@
 <!-- page specific tags -->
 <%= yield :header_tags -%>
 </head>
-<body class="<%= body_css_classes %>">
+<body class="<%= body_css_classes %>" data-text-formatting="<%= Setting.text_formatting %>">
 <%= call_hook :view_layouts_base_body_top %>
 <div id="wrapper">

Actions #6

Updated by Go MAEDA 4 months ago

Here is a patch to introduce a data-text-formatting attribute to the <body> tag.

Actions #7

Updated by Felix Schäfer 4 months ago

Thank you. I think this should also be helpful for our use-case.

We look forward to this being added to core Redmine.

Actions #8

Updated by Go MAEDA 4 months ago

  • Subject changed from Add javascript variable for selected markup language to Add data-text-formatting attribute for selected markup language to body tag
  • Target version set to 6.0.0

Setting the target version to 6.0.0.

Actions #9

Updated by Go MAEDA 4 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch in r22472.

Actions

Also available in: Atom PDF