Skip to content

Commit

Permalink
bfix(markdown)!: fix inline html parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-singh7 committed Mar 17, 2022
1 parent 3a36b23 commit dbdc490
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/services/ib_engine_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,31 @@ class IbEngineServiceImpl implements IbEngineService {

if (_ibRawPageData == null) return null;

/// Inline HTML Tags bounded by Backticks(`) are not parsed
/// For example,
/// 2<sup>6</sup> -> 2^6
/// whereas, `2<sup>6</sup>` -> `2<sup>6</sup>`
final content = HtmlUnescape()
.convert(_ibRawPageData.rawContent)
.splitMapJoin(
RegExp(r'\`(.*?)\`'),
onMatch: (m) {
if (m[1] != null &&
RegExp(r'<(\S*?)[^>]*>(.*?)<\/\1>|<.*?\/>').hasMatch(m[1]!)) {
return '${m[1]}';
}

return '${m[0]}';
},
onNonMatch: (n) => n,
);

return IbPageData(
id: _ibRawPageData.id,
pageUrl: _ibRawPageData.httpUrl,
title: _ibRawPageData.title,
content: [
IbMd(content: '${HtmlUnescape().convert(_ibRawPageData.rawContent)}\n'),
IbMd(content: '$content\n'),
],
tableOfContents: _ibRawPageData.hasToc
? _getTableOfContents(_ibRawPageData.content!)
Expand Down

0 comments on commit dbdc490

Please sign in to comment.