Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

embedding mime type text in Confluence

roomeon July 27, 2014

Hi,

is there any option to embed plain text files via macro which are attached to a page (like it is possible with images or pdf already)?

Something like

<ac:text>

<ri:attachment ri:filename="test.sh"/>

</ac:text>

This is not about embedding Office Files, Images, Multi Media or PDF which are supported.

We would like to attach files (e.g. just by dropping them in page window).
Embedding should show the content of the actual version of the attached / embedded file.
Means, we do not want to have to edit page each time an attachment has changed.

If this is not supported anyway, is it part of feature planning or where can I open an issue for Confluence?

Regards

Peter

5 answers

1 accepted

1 vote
Answer accepted
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2014

Here is a user macro I created for this.

Macro Name:
text

Macro Title:
Text Document

Macro Body Processing:
No macro body

Template:

## Developed by: Davin Studer
## Date created: 05/07/2014
## @param TXTName:title=Text File Name|type=string|required=true|desc=The name of the attached TXT file. (ex. Stuff.txt, Stuff.csv, Stuff.sh, Stuff.bat)
## @param Page:title=Page Title|type=confluence-content|required=false|desc=If not specified, the current page is used. (for a page in another space use the format "spacekey:page name")

#set( $id=$action.dateFormatter.calendar.timeInMillis )
#if( $paramPage && $paramPage != "" )
    ##########################
    ## Get the page manager ##
    ##########################
    #set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
    #set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
    #set( $containerManager=$getInstanceMethod.invoke(null,null) )
    #set( $containerContext=$containerManager.containerContext )
    #set( $pageManager=$containerContext.getComponent('pageManager') )

    ##########################
    ## Find the page        ##
    ##########################
    #set( $parts = $paramPage.split(":") )
    #set( $i = 0 )
    #set( $len = 0 )
    #set( $key = "" )
    #set( $name = "" )

    ##Having trouble finding out the length/size of $parts ... brute force it
    #foreach( $part in $parts )
        #set( $len = $len + 1 )
    #end
    
    #if( $len == 1 )
        #set( $key = $content.spaceKey )
        #set( $name = $paramPage )
    #else
        #foreach( $part in $parts )
            #if( $i == 0 )
              #set( $key = $part )
              #set( $i = $i + 1 )
           #else
              #set( $name = $part )
           #end
        #end
    #end

    #set( $tempcontent = "" )
    #if( $pageManager )
        #set( $tempcontent = $pageManager.getPage($key, $name) )
    #end
    #if( $tempcontent && $tempcontent != "" )
        #set( $content = $tempcontent )
    #else
        The page "$paramPage" was not found in this space.
        #set( $content = "" )
    #end
#end

#set( $attachments = $attachmentManager.getLatestVersionsOfAttachments($content) )
#set( $baseUrl = $action.getGlobalSettings().getBaseUrl() )

#set( $url = "" )
#foreach( $attachment in $attachments )
    #if( $attachment.getTitle().toLowerCase() == $paramTXTName.toLowerCase() )
        #set( $url = $attachment.getDownloadPathWithoutVersion() )
    #end
#end
#set( $d = '$' )
<div id="text$id">
    <ac:structured-macro ac:name="noformat">
		<ac:parameter ac:name="nopanel">true</ac:parameter>
		<ac:plain-text-body><![CDATA[ ]]></ac:plain-text-body>
	</ac:structured-macro>
</div>
<script type="text/javascript">
AJS.toInit(function(){
    AJS.${d}.get("$baseUrl$url", function( data ) {
        AJS.$('#text$id pre').text(data);
    });
});
</script>

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2014

Does this work for your needs?

roomeon August 5, 2014

Hi Davin,

that's really great. Exactly what we are looking for. Setting this in a

panel or

expandable text block

you can even give it a (border and) a title.

Thank you so much for sharing this. We love you ;)

Kind regards

Peter Neelmeyer

PS:

If confluence team is interested:

this could be a bundled macro with syntax highlighting and select field (dropdown) for choice of attachment file like there are plugins for PDF and Office files.

roomeon August 5, 2014

Hi Davin,

A little workaround. For title option we added parameter Title and changed xml a bit. It uses panel macro with pre tag instead of noformat macro.

<div id="text$id">
  <ac:structured-macro ac:name="panel">
  <ac:parameter ac:name="titleBGColor">#F7F7F7</ac:parameter>
  <ac:parameter ac:name="title">
#if( $paramTitle && $paramTitle != "" )
$paramTitle
#else
$paramTXTName
#end
   </ac:parameter>
   <ac:parameter ac:name="titleColor">#000000</ac:parameter>
   <ac:parameter ac:name="bgColor">#F0F0F0</ac:parameter>
   <ac:parameter ac:name="borderStyle">dashed</ac:parameter>
   <ac:parameter ac:name="borderColor">#BBBBBB</ac:parameter>
    <ac:rich-text-body>
       <pre><![CDATA[ ]]></pre>
     </ac:rich-text-body>
   </ac:structured-macro>
</div>

(and if totally no title would be given just no title row will be shown)

Added trimming data

// guessed there is a method for trimming data
AJS.$('#text$id pre').text(AJS.trim(data));

Thanks again for your great help

Peter

0 votes
Waldemar Wetzel March 7, 2018

Hello everybody,

 

how can i resolve the issue with the PDF-Export.
PDF don't show any text from included files.

 

can anyone help me to resolve this issue?

0 votes
roomeon July 30, 2014

Well, it seems to be not supported anyway and an issue can be opened here

https://jira.atlassian.com/issues/?jql=project%20%3D%20CONF

See

https://jira.atlassian.com/browse/CONF-34445

0 votes
Alejandro Conde Carrillo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2014

To embed plain text files, I suggest you to use the noformat macro. You will need to copy and paste the content of the file (it does not work from an attachment).

0 votes
Elisa [Atlassian]
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 27, 2014

Hi Peter,

Confluence can interact with any MSOffice file. So you can use a macro to integrate it. More info: https://confluence.atlassian.com/display/DOC/Displaying+Office+Files+in+Confluence

Or you can create a text link with the attachement's address.

Hope this helps!

Cheers!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events