-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement custom builder for backticks content
- Loading branch information
1 parent
dbdc490
commit effbc42
Showing
4 changed files
with
43 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
import 'package:markdown/markdown.dart' as md; | ||
import 'package:mobile_app/ui/views/ib/syntaxes/ib_inline_html_syntax.dart'; | ||
|
||
class IbBackTicksSyntax extends md.InlineSyntax { | ||
IbBackTicksSyntax() : super(_pattern); | ||
|
||
static const String _pattern = r'\`(.*?)\`'; | ||
|
||
@override | ||
bool onMatch(md.InlineParser parser, Match match) { | ||
final String matched = match[1] ?? ''; | ||
|
||
final inlineRegex = RegExp(IbInlineHtmlSyntax.Pattern); | ||
|
||
/// Inline HTML Tags bounded by Backticks(`) are not parsed | ||
if (inlineRegex.hasMatch(matched)) { | ||
for (var word in matched.split(' ')) { | ||
if (inlineRegex.hasMatch(word)) { | ||
parser.addNode(md.Text(word.substring(0, word.indexOf('<')))); | ||
|
||
final match = inlineRegex.firstMatch(word); | ||
if (match != null) { | ||
parser.addNode(md.Element.text(match[1]!, match[2]!)); | ||
} | ||
|
||
parser.addNode( | ||
md.Text("${word.substring(word.lastIndexOf('>') + 1)} ")); | ||
continue; | ||
} | ||
parser.addNode(md.Text('$word ')); | ||
} | ||
} else { | ||
parser.addNode(md.Element.text('code', matched)); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains 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