Project

General

Profile

how to allow html tag in redmine wiki

Added by Tuan-Tu Tran about 6 years ago

Hello,

My wiki settings are such that it uses Markdown (and not Textile) formatting.

My goal here is to be able to color text.

I found in the user guide for markdown formatting
that html tags must be allowed for this to work:

Note: HTML tags need to be allowed to use the HTML tag (<span>). See #15520-16 and #15520-17 for details.

I went over the linked issues but I only saw warnings on why this should not be done for security reasons.
I have to admit I did not read the entire issues.

At the top of the user guide it also says:

Currently HTML tags are not allowed by default. See #15520 and #20497 for details. For other limitations of the current Markdown formatting see #16373 and #21443.

But I can't find how to allow HTML tags.
Is there a configuration/setting for this ?

Or does the code need to be patched e.g. https://www.redmine.org/projects/redmine/repository/revisions/14449/entry/trunk/lib/redmine/wiki_formatting/markdown/formatter.rb#L122

Thanks in advance for your help.


Replies (6)

RE: how to allow html tag in redmine wiki - Added by Ivan Cenov about 6 years ago

You may use macro html this way:

{{html
your html content
}}
Example
before html
{{html
<b>this is bold</b> <i>this is italic</i> This is normal
}}after html

The macro should be inserted in <path_to_redmine>/lib/redmine/wiki_formatting/macros.rb somewhere among other macros there:

      desc "Insert html" + "\n\n" +
           "  !{{html\n<HTML CODE HERE>\n}}" 
      macro :html do |obj, args, text|
        text.html_safe
      end
Don't forget to restart Redmine.

RE: how to allow html tag in redmine wiki - Added by Tuan-Tu Tran about 6 years ago

Hello

Thank you for your answer.

However I was hoping for something more integrated with the markdown, as described here in the user documentation:
https://www.redmine.org/projects/redmine/wiki/RedmineTextFormattingMarkdown#Color

with an html macro as you proposed, I guess I'd have to do things like:

{{html
<ul>
<li> <span style="color:red">red</span> <span style="color:green">green</span>  </li>
<li> ... </li>
</ul>
}}

to achieve the same list, which is much less convenient.

The note in the user documentation

Note: HTML tags need to be allowed to use the HTML tag (<span>). See #15520-16 and #15520-17 for details.

suggests there's a straightforward way to just allow the HTML tag <span>

I just can't seem to find it and that was more the object of my initial question.

Thanks again.

RE: how to allow html tag in redmine wiki - Added by Tuan-Tu Tran about 6 years ago

Hello,

I'm bumping up this question.

I hope someone can help.

Thanks!

RE: how to allow html tag in redmine wiki - Added by Odare Abisam Odare over 5 years ago

Hi!

You can change it here

redmine/lib/redmine/wiki_formatting/markdown/formatter.rb

I changed the boolean from true to false for filter_html

 def formatter
          @@formatter ||= Redcarpet::Markdown.new(
            Redmine::WikiFormatting::Markdown::HTML.new(
              :filter_html => false,
              :hard_wrap => true
            ),
            :autolink => true,
            :fenced_code_blocks => true,
            :space_after_headers => true,
            :tables => true,
            :strikethrough => true,
            :superscript => true,
            :no_intra_emphasis => true,
            :footnotes => true,
            :lax_spacing => true,
            :underline => true
          )
        end

Then restart redmine

RE: how to allow html tag in redmine wiki - Added by Tuan-Tu Tran over 4 years ago

Thanks.

I've updated the documentation accordingly:
https://www.redmine.org/projects/redmine/wiki/RedmineTextFormattingMarkdown/diff?utf8=%E2%9C%93&version=26&version_from=24&commit=View+differences

Now that I re-read this, it was indeed pointed out in #15520#note-16 but it was not very explicit:

For the Markdown implementation see source:/trunk/lib/redmine/wiki_formatting/markdown/formatter.rb@14449#L122, which tells the Redcarpet gem to filter out any HTML from the user input completely.

RE: how to allow html tag in redmine wiki - Added by Dennis Bindernagel about 2 years ago

Can someone please also post a solution for the "CommonMark Markdown (Github Flavored) - experimental" formatter.
The mentioned file looks completely different and I am lost at to what needs to be changed. Thank you!

(I'm switching from Textile to Markdown and from what I gathered the new "CommonMark Markdown" will eventually become the default Markdown "flavour" for Redmine. So I want to directly use it instead of the current "default" Markdown.)

    (1-6/6)