Feature #3061
closed
Let macros optionally match over multiple lines and ignore single curly braces
Added by Nils Israel over 15 years ago.
Updated over 12 years ago.
Description
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)
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?
- Target version set to Candidate for next minor release
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.
- Category set to Text formatting
There is no MACROS_RE = line on Redmine 1.3. Has anyone managed to make the plugin work with redmine 1.3?
thanks!
In Redmine 1.3, MACROS_RE is defined in redmine/app/helpers/application_helper.rb
- Status changed from New to Resolved
- Target version changed from Candidate for next minor release to 2.1.0
- Resolution set to Fixed
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.
- Target version changed from 2.1.0 to Candidate for next major release
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?
- Status changed from Resolved to New
- Resolution deleted (
Fixed)
- Target version changed from Candidate for next major release to 2.2.0
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.
- Subject changed from Modify MACRO_RE to match over multiple lines and ignore single curly braces to Let macros optionally match over multiple lines and ignore single curly braces
- Status changed from New to Closed
- Assignee set to Jean-Philippe Lang
- Target version changed from 2.2.0 to 2.1.0
- Resolution set to Fixed
Implemented in r10209, r10210. Macros now optionally accept a block of text as a third argument. Examples from the doc:
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
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:
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 <tag>
#
# {{my_macro2}}
# produces: Safe <tag>
Also available in: Atom
PDF