#region License Statement // Copyright (c) L.A.B.Soft. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. #endregion #region Using Statements using System; using System.Text.RegularExpressions; #endregion namespace Textile { /// /// Base class for formatter states. /// /// A formatter state describes the current situation /// of the text being currently processed. A state can /// write HTML code when entered, exited, and can modify /// each line of text it receives. public abstract class FormatterState { /// /// The formatter this state belongs to. /// public TextileFormatter Formatter { get; } /// /// Public constructor. /// /// The parent formatter. public FormatterState(TextileFormatter formatter) { Formatter = formatter; } /// /// /// /// /// /// public abstract string Consume(string input, Match m); /// /// Method called when the state is entered. /// public abstract void Enter(); /// /// Method called when the state is exited. /// public abstract void Exit(); /// /// Method called when a line of text should be written /// to the web form. /// /// The line of text. public abstract void FormatLine(string input); /// /// Returns whether this state can last for more than one line. /// /// A boolean value stating whether this state is only for one line. /// This method should return true only if this state is genuinely /// multi-line. For example, a header text is only one line long. You can /// have several consecutive lines of header texts, but they are not the same /// header - just several headers one after the other. /// Bulleted and numbered lists are good examples of multi-line states. //abstract public bool IsOneLineOnly(); /// /// /// /// /// public abstract bool ShouldExit(string input); /// /// /// /// /// /// /// public virtual bool ShouldNestState(FormatterState other) { return false; } /// /// Returns whether block formatting (quick phrase modifiers, etc.) should be /// applied to this line. /// /// The line of text /// Whether the line should be formatted for blocks public virtual bool ShouldFormatBlocks(string input) { return true; } /// /// Returns whether the current state accepts being superceded by another one /// we would possibly find by parsing the input line of text. /// /// /// public virtual bool ShouldParseForNewFormatterState(string input) { return true; } /// /// Gets the formatting state we should fallback to if we don't find anything /// relevant in a line of text. /// public virtual Type FallbackFormattingState { get { return typeof(States.ParagraphFormatterState); } } protected FormatterState CurrentFormatterState { get { return this.Formatter.CurrentState; } } protected void ChangeFormatterState(FormatterState formatterState) { this.Formatter.ChangeState(formatterState); } } }