/// <summary>
 /// Установить разметку.
 /// </summary>
 /// <param name="src">Исходная строка.</param>
 /// <param name="tag">Тэг.</param>
 /// <param name="startIndex">Начальный индекс.</param>
 /// <param name="length">Длина.</param>
 /// <returns></returns>
 public string SetMarkup(string src, MarkupTag tag, int startIndex, int length)
 {
     if (src == null || !ProvidedTags.ContainsKey(tag))
     {
         return src;
     }
     var mt = ProvidedTags[tag];
     return src.Replace("\r\n", "\n").Insert(startIndex, mt.Begin).Insert(startIndex + mt.Begin.Length + length, mt.End).Replace("\n", "\r\n");
 }
 /// <summary>
 /// This is the only constructor for this class.
 /// </summary>
 /// <param name="tag">The MarkupTag to which this attribute belongs.</param>
 /// <param name="indexBegin">The index in the document text at which this attribute begins.</param>
 /// <param name="length">The text length of this attribute.</param>
 /// <param name="nameIndexBegin">The index in the document text at which the name of this attribute begins.</param>
 /// <param name="nameLength">The text length of the name of this attribute.</param>
 /// <param name="valueIndexBegin">The index in the document text at which the value of this attribute begins.</param>
 /// <param name="valueLength">The text length of the value of this attribute.</param>
 internal MarkupAttribute(MarkupTag tag, int indexBegin, int length, int nameIndexBegin, int nameLength, int valueIndexBegin, int valueLength)
 {
     this.tag = tag;
     this.indexBegin = indexBegin;
     this.length = length;
     this.nameIndexBegin = nameIndexBegin;
     this.nameLength = nameLength;
     this.valueIndexBegin = valueIndexBegin;
     this.valueLength = valueLength;
 }
Example #3
0
        private MarkupNode?ParseElement()
        {
            MarkupTag  startTag = ParseTag();
            MarkupNode?node;

            switch (startTag.Name)
            {
            case "FONT":
                node = ParseFontElement(startTag);
                break;

            case "span":
            case "SPAN":
                node = ParseSpan(startTag);
                break;

            case "RUBY":
                node = ParseRubyElement(startTag);
                break;

            case "pre":
            case "PRE":
                node = ParsePreformattedText();
                break;

            case "voice":
                node = ParseVoiceElement(startTag);
                break;

            case "k":
            case "K":
                return(new HaltElement());

            case "?":
                return(new NoLinebreaksElement());

            case "br":
            case "BR":
                return(new LinebreakElement());

            case "i":
            case "I":
                MarkupContent content = ParseContent(startTag.Name);
                return(new ItalicElement(content));

            case "u":
            case "U":
                return(ParseContent(startTag.Name));

            default:
                throw new NotImplementedException($"Markup tag '{startTag.Name}' is not yet supported.");
            }
            return(node);
        }
Example #4
0
 /// <summary>
 /// This is the only constructor for this class.
 /// </summary>
 /// <param name="tag">The MarkupTag to which this attribute belongs.</param>
 /// <param name="indexBegin">The index in the document text at which this attribute begins.</param>
 /// <param name="length">The text length of this attribute.</param>
 /// <param name="nameIndexBegin">The index in the document text at which the name of this attribute begins.</param>
 /// <param name="nameLength">The text length of the name of this attribute.</param>
 /// <param name="valueIndexBegin">The index in the document text at which the value of this attribute begins.</param>
 /// <param name="valueLength">The text length of the value of this attribute.</param>
 internal MarkupAttribute(MarkupTag tag, int indexBegin, int length, int nameIndexBegin, int nameLength,
                          int valueIndexBegin, int valueLength)
 {
     this.tag             = tag;
     this.indexBegin      = indexBegin;
     this.length          = length;
     this.nameIndexBegin  = nameIndexBegin;
     this.nameLength      = nameLength;
     this.valueIndexBegin = valueIndexBegin;
     this.valueLength     = valueLength;
 }
Example #5
0
        private MarkupContent ParseContent(string?rootElementName)
        {
            var children = ImmutableArray.Create <MarkupNode>();

            ImmutableArray <MarkupNode> .Builder?builder = null;
            while (PeekChar() != EofCharacter)
            {
                if (IsEndTag())
                {
                    MarkupTag endTag = ParseTag();
                    if (rootElementName == endTag.Name)
                    {
                        break;
                    }
                }

                MarkupNode?node = ParseNode();
                if (node is null)
                {
                    continue;
                }
                if (children.Length == 0)
                {
                    children = ImmutableArray.Create(node);
                }
                else
                {
                    Debug.Assert(children.Length == 1);
                    if (builder is null)
                    {
                        builder = ImmutableArray.CreateBuilder <MarkupNode>();
                        builder.Add(children[0]);
                    }
                    builder.Add(node);
                }
            }

            ImmutableArray <MarkupNode> array = builder?.ToImmutable() ?? children;

            return(new MarkupContent(array));
        }
 /// <summary>
 /// Конструктор.
 /// </summary>
 /// <param name="provider">Провайдер.</param>
 /// <param name="tag">Тэг.</param>
 public ApplyMarkupEventArgs(IMarkupProvider provider, MarkupTag tag)
 {
     this.provider = provider;
     this.tag = tag;
 }