Skip to content

Improve the handling of inline-math containing | in the table #9227

Closed
@Zuoqiu-Yingyi

Description

@Zuoqiu-Yingyi
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

无法在表格输入含有 \| 符号的公式

输入后 \| 后刷新一次会变成 |
示例: 在表格内公式中输入 333 \| bar \| 444 后再刷新文档, 该公式会变成 333 | bar | 444

思源笔记-bug反馈-53

该问题产生的原因: Lute 无法正确解析表格中的行内公式

含有符号 | 的行内公式在表格中 应按照如下方案进行转义

$111 | foo | 222$

|                     |
| ------------------- |
| $111 \| foo \| 222$ |

---

$333 \| bar \| 444$

|                       |
| --------------------- |
| $333 \\| bar \\| 444$ |

当前使用的方案

$111 | foo | 222$

|      |
| ---- |
| $111 | foo | 222$ |

---

$333 \| bar \| 444$

|      |
| ---- |
| $333 | bar | 444$ |

受影响的方法

  • Markdown import
  • Markdown export
  • database markdown field
  • kernel API /api/export/exportMdContent
  • kernel API /api/block/getBlockKramdown
  • lute.BlockDOM2StdMd
  • lute.BlockDOM2Md

Expected result

$111 | foo | 222$ 在表格中表示为

|                     |
| ------------------- |
| $111 \| foo \| 222$ |

$333 \| bar \| 444$ 在表格中表示为

|                       |
| --------------------- |
| $333 \\| bar \\| 444$ |

Screenshot or screen recording presentation

No response

Version environment

- Version: 2.10.6
- Operating System: 
- Browser (if used):

Log file

无有效信息输出

More information

No response

Activity

88250

88250 commented on Sep 20, 2023

@88250
Member

能够解决这个情况:

image

但是对于这个情况无法解决(因为解析器解析块级表格 | 优先级高于行级):

image

changed the title [-]Can't correct handle inline formula in table[/-] [+]Improve the handling of inline-level formulas containing escape char `\` in the table[/+] on Sep 20, 2023
self-assigned this
on Sep 20, 2023
added this to the 2.10.7 milestone on Sep 20, 2023
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 20, 2023

@Zuoqiu-Yingyi
ContributorAuthor

但是对于这个情况无法解决(因为解析器解析块级表格 | 优先级高于行级):

image

保证表格内行内公式与表格外行内公式相同的内容渲染一致即可

88250

88250 commented on Sep 20, 2023

@88250
Member
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 20, 2023

@Zuoqiu-Yingyi
ContributorAuthor

嗯,等发版看看。

我拉取后试了一下, 发现导出预览模式下依旧未正确渲染

该问题同时影响导出的内容

  • 导出 *.png
  • 导出 *.pdf
  • 导出 *.docx
  • 导出 *.html

image

88250

88250 commented on Sep 20, 2023

@88250
Member

多谢测试,稍后再改改。

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 20, 2023

@Zuoqiu-Yingyi
ContributorAuthor

现在貌似引入了更多问题...

1. 表格中行内公式中的 | 在刷新后均被替换为 \|

思源笔记-bug反馈-54

2. 表格中行内公式中的 \\| 在刷新后无法正确解析

思源笔记-bug反馈-55

  • 奇数个 \ + \ 可以正确解析
  • 偶数个 \ + | 无法正确解析

42 remaining items

88250

88250 commented on Sep 24, 2023

@88250
Member

感谢测试,已经修改提交,这次应该差不多了。

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 24, 2023

@Zuoqiu-Yingyi
ContributorAuthor

感谢测试,已经修改提交,这次应该差不多了。

之前已经修复的问题再次出现了...

模板

|     |                                                   <span data-type="inline-math" data-subtype="math" data-content="000" contenteditable="false" class="render-node"></span>                                                   |     |
| --- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | --- |
|     |                                         <span data-type="inline-math" data-subtype="math" data-content="&amp;#124;111&amp;#124;" contenteditable="false" class="render-node"></span>                                         |     |
|     |                               <span data-type="inline-math" data-subtype="math" data-content="&amp;#124;&amp;#124;222&amp;#124;&amp;#124;" contenteditable="false" class="render-node"></span>                               |     |
|     |                     <span data-type="inline-math" data-subtype="math" data-content="&amp;#124;&amp;#124;&amp;#124;333&amp;#124;&amp;#124;&amp;#124;" contenteditable="false" class="render-node"></span>                     |     |
|     |           <span data-type="inline-math" data-subtype="math" data-content="&amp;#124;&amp;#124;&amp;#124;&amp;#124;444&amp;#124;&amp;#124;&amp;#124;&amp;#124;" contenteditable="false" class="render-node"></span>           |     |
|     | <span data-type="inline-math" data-subtype="math" data-content="&amp;#124;&amp;#124;&amp;#124;&amp;#124;&amp;#124;555&amp;#124;&amp;#124;&amp;#124;&amp;#124;&amp;#124;" contenteditable="false" class="render-node"></span> |     |

渲染结果:
image

期待的导出内容:

|     |           $000$           |     |
| --- | :-----------------------: | --- |
|     |         $\|111\|$         |     |
|     |       $\|\|222\|\|$       |     |
|     |     $\|\|\|333\|\|\|$     |     |
|     |   $\|\|\|\|444\|\|\|\|$   |     |
|     | $\|\|\|\|\|555\|\|\|\|\|$ |     |

实际导出内容:

|     |                $000$                |     |
| --- | :---------------------------------: | --- |
|     |             $\\|111\\|$             |     |
|     |          $\\|\\|222\\|\\|$          |     |
|     |       $\\|\\|\\|333\\|\\|\\|$       |     |
|     |    $\\|\\|\\|\\|444\\|\\|\\|\\|$    |     |
|     | $\\|\\|\\|\\|\\|555\\|\\|\\|\\|\\|$ |     |
88250

88250 commented on Sep 25, 2023

@88250
Member

我看你上面回复的是这个期待哦:

image

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 25, 2023

@Zuoqiu-Yingyi
ContributorAuthor

我看你上面回复的是这个期待哦:

image

图中里面转换前的内容是指非表格内的公式导出的内容,转换后的内容是指表格内公式导出的内容

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 25, 2023

@Zuoqiu-Yingyi
ContributorAuthor

再详细描述一下导出需求

需求 1

image
希望导出为

|     |           |     |
| --- | --------- | --- |
|     | $\|111\|$ |     |

需求 2

image
希望导出为

|     |             |     |
| --- | ----------- | --- |
|     | $\\|111\\|$ |     |

需求 3

image
希望导出为

|     |               |     |
| --- | ------------- | --- |
|     | $\\\|111\\\|$ |     |
88250

88250 commented on Sep 25, 2023

@88250
Member

@Zuoqiu-Yingyi 好的,叒改了改,麻烦测试。

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Sep 25, 2023

@Zuoqiu-Yingyi
ContributorAuthor

@Zuoqiu-Yingyi 好的,叒改了改,麻烦测试。

还是不行啊, 满足 需求 2需求 3, 但仍不满足 需求 1:

image

期望导出为

|     |           |     |
| --- | --------- | --- |
|     | $\|111\|$ |     |

实际导出为

|     |             |     |
| --- | ----------- | --- |
|     | $\\|000\\|$ |     |
88250

88250 commented on Sep 25, 2023

@88250
Member

感谢测试,这次应该都解决了,相关测试用例已经在 Lute 中添加。

08906F92D0577EBECC559754B1916462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @88250@Zuoqiu-Yingyi

      Issue actions

        Improve the handling of inline-math containing `|` in the table · Issue #9227 · siyuan-note/siyuan