/// <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(); }
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); }