how to allow html tag in redmine wiki

Added by Tuan-Tu Tran 10 months 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 (4)

RE: how to allow html tag in redmine wiki - Added by Ivan Cenov 10 months 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 10 months 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 9 months 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 4 months 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

(1-4/4)