New Code Macro Examples

First, let's look at a simple Java code example with nothing fancy going on:

package com.atlassian.confluence.admin.actions.macros;

import com.atlassian.confluence.renderer.UserMacroLibrary;

public class UserMacroBean
{
    String name;
    String template;

    public UserMacroBean()
    {
    }

    public UserMacroBean(String name, UserMacroLibrary userMacroLibrary)
    {
        this.name = name;
        this.template = userMacroLibrary.getMacroTemplate(name);
    }
}

Now, let's try a snippet of ugly sample SQL but with all the cool features turned on. Here we can see line numbers in the gutter (with a first line set to 20) and the controls at the top.

SELECT TOP 10
	FirstName,
	LastName,
	Email,
	--SUBSTRING(Phone, 2, 3) AS CityCode,
	SUBSTRING(Phone, 7, 8) AS PhoneNumber,
	upper(LanguagePref) AS Language,
	Address1,
	UpdatedOn AS CreatedOn
FROM
	profiles
WHERE
	-- Exclude all test emails
	Email NOT LIKE '%test%'
	AND Email NOT LIKE '%asdf%'
ORDER BY
	UpdatedOn DESC

What about some C-Sharp code, but collapsed?

Unable to find source-code formatter for language: csharp. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
// single line comments
// second single line
override protected void OnLoad(EventArgs e)
{
	if(Attributes["class"] != null)
	{
		//_year.CssClass = _month.CssClass = _day.CssClass = Attributes["class"];
	}
//	base.OnLoad(e);
}

/***********************************
 ** Multiline block comments
 **********************************/

/// <summary>
///		Gets or sets currently selected date of birth or <see cref="DateTime.MinValue"/> if selection is incomplete or invalid.
/// </summary>
public DateTime Date
{
	String stringWithUrl = "http://blog.dreamprojections.com";
	
	get
	{
		#region Hello world
		try
		{
			/*
			DateTime result = new DateTime(
				int.Parse(_year.SelectedItem.Value),
				int.Parse(_month.SelectedItem.Value),
				int.Parse(_day.SelectedItem.Value)
				);
			
			i *= 2;
			*/
			return result;
		}
		catch
		{
			/* return _minDate; */
		}
		#endregion
	}
	set
	{
		Day		= value.Day;
		Month	= value.Month;
		Year	= value.Year;
	}
}

Now, let's see how two code blocks look next to each other.

Here is some VB (not the beer kind):

Unable to find source-code formatter for language: vb. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
'
' This is a VB test
'

Imports System.Collections

Dim stringWithUrl = "http://blog.dreamprojections.com"

Public Class MyVbClass
    Private m_MyString As String

    Public Sub New()
        myString = "Hello there"
    End Sub

    Public Property MyString() As String
        Get
            Return m_MyString
        End Get
        Set(ByVal Value As String)
            m_MyString = Value
        End Set
    End Property

#Region "This is my region"
    ' This is a comment
    Public Function MyFunction( ByVal i as Integer ) As Double
        MyFunction = 123.456
    End Function
#End Region
End Class

And here is some PHP (not the drug kind):

Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
/***********************************
 ** Multiline block comments
 **********************************/

$stringWithUrl = "http://blog.dreamprojections.com";
$stringWithUrl = 'http://www.dreamprojections.com';

ob_start("parseOutputBuffer");		// Start Code Buffering
session_start();

function parseOutputBuffer($buf) {
	global $portal_small_code, $portal_gzcompress;
	global $PHP_SELF, $HTTP_ACCEPT_ENCODING;

	// cleaning out the code.
	if($portal_small_code && !$portal_gzcompress) {
		$buf = str_replace("	", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace(chr(13), "", $buf);
	}
}

Labels

code code Delete
samples samples Delete
highlighting highlighting Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 25, 2006

    Justin Pitts says:

    I suspect this page is broken today. There are no line numbers in the gutter for...

    I suspect this page is broken today. There are no line numbers in the gutter for the sql, and the rest have errors in red at the top of their panels except for the Java one.

  2. Nov 09, 2006

    Pavlo Kasperskyi says:

    "Unable to find sourcecode formatter for language: csharp. Available languages a...

    "Unable to find source-code formatter for language: csharp. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml" ?

    1. Nov 09, 2006

      Tom Davies says:

      The new code macro is no longer installed on confluence.atlassian.com, as it doe...

      The new code macro is no longer installed on confluence.atlassian.com, as it doesn't work with the rich text editor.

      1. Feb 12, 2007

        Jed Wesley-Smith says:

        Jeez Tom, you should have disabled the Rich Text Editor instead :)

        Jeez Tom, you should have disabled the Rich Text Editor instead