embedding mime type text in Confluence
Asked by roomeon:

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

```
&lt;ac:text&gt;&lt;ri:attachment ri:filename="test.sh"/&gt;&lt;/ac:text&gt;
```

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


Answers:
author: Davin Studer
body: 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>
```

comments: author: Davin Studer
body: Does this work for your needs?


author: roomeon
body: 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.


author: roomeon
body: 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 dataAJS.$('#text$id pre').text(AJS.trim(data));
```

Thanks again for your great help

Peter


author: Waldemar Wetzel
body: 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?


author: roomeon
body: 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)[https://jira.atlassian.com/issues/?jql=project%20%3D%20CONF](https://jira.atlassian.com/issues/?jql=project%2520%253D%2520CONF)

See

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


author: Alejandro Conde Carrillo
body: 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).


author: Elisa [Atlassian]
body: 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)<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!