Text Processing Scripts

Note: This area is currently under development. Please let us know about any problems you have using this feature.

Staff.Wiki provides a way to programmatically make changes to articles or extract information from them using a simple scripting language. This can be useful after importing a lot of documents that have headers or footers that need removing, or to add headers, bolding, extract the title and so on.

Text Processing Scripts can be run on an individual article using the Reformat action available in the editor. You can also run it on multiple articles at once using an action on the Text Processor itself.

When creating the script, you can select an article to use for testing. This article won't be modified, but the changes will be previewed on the screen instead.

Creating a Script

To create Text Processing script, you'll need to login as an administrator. Then go to the Configuration tab, and click on "Text Processing Scripts":

Then click "+" to add a new entry:

Here you can enter in a name for the script, and optionally a longer description.

You should also select a sample tab and policy. This article won't be modified, but the content will be used for testing your script and previewing the result of the processing.

You can also optionally add a "Must Contain Text" value. This is text that must appear in the article for the text processor to work.

Once you click OK on that, you'll be taken to the script editor screen.

Here you will enter in the script on the left, and then click "Run" to test it and see the preview of the results on the right side. You can click Original at any time to show the original sample article.

The script runs from top to bottom. Empty lines are ignored, as are lines starting with a double forward slash (//). Indented text will only run if the previous find succeeded.

A key concept is that of the cursor. The cursor is an imaginary cursor within the document. Various commands like find will move the cursor in the document. You can then put select mode on, which is the same as moving the cursor with the shift key down to extend the selection. Then various commands, like bold will make the selected text bold.

The following commands can be used:

  • bold: makes the selected text bold.
  • delete: deletes the selected text from the document.
  • exit: exits and stops processing the remainder of the script
  • where: outputs in the log the current cursor location (used for diagnostics purposes)
  • oneLine: collapses the selection into one single line.
  • prefix X: places the specified text before the current selection.
  • suffix X: places the specified text after the current selection.
  • header: makes the selected text a heading level 1.
  • top: move the cursor to the top, and the beginning of the selection to the top if select mode is on.
  • end: move the cursor to the end, and extend the selection to the end if select mode is on. 
  • selectOn: starts select mode, with the selection starting at the current cursor location.
  • selectOff: ends select mode, removing any selection.
  • selStart N: moves the start of the selection back N words (specified as N).
  • selEnd N: moves the end of the selection forwards N words (specified as N). 
  • surround S E: surrounds the current selection with S at the beginning and E at the end.
  • findReplace find replace: Within the selection, finds any occurrence of find and replaces it with replace.
  • setAsTitle: sets the current text in the selection as the title of the article.
  • addChangeHistory: adds the selected text as a change history entry for the article.
  • endOfLine: moves the cursor to the end of the current line.
  • find X: moves the cursor to the next occurrence of X (after the cursor). If selection mode is on, extends the end of the selection to the start of the found term.

When you click Run it will show a preview of the results in the preview pane to the right. At the end of the preview will be a log of the commands run.

Applying the Script

To actually apply this text processor to a specific article, click Apply to Articles.

Here you can select the article (and its sub-articles) that this script will be applied to. Optionally set "Leave Pending" to leave it as a draft for you to publish. Otherwise it will apply the change and publish the change.

You can revert the change in the History tab (using the Revert button).

Find and Replace Across All Articles

The Text Processing script is the best way to perform a find and replace across your entire wiki. This may be useful, for example, if your company name changes. You would simply run a script like this:

selectOn
top
end
findReplace "Old Company Name" "New Company Name"

You would then apply this to the entire tab, in order to replace all occurrences in all articles. You can leave the articles pending so the changes can be reviewed afterwards.


Next Topic:
v6.0.0.14090
Up Since 4/12/2024 11:49:28 PM