プロジェクト

全般

プロフィール

Vote #64964

完了

Let macros optionally match over multiple lines and ignore single curly braces

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Text formatting_26
対象バージョン:
開始日:
2009/03/27
期日:
進捗率:

0%

予定工数:
category_id:
26
version_id:
47
issue_org_id:
3061
author_id:
4708
assigned_to_id:
1
comments:
16
status_id:
5
tracker_id:
2
plus1:
1
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

Hi,
please modify the regex to match the wiki macros in source:trunk/lib/redmine/wiki_formatting/textile/formatter.rb. With this version the regex matches options with multiple lines and closing curly braces in it. I use this in the wiki_latex_plugin.

Thx,
Nils

        MACROS_RE = /
                      (!)?                        # escaping
                      (
                      \{\{                        # opening tag
                      ([\w]+)                     # macro name
                      (\((.*?)\))?             # optional arguments
                      \}\}                        # closing tag
                      )
                    /xm unless const_defined?(:MACROS_RE)

journals

Note that this is now in:
lib/redmine/wiki_formatting.rb and not down in the textile specific code...
--------------------------------------------------------------------------------
It seems in current trunk it is still not included? Is there anything wrong with the proposed regex?
--------------------------------------------------------------------------------
Looks ok, but why do the actual RE has such a limitation preventing a closing curly brace to be present in the argument list ?

(source:trunk/lib/redmine/wiki_formatting.rb#L74)
--------------------------------------------------------------------------------
I'm not sure, if this is the main "issue" - but there are quite some macro-plugins out there, which need support for multiline macros (e.g. http://www.redmine.org/boards/3/topics/10649 or also the graphviz-plugin could benefit from it).

Currently they only work by patching multiple redmine files (if I understood the docu of those plugins correctly). They usually work all the same: an external tool generates an image. The "recipe" how to bake this image is inside a multi-line macro. I like this approach, as it allows to extend redmine in a very flexible way.
--------------------------------------------------------------------------------
There is no MACROS_RE = line on Redmine 1.3. Has anyone managed to make the plugin work with redmine 1.3?

thanks!
--------------------------------------------------------------------------------
An alternative to using this plugin, is using MathJax: https://github.com/process91/redmine_latex_mathjax

Just installed it on Redmine 1.3 stable and it works fine.
--------------------------------------------------------------------------------
+1

--------------------------------------------------------------------------------
In Redmine 1.3, MACROS_RE is defined in redmine/app/helpers/application_helper.rb
--------------------------------------------------------------------------------
Looks like it has been fixed with r10178, could you please confirm?
--------------------------------------------------------------------------------
Etienne Massip wrote:
> Looks like it has been fixed with r10178, could you please confirm?

No, the regexp does not match multiple lines (no @m@ modifier). The problem with passing a block of text to a macro is that it would be processed by all previous parsers (textile, redmine links...) and has a lot of chances to be altered. To make this feature work nicely, we should prevent that.
--------------------------------------------------------------------------------
Indeed, I missed the modifier (you committed the "allow curly braces as argument" part, still).

Wouldn't it make sense to parse macro tags first?

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Etienne Massip wrote:
> Wouldn't it make sense to parse macro tags first?

Sure, but that's not that simple. Formatted text is cached and macro output must not be parsed by textile and redmine links. The solution would be to "catch" macro at the beginning then substitue with their output at the very end of the process.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Implemented in r10209, r10210. Macros now optionally accept a block of text as a third argument. Examples from the doc:

<pre><code class="ruby">
Redmine::WikiFormatting::Macros.register do
# Declaring a macro that do not accept a block of text
macro :my_macro do |obj, args|
"My macro output"
end

# Declaring a macro that accepts a block of text (as third argument)
macro :my_macro2 do |obj, args, text|
"My macro output"
end
end

# Macros are invoked in formatted text using the following
# syntax:
#
# No arguments:
# {{my_macro}}
#
# With arguments:
# {{my_macro(arg1, arg2)}}
#
# With a block of text:
# {{my_macro2
# multiple lines
# of text
# }}
#
# With arguments and a block of text
# {{my_macro2(arg1, arg2)
# multiple lines
# of text
# }}
#
# Note that the closing tag }} must be at the start of a new line
</code></pre>

With r10209, the output of macros is automatically escaped. Use @#html_safe@ if the generated output contains html tags that should not be escaped. Examples:

<pre><code class="ruby">
Redmine::WikiFormatting::Macros.register do
macro :my_macro do |obj, args|
"Unsafe <tag>"
end

macro :my_macro2 do |obj, args|
"Safe <tag>".html_safe
end
end

# Then:
#
# {{my_macro}}
# produces: Unsafe &lt;tag&gt;
#
# {{my_macro2}}
# produces: Safe <tag>
</code></pre>
--------------------------------------------------------------------------------

Admin Redmine さんが約4年前に更新

  • カテゴリText formatting_26 にセット
  • 対象バージョン2.1.0_47 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0