/// <summary> /// Formats the given text. /// </summary> /// <param name="input">The text to format.</param> public void Format(string input) { m_output.Begin(); // Clean the text... string str = PrepareInputForFormatting(input); // ...and format each line. foreach (string line in str.Split('\n')) { string tmp = line; // Let's see if the current state(s) is(are) finished... while (CurrentState != null && CurrentState.ShouldExit(tmp)) { PopState(); } if (!Regex.IsMatch(tmp, @"^\s*$")) { // Figure out the new state for this text line, if possible. if (CurrentState == null || CurrentState.ShouldParseForNewFormatterState(tmp)) { tmp = HandleFormattingState(tmp); } // else, the current state doesn't want to be superceded by // a new one. We'll leave him be. // Modify the line with our block modifiers. if (CurrentState == null || CurrentState.ShouldFormatBlocks(tmp)) { foreach (BlockModifier blockModifier in s_blockModifiers) { //TODO: if not disabled... tmp = blockModifier.ModifyLine(tmp); } for (int i = s_blockModifiers.Count - 1; i >= 0; i--) { BlockModifier blockModifier = s_blockModifiers[i]; tmp = blockModifier.Conclude(tmp); } } // Format the current line. CurrentState.FormatLine(tmp); } } // We're done. There might be a few states still on // the stack (for example if the text ends with a nested // list), so we must pop them all so that they have // their "Exit" method called correctly. while (m_stackOfStates.Count > 0) { PopState(); } m_output.End(); }
public bool UnregisterBlockModifier(BlockModifier blockModifier) { if (m_blockModifiers.Remove(blockModifier)) { blockModifier.Formatter = null; return(true); } return(false); }
public void RegisterBlockModifier(BlockModifier blockModifer) { if (blockModifer == null) { throw new ArgumentNullException("blockModifier"); } m_blockModifiers.Add(blockModifer); blockModifer.Formatter = this; }
public void SwitchBlockModifier(Type type, bool onOff) { BlockModifier blockModifier = GetBlockModifier(type); if (blockModifier == null) { throw new InvalidOperationException(string.Format("No block modifier of type '{0}' was registered.", type)); } blockModifier.IsEnabled = onOff; }
public bool IsBlockModifierEnabled(Type type) { BlockModifier blockModifier = GetBlockModifier(type); if (blockModifier == null) { return(false); } return(blockModifier.IsEnabled); }
public bool UnregisterBlockModifier(Type type) { BlockModifier blockModifier = GetBlockModifier(type); if (blockModifier != null) { return(UnregisterBlockModifier(blockModifier)); } return(false); }
internal static string ApplyBlockModifiers(string tmp) { foreach (BlockModifier blockModifier in s_blockModifiers) { //TODO: if not disabled... tmp = blockModifier.ModifyLine(tmp); } for (int i = s_blockModifiers.Count - 1; i >= 0; i--) { BlockModifier blockModifier = s_blockModifiers[i]; tmp = blockModifier.Conclude(tmp); } return(tmp); }
/// <summary> /// Applies the currently enabled block modifiers to a string. /// </summary> /// <param name="str"></param> /// <returns></returns> public string ApplyBlockModifiers(string str) { foreach (BlockModifier blockModifier in _blockModifiers) { if (blockModifier.IsEnabled) { str = blockModifier.ModifyLine(str); } } for (int j = _blockModifiers.Count - 1; j >= 0; j--) { BlockModifier blockModifier = _blockModifiers[j]; if (blockModifier.IsEnabled) { str = blockModifier.Conclude(str); } } return(str); }
public static void RegisterBlockModifier(BlockModifier blockModifer) { s_blockModifiers.Add(blockModifer); s_blockModifiersTypes.Add(blockModifer.GetType()); }
public bool IsBlockModifierRegistered(BlockModifier blockModifier) { return(m_blockModifiers.Contains(blockModifier)); }