This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Implementing Simultaneous Bold and Italic in MarkdownTextBlock #1710
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
34a0809
Merge pull request #2 from Microsoft/master
avknaidu aa18aa3
Merge pull request #3 from Microsoft/master
avknaidu 28a876f
Merge pull request #4 from Microsoft/master
avknaidu 09dfb8e
Implement simultaneous bold and italic
avknaidu 522c109
Fixing character in definition
avknaidu 5bb4b58
Implementing Comments in MarkdownTextBlock
avknaidu c8fa5a2
Updated Initial content documentation for comments implementation
avknaidu 93c4d3f
Removed enum and modified parser.
avknaidu 15c588a
Updated sample with example.
avknaidu 69ca98a
resolving conflicts
avknaidu bd1d609
Exception check.
avknaidu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Parse/Inlines/BoldItalicTextInline.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // ****************************************************************** | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // This code is licensed under the MIT License (MIT). | ||
| // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
| // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
| // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
| // ****************************************************************** | ||
|
|
||
| using System.Collections.Generic; | ||
| using Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Helpers; | ||
|
|
||
| namespace Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Parse | ||
| { | ||
| /// <summary> | ||
| /// Represents a span containing bold italic text. | ||
| /// </summary> | ||
| internal class BoldItalicTextInline : MarkdownInline, IInlineContainer | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="BoldItalicTextInline"/> class. | ||
| /// </summary> | ||
| public BoldItalicTextInline() | ||
| : base(MarkdownInlineType.BoldItalic) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the contents of the inline. | ||
| /// </summary> | ||
| public IList<MarkdownInline> Inlines { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Returns the chars that if found means we might have a match. | ||
| /// </summary> | ||
| internal static void AddTripChars(List<Common.InlineTripCharHelper> tripCharHelpers) | ||
| { | ||
| tripCharHelpers.Add(new Common.InlineTripCharHelper() { FirstChar = '*', Method = Common.InlineParseMethod.BoldItalic }); | ||
| tripCharHelpers.Add(new Common.InlineTripCharHelper() { FirstChar = '_', Method = Common.InlineParseMethod.BoldItalic }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to parse a bold text span. | ||
| /// </summary> | ||
| /// <param name="markdown"> The markdown text. </param> | ||
| /// <param name="start"> The location to start parsing. </param> | ||
| /// <param name="maxEnd"> The location to stop parsing. </param> | ||
| /// <returns> A parsed bold text span, or <c>null</c> if this is not a bold text span. </returns> | ||
| internal static Common.InlineParseResult Parse(string markdown, int start, int maxEnd) | ||
| { | ||
| if (start >= maxEnd - 1) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // Check the start sequence. | ||
| string startSequence = markdown.Substring(start, 3); | ||
| if (startSequence != "***" && startSequence != "___") | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // Find the end of the span. The end sequence (either '***' or '___') must be the same | ||
| // as the start sequence. | ||
| var innerStart = start + 3; | ||
| int innerEnd = Common.IndexOf(markdown, startSequence, innerStart, maxEnd); | ||
| if (innerEnd == -1) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // The span must contain at least one character. | ||
| if (innerStart == innerEnd) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // The first character inside the span must NOT be a space. | ||
| if (Common.IsWhiteSpace(markdown[innerStart])) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // The last character inside the span must NOT be a space. | ||
| if (Common.IsWhiteSpace(markdown[innerEnd - 1])) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // We found something! | ||
| var result = new BoldItalicTextInline(); | ||
|
||
| result.Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd); | ||
| return new Common.InlineParseResult(result, start, innerEnd + 3); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts the object into it's textual representation. | ||
| /// </summary> | ||
| /// <returns> The textual representation of this object. </returns> | ||
| public override string ToString() | ||
| { | ||
| if (Inlines == null) | ||
| { | ||
| return base.ToString(); | ||
| } | ||
|
|
||
| return "***" + string.Join(string.Empty, Inlines) + "***"; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes an Exception when at the start of the document, and writing asterisks. Ensure markdown is at least length 6.