// (c) Copyright Ascensio System SIA 2010-2022 // // This program is a free software product. // You can redistribute it and/or modify it under the terms // of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software // Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended // to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of // any third-party rights. // // This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see // the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html // // You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. // // The interactive user interfaces in modified source and object code versions of the Program must // display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. // // Pursuant to Section 7(b) of the License you must retain the original Product logo when // distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under // trademark law for use of our trademarks. // // All the Product's GUI elements, including illustrations and icon sets, as well as technical writing // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode 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. protected 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(ParagraphFormatterState); } } protected FormatterState CurrentFormatterState { get { return this.Formatter.CurrentState; } } protected void ChangeFormatterState(FormatterState formatterState) { this.Formatter.ChangeState(formatterState); } }