From dbdc4901725f7508c10aa84db959a67a11b3d09a Mon Sep 17 00:00:00 2001 From: Aman Date: Tue, 8 Mar 2022 10:47:44 +0530 Subject: [PATCH] bfix(markdown)!: fix inline html parsing --- lib/services/ib_engine_service.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/services/ib_engine_service.dart b/lib/services/ib_engine_service.dart index 135a3502..1f570c09 100644 --- a/lib/services/ib_engine_service.dart +++ b/lib/services/ib_engine_service.dart @@ -249,12 +249,31 @@ class IbEngineServiceImpl implements IbEngineService { if (_ibRawPageData == null) return null; + /// Inline HTML Tags bounded by Backticks(`) are not parsed + /// For example, + /// 26 -> 2^6 + /// whereas, `26` -> `26` + 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!)