I have .txt documents that I want to attach and easily view in the browser. Confluence can't preview a .txt, so it has to be downloaded. I don't want to paste the text into a confluence page. Browsers natively can display .txt, so it is an odd limitiation.
The lack of preview for a text document is very surprising. This seems like a basic feature.
I don't think there is a way to preview it. I did create a user macro a few years ago to embed the contents of a txt file into a page. The user macro is below.
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 = '$' ) <style> #text${id} pre {white-space: pre-wrap;} </style> <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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.