Skip to content

Commit 49adda1

Browse files
committed
Implements #93
1 parent 0f88724 commit 49adda1

8 files changed

Lines changed: 122 additions & 9 deletions

File tree

src/DocNet/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
1212
[assembly: AssemblyProduct("Docnet")]
13-
[assembly: AssemblyCopyright("Copyright ©2023 Frans Bouma")]
13+
[assembly: AssemblyCopyright("Copyright ©2025 Frans Bouma")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.16.6.0")]
36-
[assembly: AssemblyFileVersion("0.16.6")]
35+
[assembly: AssemblyVersion("0.16.7.0")]
36+
[assembly: AssemblyFileVersion("0.16.7")]

src/MarkdownDeep/Block.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ internal enum BlockType
6161
alert, // Data is the alert type specified.
6262
tab, // Data is the tab header text.
6363
tabs, // children are the tabs.
64+
font_awesome_brands, // data is icon name
65+
font_awesome_solid, // data is icon name
6466
}
6567

6668
class Block
@@ -395,6 +397,22 @@ internal void Render(Markdown m, StringBuilder b)
395397
b.Append("\"></i>");
396398
}
397399
break;
400+
case BlockType.font_awesome_brands:
401+
if(m.DocNetMode)
402+
{
403+
b.Append("<i class=\"fa-brands fa-");
404+
b.Append(this.Data as string ?? string.Empty);
405+
b.Append("\"></i>");
406+
}
407+
break;
408+
case BlockType.font_awesome_solid:
409+
if(m.DocNetMode)
410+
{
411+
b.Append("<i class=\"fa-solid fa-");
412+
b.Append(this.Data as string ?? string.Empty);
413+
b.Append("\"></i>");
414+
}
415+
break;
398416
case BlockType.alert:
399417
if(m.DocNetMode)
400418
{

src/MarkdownDeep/BlockProcessor.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,15 @@ private bool HandleDocNetExtension(Block b)
12711271
var initialStart = this.Position;
12721272
if(DoesMatch("@fa-"))
12731273
{
1274-
return HandleFontAwesomeExtension(b);
1274+
return HandleFontAwesomeExtension(b, BlockType.font_awesome);
1275+
}
1276+
if(DoesMatch("@fabrands-"))
1277+
{
1278+
return HandleFontAwesomeExtension(b, BlockType.font_awesome_brands);
1279+
}
1280+
if(DoesMatch("@fasolid-"))
1281+
{
1282+
return HandleFontAwesomeExtension(b, BlockType.font_awesome_solid);
12751283
}
12761284
// first match @tabs, and then @tab, as both are handled by this processor.
12771285
if(DoesMatch("@tabs"))
@@ -1553,7 +1561,7 @@ private bool HandleSnippetExtension(Block b)
15531561
/// </summary>
15541562
/// <param name="b">The b.</param>
15551563
/// <returns></returns>
1556-
private bool HandleFontAwesomeExtension(Block b)
1564+
private bool HandleFontAwesomeExtension(Block b, BlockType typeofBlock = BlockType.font_awesome)
15571565
{
15581566
string iconName = string.Empty;
15591567
int newPosition = this.Position;
@@ -1562,7 +1570,7 @@ private bool HandleFontAwesomeExtension(Block b)
15621570
return false;
15631571
}
15641572
this.Position = newPosition;
1565-
b.BlockType = BlockType.font_awesome;
1573+
b.BlockType = typeofBlock;
15661574
b.Data = iconName;
15671575
return true;
15681576
}

src/MarkdownDeep/SpanFormatter.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ private void Render(StringBuilder sb, string str)
267267
sb.Append(str, t.startOffset, t.length);
268268
sb.Append("\"></i>");
269269
break;
270+
271+
case TokenType.font_awesome_brands:
272+
sb.Append("<i class=\"fa-brands fa-");
273+
sb.Append(str, t.startOffset, t.length);
274+
sb.Append("\"></i>");
275+
break;
276+
277+
case TokenType.font_awesome_solid:
278+
sb.Append("<i class=\"fa-solid fa-");
279+
sb.Append(str, t.startOffset, t.length);
280+
sb.Append("\"></i>");
281+
break;
270282
}
271283

272284
FreeToken(t);
@@ -489,6 +501,30 @@ public void Tokenize(string str, int start, int len)
489501
this.Position = newPosition;
490502
}
491503
}
504+
if(this.DoesMatch("@fabrands-"))
505+
{
506+
// expect FontAwesome brands v6.
507+
string iconName = string.Empty;
508+
int newPosition = 0;
509+
if(Utils.SkipFontAwesome(this.Input, this.Position, out newPosition, out iconName))
510+
{
511+
// token should be just the iconname, so adjust position specification to that.
512+
token = CreateToken(TokenType.font_awesome_brands, newPosition - iconName.Length, iconName.Length);
513+
this.Position = newPosition;
514+
}
515+
}
516+
if(this.DoesMatch("@fasolid-"))
517+
{
518+
// expect FontAwesome solid v6.
519+
string iconName = string.Empty;
520+
int newPosition = 0;
521+
if(Utils.SkipFontAwesome(this.Input, this.Position, out newPosition, out iconName))
522+
{
523+
// token should be just the iconname, so adjust position specification to that.
524+
token = CreateToken(TokenType.font_awesome_solid, newPosition - iconName.Length, iconName.Length);
525+
this.Position = newPosition;
526+
}
527+
}
492528
}
493529
break;
494530
}

src/MarkdownDeep/Token.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ internal enum TokenType
5555

5656
// DocNet Extensions
5757
font_awesome, // <i class="fa fa-name"></i>
58+
font_awesome_brands, // <i class="fa-brands fa-name"></i>
59+
font_awesome_solid, // <i class="fa-solid fa-name"></i>
5860
}
5961

6062
// Token

src/MarkdownDeep/Utils.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,11 @@ public static bool SkipFontAwesome(string str, int currentPos, out int newPos, o
562562
var scanner = new StringScanner(str, currentPos);
563563
// skip '@'
564564
scanner.SkipForward(1);
565-
if(!scanner.DoesMatch("fa-"))
565+
if(!MatchAnyAndSkip(scanner, new List<string>() { "fa-", "fabrands-", "fasolid-" }))
566566
{
567-
// not a font awesome specification
567+
// nothing matches
568568
return false;
569569
}
570-
scanner.SkipForward(3);
571570
iconName = string.Empty;
572571
if(!scanner.SkipIdentifier(ref iconName, dashIsValidChar:true))
573572
{
@@ -582,5 +581,33 @@ public static bool SkipFontAwesome(string str, int currentPos, out int newPos, o
582581
newPos = scanner.Position;
583582
return true;
584583
}
584+
585+
586+
/// <summary>
587+
/// Tries to match any of the strings passed in at the current scanner position. If matched it'll skip the matched string on the scanner and return true,
588+
/// otherwise it won't skip and false
589+
/// </summary>
590+
/// <param name="scanner"></param>
591+
/// <param name="toMatch"></param>
592+
/// <returns></returns>
593+
private static bool MatchAnyAndSkip(StringScanner scanner, List<string> toMatch)
594+
{
595+
int toSkip = 0;
596+
foreach(string s in toMatch)
597+
{
598+
if(scanner.DoesMatch(s))
599+
{
600+
toSkip = s.Length;
601+
break;
602+
}
603+
}
604+
605+
if(toSkip == 0)
606+
{
607+
return false;
608+
}
609+
scanner.SkipForward(toSkip);
610+
return true;
611+
}
585612
}
586613
}

src/MarkdownDeepTests/testfiles/docnetmode/FontAwesome(DocNetMode).html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
<i class="fa fa-arrow-right"></i><i class="fa fa-arrow-right"></i><i class="fa fa-arrow-right"></i><i class="fa fa-arrow-right"></i>
88

9+
<i class="fa-solid fa-arrow-right"></i><i class="fa-solid fa-arrow-right"></i><i class="fa-solid fa-arrow-right"></i><i class="fa-solid fa-arrow-right"></i><p>a <i class="fa-solid fa-arrow-right"></i></p>
10+
911
<i class="fa fa-github"></i><i class="fa fa-github"></i><i class="fa fa-github"></i><p>a <i class="fa fa-github"></i></p>
1012

13+
<i class="fa-brands fa-github"></i><i class="fa-brands fa-github"></i><i class="fa-brands fa-github"></i><p>a <i class="fa-brands fa-github"></i></p>
14+
1115
<p>post</p>

src/MarkdownDeepTests/testfiles/docnetmode/FontAwesome(DocNetMode).txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@ this is a @fa-arrow-right right arrow!
1212

1313
@fa-arrow-right @fa-arrow-right
1414

15+
@fasolid-arrow-right
16+
17+
@fasolid-arrow-right
18+
19+
@fasolid-arrow-right
20+
21+
@fasolid-arrow-right @fasolid-arrow-right
22+
23+
a @fasolid-arrow-right
24+
1525
@fa-github
1626

1727
@fa-github
1828
@fa-github
1929

2030
a @fa-github
31+
32+
@fabrands-github
33+
34+
@fabrands-github
35+
@fabrands-github
36+
37+
a @fabrands-github
38+
2139

2240
post

0 commit comments

Comments
 (0)