Content Macro

Last modified by Admin on 2024/10/30 01:15

cogAllows entering content in any of the supported Syntaxes
TypeJAR
Category
Developed by

XWiki Development Team

Rating
1 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Compatibility

XWiki 4.2M3+

Installable with the Extension Manager

Description

Allows to enter content in any of the supported Syntaxes and thus allows to have content written in various syntaxes.

Usage

{{content syntax="<syntax id>" source="script:myvariable"}}
...content written in <syntax id> syntax...
{{/content}}

where:

  • syntax: The technical identifier of the syntax in which the content is written. For example: xwiki/2.0, xwiki/2.1, confluence/1.0, html/4.01, xhtml/1.0, markdown/1.0, etc. Check the "Input" column of the supported Syntax table for the full list of supported syntaxes. XWiki 15.1+, 14.10.5+ Fallback on current syntax if not indicated
  • XWiki 15.1+, 14.10.5+ source (optional): indicate the reference of a source to use to get the content instead of passing it as macro content

Source

XWiki 15.1+, 14.10.5+  

The format of the reference of the source is <source type>:<reference>.

The content macro currently supports the following types of sources:

  • string: the reference is the content to highlight ({{content source="string:**wiki content**"/}}), it's also the default type when none is provided ({{content source="**wiki content**"/}}
  • script: the reference is the name of a script binding in the current script context, using it requires SCRIPT right.
    {{velocity}}
    #set($myvar = '**wiki content**')
    {{/velocity}}
    
    {{content source="script:myvar"/}}
    

Add support for a new source type

To add support for a new type of source, you need to provide a component implementing role org.xwiki.rendering.macro.source.MacroContentWikiSourceFactory and having as role hint the prefix to use in the source reference.

@Component
@Singleton
@Named("mytype")
public class MyMacroContentWikiSourceFactory implements MacroContentWikiSourceFactory
{
   @Override
   public MacroContentWikiSource getContent(MacroContentSourceReference reference, MacroTransformationContext context)
       throws MacroExecutionException
   {
       return new MacroContentWikiSource(reference, getContent(reference.getReference()), getSyntax(reference.getReference()));
   }
}

{{code source="mytype:myreference"/}}

Example

This is in **bold**

{{content syntax="confluence/1.0"}}
This is *bold* too!
{{/content}}

Results in:

contentmacro.png

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Dependencies

Dependencies for this extension (org.xwiki.rendering:xwiki-rendering-macro-content 16.9.0):

Get Connected