/// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input)
        {
            string consumedInput = GetConsumedInput(m_disabledFormatterStates, input, this);

            if (consumedInput != null)
            {
                return(consumedInput);
            }

            // Default, when no block is specified, we ask the current state, or
            // use the paragraph state.
            if (CurrentState != null)
            {
                if (CurrentState.FallbackFormattingState != null)
                {
                    FormatterState formatterState = (FormatterState)Activator.CreateInstance(CurrentState.FallbackFormattingState, this);
                    ChangeState(formatterState);
                }
                // else, the current state doesn't want to be superceded by
                // a new one. We'll leave him be.
            }
            else
            {
                ChangeState(new States.ParagraphFormatterState(this));
            }
            return(input);
        }
        /// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input, string inputLookAhead)
        {
            // Find an appropriate formatter state.
            Match match;
            Match lookAheadMatch;
            Type  type = GetCandidateFormatterStateType(input, inputLookAhead, out match, out lookAheadMatch);

            // Got it! Apply it.
            if (type != null)
            {
                FormatterState formatterState = (FormatterState)Activator.CreateInstance(type);
                formatterState.Formatter = this;
                FormatterStateConsumeContext context = new FormatterStateConsumeContext(input, inputLookAhead, match, lookAheadMatch);
                return(formatterState.Consume(context));    // This may or may not change the current state.
            }

            // Default, when no block is specified, we ask the current state, or
            // use the default state.
            if (CurrentState != null)
            {
                if (CurrentState.FallbackFormattingState != null)
                {
                    ChangeState(CurrentState.FallbackFormattingState);
                }
                // else, the current state doesn't want to be superceded by
                // a new one. We'll leave him be.
            }
            else
            {
                ChangeState(m_defaultFormatterStateType);
            }
            return(input);
        }
        /// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input)
        {
            for (int i = 0; i < s_registeredStates.Count; i++)
            {
                Type type = s_registeredStates[i];
                if (IsFormatterStateEnabled(type))
                {
                    FormatterStateAttribute att = s_registeredStatesAttributes[i];
                    Match m = Regex.Match(input, att.Pattern);
                    if (m.Success)
                    {
                        FormatterState formatterState = (FormatterState)Activator.CreateInstance(type, this);
                        return(formatterState.Consume(input, m));
                    }
                }
            }

            // Default, when no block is specified, we ask the current state, or
            // use the paragraph state.
            if (CurrentState != null)
            {
                if (CurrentState.FallbackFormattingState != null)
                {
                    FormatterState formatterState = (FormatterState)Activator.CreateInstance(CurrentState.FallbackFormattingState, this);
                    ChangeState(formatterState);
                }
                // else, the current state doesn't want to be superceded by
                // a new one. We'll leave him be.
            }
            else
            {
                ChangeState(new States.ParagraphFormatterState(this));
            }
            return(input);
        }
        /// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input)
        {
            {
                Match match;
                var   formatterState = FindState(input, out match);
                if (formatterState != null)
                {
                    var result = formatterState.Consume(input, match);
                    return(result);
                }
            }

            // Default, when no block is specified, we ask the current state, or
            // use the paragraph state.
            if (CurrentState != null)
            {
                if (CurrentState.FallbackFormattingState != null)
                {
                    FormatterState formatterState = (FormatterState)Activator.CreateInstance(CurrentState.FallbackFormattingState, this);
                    ChangeState(formatterState);
                }
                // else, the current state doesn't want to be superceded by
                // a new one. We'll leave him be.
            }
            else
            {
                ChangeState(new States.ParagraphFormatterState(this));
            }
            return(input);
        }
 internal void ChangeState(FormatterState formatterState)
 {
     if (CurrentState != null && CurrentState.GetType() == formatterState.GetType())
     {
         if (!CurrentState.ShouldNestState(formatterState))
             return;
     }
     PushState(formatterState);
 }
 internal void ChangeState(FormatterState formatterState)
 {
     if (CurrentState != null && CurrentState.GetType() == formatterState.GetType())
     {
         if (!CurrentState.ShouldNestState(formatterState))
         {
             return;
         }
     }
     PushState(formatterState);
 }
        public void ChangeState(FormatterState state)
        {
            if (CurrentState != null && CurrentState.GetType() == state.GetType())
            {
                if (!CurrentState.ShouldNestState(state))
                {
                    return;
                }
            }

            state.Formatter = _formatter;
            _states.Push(state);
            state.Enter();
        }
 internal static string GetConsumedInput(List <Type> disabledFormatterStates, string input, TextileFormatter instance)
 {
     for (int i = 0; i < s_registeredStates.Count; i++)
     {
         Type type = s_registeredStates[i];
         if (!disabledFormatterStates.Contains(type))
         {
             FormatterStateAttribute att = s_registeredStatesAttributes[i];
             Match m = Regex.Match(input, att.Pattern);
             if (m.Success)
             {
                 FormatterState formatterState = (FormatterState)Activator.CreateInstance(type, instance);
                 return(formatterState.Consume(input, m));
             }
         }
     }
     return(null);
 }
Esempio n. 9
0
        /// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input, string inputLookAhead)
        {
            // Find an appropriate formatter state.
            Match match;
            Match lookAheadMatch;
            Type  type = GetCandidateFormatterStateType(input, inputLookAhead, out match, out lookAheadMatch);

            // Got it! Apply it.
            if (type != null)
            {
                FormatterState formatterState = (FormatterState)Activator.CreateInstance(type);
                formatterState.Formatter = this;
                FormatterStateConsumeContext context = new FormatterStateConsumeContext(input, inputLookAhead, match, lookAheadMatch);
                return(formatterState.Consume(context));    // This may or may not change the current state.
            }

            StateManager.Fallback();

            return(input);
        }
 /// <summary>
 /// Pushes a new state on the stack.
 /// </summary>
 /// <param name="s">The state to push.</param>
 /// The state will be entered automatically.
 private void PushState(FormatterState s)
 {
     m_stackOfStates.Push(s);
     s.Enter();
 }
Esempio n. 11
0
 public void PushState(FormatterState state)
 {
 }
Esempio n. 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="actualTag"></param>
 /// <param name="alignNfo"></param>
 /// <param name="attNfo"></param>
 /// <returns></returns>
 public virtual bool ShouldNestState(FormatterState other)
 {
     return false;
 }
Esempio n. 13
0
 protected void ChangeFormatterState(FormatterState formatterState)
 {
     this.Formatter.ChangeState(formatterState);
 }
 /// <summary>
 /// Pushes a new state on the stack.
 /// </summary>
 /// <param name="s">The state to push.</param>
 /// The state will be entered automatically.
 private void PushState(FormatterState s)
 {
     m_stackOfStates.Push(s);
     s.Enter();
 }
        public void ChangeState(Type formatterStateType)
        {
            FormatterState formatterState = (FormatterState)Activator.CreateInstance(formatterStateType);

            ChangeState(formatterState);
        }
 protected void ChangeFormatterState(FormatterState formatterState)
 {
     this.Formatter.ChangeState(formatterState);
 }
Esempio n. 17
0
 protected void ChangeState(FormatterState newState) => Formatter.StateManager.ChangeState(newState);
Esempio n. 18
0
 public virtual bool ShouldNestState(FormatterState other) => false;
 /// <summary>
 ///
 /// </summary>
 /// <param name="actualTag"></param>
 /// <param name="alignNfo"></param>
 /// <param name="attNfo"></param>
 /// <returns></returns>
 public virtual bool ShouldNestState(FormatterState other)
 {
     return(false);
 }
 /// <summary>
 /// Pushes a new state on the stack.
 /// </summary>
 /// <param name="s">The state to push.</param>
 /// The state will be entered automatically.
 private void PushState(FormatterState state)
 {
     state.Formatter = this;
     m_stackOfStates.Push(state);
     state.Enter();
 }