NativeScript / NativeScript/angular

Render unsafe latex html string using Html View

未关闭
#138 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
55
派生
13
平均合并
16 分钟
30 天内合并 PR
1

描述

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: "@angular/compiler-cli": "~18.0.0",
  • Cross-platform modules:
  • Android Runtime: "@nativescript/android": "8.8.1-next.2024-07-19-10014251437",
  • iOS Runtime:
  • Plugin(s): "katex": "^0.16.11",, "@types/katex": "^0.16.7",
  • NativeScript-Angular: "@nativescript/angular": "^18.0.0",
  • Angular: "@angular/core": "~18.0.0",

Describe the bug

I created unsafe html string using

this._safeHtml = this.domSanitizer.bypassSecurityTrustHtml(htmlString);

Attempting to render this content using Html View using property binding like so

<HtmlView [html]="_safeHtml"></HtmlView>

results to the following error

An uncaught Exception occurred on "main" thread.
Calling js method onCreateView failed
TypeError: value.search is not a function

StackTrace:
[html:setNative]...

NB:

  • Using the approach below:
    <HtmlView html="{{_safeHtml}}"></HtmlView>

does not render the string(latex string) as expected and also throws a safevalue must use [property]=binding error on the screen.

  • The string renders as expected in pure angular project using the following code:
    <div [innerHTML]="_safeHtml"></div>

A sample string to be rendered looks like so
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>s</mi><mi>u</mi><msubsup><mi>m</mi><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><mo stretchy="false">(</mo><msubsup><mi>x</mi><mi>i</mi><mn>2</mn></msubsup><mo>−</mo><mi>o</mi><mi>v</mi><mi>e</mi><mi>r</mi><mi>l</mi><mi>i</mi><mi>n</mi><mi>e</mi><msup><mi>x</mi><mn>2</mn></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">sum_{i=1}^n(x_i^2 - overline{x}^2)</annotation></semantics></math></span>

What could be a recommended way to solve this situation or a walkaround?

To Reproduce

Expected behavior

Sample project

Additional context

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 HtmlView 的 html 属性和 Angular [html] 绑定路径开始;报告中的失败是传入 DomSanitizer 的可信值时出现 value.search is not a function。使用提供的 KaTeX HTML 重现该问题,并通过在没有异常或安全值警告的情况下渲染它,同时保留预期的标记,来验证完成情况。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
mobile-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
28/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。