Version: current

# Class TextParser

Parses text in a variety of ways.

Called from a template by $Content.Parse(SubClassName), similar to $Content.XML. This will work on any Text database field (Or a sub-class, such as HTMLText, although it's usefulness in this situation is more limited).

Any sub-classes of TextParser must implement a parse() method. This should take $this->content and parse it however you want. For an example of the implementation, @see BBCodeParser.

Your sub-class will be initialized with a string of text, then parse() will be called. parse() should (after processing) return the formatted string.

Note: $this->content will have NO conversions applied to it. You should run Covert::raw2xml or whatever is appropriate before using it.

Optionally (but recommended), is creating a static usable_tags method, which will return a DataObjectSet of all the usable tags that can be parsed. This will (mostly) be used to create helper blocks - telling users what things will be parsed. Again, @see BBCodeParser for an example of the syntax

  Object
  TextParser

### Direct known subclasses

`BBCodeParser`

Abstract
Package: sapphire\misc
Located at sapphire/parsers/TextParser.php

## Methods summary

`public` | # `__construct( string $content = "" )` Creates a new TextParser object. Creates a new TextParser object. #### Parameters $content string $content The contents of the dbfield #### Overrides `Object::__construct`
`public` | # `setContent( mixed $content = "" )` Convenience method, shouldn't really be used, but it's here if you want it Convenience method, shouldn't really be used, but it's here if you want it
`abstract public` | # `parse( )` Define your own parse method to parse $this->content appropriately. See the class doc-block for more implementation details. Define your own parse method to parse $this->content appropriately. See the class doc-block for more implementation details.

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `defineMethods()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected mixed` | $content | #

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -