How to achieve a preformatted text block?

Hello,

I want to have a block of preformatted text inside a box. An extra requirement is that the text wraps.

Just like here, how easy!

The only way I could achieve this (but without wrapping) is with {{code}}some text{{/code}} syntax. Is this the way to go?

XWiki syntax help page doesn’t seem to mention any alternative (apart from the inline formatting with ##monospace## syntax). However, I have seen some mentions on the Internet like, for example, in this comment ({pre}some text{pre}, this has no effect) or this ticket (and this attachment, how were the grey boxes created?).

Thanks

(just a random edit to re-enable this post that somehow got marked as spam)

See http://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiSyntax/?syntax=2.1&section=Verbatim

You’ll see that preformatted (we call it verbatim) is defined with {{{...}}} in XWiki Syntax 2.0+

But it does not wrap unfortunately.

Wrapping is not controlled by the syntax but by the view mode. I don’t understand.

Now you can use:

{{{
a
b
c
}}}

Thanks for the link. I tried that before and it doesn’t do what I want. I thought the main purpose of the {{{}}} syntax was, to quote the help page:

the XWiki Syntax will not be taken into account

and that’s it (just as seen in the Result column). That works but it doesn’t produce either monospace text or put the block of text into a box. What I see is:

This is a test {{toc}}

whereas what I want is:

This is a test {{toc}}

As for the view mode, where can I change that mode so the following wraps?

xwiki-code-wrapping

Here is another example that demonstrates how unusable this becomes when there is no wrapping and the page is long. You cannot access the text on the right because the scroll bar is at the bottom of the page:

preformatted-text-no-horizontal-scroll

In MediaWiki all I have to do to get preformatted text that wraps is to sprinkle the configuration with a few lines of CSS. Can XWiki be adjusted in a similar way?

media-wiki-preformatted-text

Same for XWiki, you can control the CSS and use the one you want. You can for example add a CSS stylesheet xobject, see http://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/SkinExtensionsTutorial/

Great, it works.

A bit complicated process and the tutorial could be a bit clearer. For example, rather than referring the reader to another page which is longer than the styles tutorial itself:

For this to happen however, you need to save the extension document with programming rights.

and doesn’t show what exactly needs to be set in order for this particular example to work it should just show the actual steps.

By the way, I just created a blank page with a style object as an admin user and didn’t set any rights at all and it still works without setting any rights anywhere. When I go to Page Administration page not a single checkbox is ticked.

Also the description says to set Use this extension option to Always on this wiki, the screenshot shows Always on this page, and what I see in my instance is none of the above:

use-this-extension-dropdown

Maybe a little thing but adds to confusion.

No you’re right we need to improve the xwiki docs. But we need help/contributions for that :wink: It’s a wiki and it’s meant to be edited by users.

Do you think you could edit the related pages to make the changes the suggested?

Thanks!

Always happy to help but it’s not just a simple matter matter of applying an edit, you have to explore and make sure you are writing something that is correct. For example, right now I would delete the reference to the “programming rights” page from the styles manual as it seems useless. I didn’t need to do anything with the permissions for the custom style to work. But someone (long time ago) put it there for a reason and this needs to be investigated. Does it apply to the older version of the wiki? Do I have a user with rights that makes the custom styles appear? etc.

By the way, the programming rights term should probably be changed to scripting rights, there is no use of ‘programming’ word on the rights page in the wiki software. Or vice versa, change ‘Script’ to ‘Program’ on rights pages.

See http://extensions.xwiki.org/xwiki/bin/view/Extension/Security+Module#HDefaultrightsbeingpredefined . We have both “script” and “program” rights and they have different meaning. We need both.

In practice “programming rights” is more a “root/god right”. It was historically introduced in the context of protected APIs but it’s actually used more as a ultimate right which is required for some dangerous tasks (like some APIs and script languages but not only).

Just an additional (a little bit dirty) solution:

{{insertCSS}}
.wrapbox .code { white-space:pre-wrap !important;}
{{/insertCSS}}

(% class="wrapbox" style="width:10cm" %)((({{code language="text"}}
computer science and knowledge are missing. computer science and knowledge are missing. computer science and knowledge are missing. computer science and knowledge are missing. computer science and knowledge are missing. computer science and knowledge are missing. computer science and knowledge are missing. computer science and knowledge are missing.  
This is correct.
{{/code}})))

with the use of a tiny macro insertCSS (instead creating a StyleSheetExtension object) with the code:

{{groovy}}
xwiki.linkx.use("data:text/css,"+xwiki.context.macro.content, ['type': 'text/css', 'rel': 'stylesheet'])
""
{{/groovy}}
1 Like