Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #230 #232

Closed
wants to merge 5 commits into from
Closed

Conversation

zhifengle
Copy link
Contributor

@zhifengle zhifengle commented Nov 30, 2022

feat(utils): allow Parser to ignore tag
fix #230

trim21 and others added 2 commits November 30, 2022 08:35
@trim21
Copy link
Contributor

trim21 commented Nov 30, 2022

base分支错了...

@trim21 trim21 changed the base branch from bbcode/convert-map-nested to master November 30, 2022 15:03
@@ -151,6 +151,12 @@ function toVNode(
return vnode;
}

let UserConverterFnMap: Record<string, ConverterFn> = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好不要这么写吧,跟现在一样是纯函数比较好...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成类了

@zhifengle zhifengle closed this Nov 30, 2022
@trim21
Copy link
Contributor

trim21 commented Nov 30, 2022

不用close啊,base分支可以直接改的

@trim21 trim21 reopened this Nov 30, 2022
@zhifengle
Copy link
Contributor Author

不用close啊,base分支可以直接改的

以为不能改,顺手就关了

@github-actions
Copy link
Contributor

github-actions bot commented Nov 30, 2022

@codecov
Copy link

codecov bot commented Nov 30, 2022

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (ac8b427) 92.00% compared to head (c3b9a8a) 92.05%.
Report is 420 commits behind head on master.

Files Patch % Lines
packages/utils/bbcode/convert.ts 93.18% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #232      +/-   ##
==========================================
+ Coverage   92.00%   92.05%   +0.05%     
==========================================
  Files          70       70              
  Lines        3688     3726      +38     
  Branches      423      432       +9     
==========================================
+ Hits         3393     3430      +37     
- Misses        293      294       +1     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@trim21
Copy link
Contributor

trim21 commented Dec 1, 2022

如果传进来的converterFn需要转换children呢…?

@zhifengle
Copy link
Contributor Author

zhifengle commented Dec 1, 2022

如果传进来的converterFn需要转换children呢…?

定义了 url 的映射转化,嵌套 children 都是使用这个映射规则。有新的自定义需求,继续在 convertMap 里面设置
如果相同的 node 需要不同的转化,可以分两次自定义规则 render

@trim21
Copy link
Contributor

trim21 commented Dec 1, 2022

我的意思是,这里传进来的convert fn有可能需要转换children吧?

比如你内置的convert fn调用了toVNode转换子节点,但是convert FN现在没法使用当前converter的toVNode

@zhifengle
Copy link
Contributor Author

zhifengle commented Dec 1, 2022

我的意思是,这里传进来的convert fn有可能需要转换children吧?

比如你内置的convert fn调用了toVNode转换子节点,但是convert FN现在没法使用当前converter的toVNode

toVNode只是一个通用的工具函数,使用自定义转化函数后,toVNode 就没有使用。
children 也是 BBCode 节点,在 convertMap 是能覆盖到的。自定义转化 Node 时,children 的转化方式已经交给调用者了。
这样吧,你提供一个案例,我来解释一下。

@trim21
Copy link
Contributor

trim21 commented Dec 1, 2022

不能吧…这个转换是森林的各个树的顶部开始遍历,按照现在的PR的情况,如果一个节点被convert map进行处理的话,他的子节点是不会被Converter处理的。

你考虑一下,实现一个user convert,所有的size tag的size都+1,然后处理一个size里面有b,u,mask等元素的BBCODE片段?

[size=18][b]1[/b][/size]

这里期待的转换结果是 <p style="font-size : 19"><strong>1</strong></p>

@trim21
Copy link
Contributor

trim21 commented Dec 1, 2022

你的子节点是在内置的convert fn里面遍历的,所以传进来的convert Fn要正常工作也需要进行对应的遍历。

@zhifengle
Copy link
Contributor Author

你的子节点是在内置的convert fn里面遍历的,所以传进来的convert Fn要正常工作也需要进行对应的遍历。

  test('should render custom node', () => {
    const input = '[size=18][b]1[/b][/size]';
    expect(
      render(input, {
        size: (node) => {
          // console.log(node);
          return {
            type: 'p',
            style: {
              'font-size': '19px',
            },
            children: [{
              type: 'strong',
              children: ['1']
            }]
          };
        },
      }),
    ).toBe('<p style="font-size:19px"><strong>1</strong></p>');
  });

我省略了判断 18 [b]1[/b] 的逻辑了。思路就是这样的

@trim21
Copy link
Contributor

trim21 commented Dec 1, 2022

🤔我觉得有可能会有不忽略的情况?

其实我现在都没想到convert map在什么情况下会用到…

@zhifengle
Copy link
Contributor Author

🤔我觉得有可能会有不忽略的情况?

其实我现在都没想到convert map在什么情况下会用到…

这个只是保留的功能。对于高频使用的自定义 tag,直接在 convert.ts 源码里面添加。毕竟这个不是对外用的包。

@trim21
Copy link
Contributor

trim21 commented Dec 1, 2022

这个只要给convertfn加一个converter参数就可以解决了吧…到底convert map的convertfn用不用converter来转子节点就是后面的事情了,而且也不需要改test,只需要改一下type和Converter.convert

@mergify
Copy link

mergify bot commented Mar 22, 2023

@zhifengle this pull request is now in conflict 😩

@mergify mergify bot added the conflict label Mar 22, 2023
@mergify mergify bot removed the conflict label Jul 16, 2023
@mergify
Copy link

mergify bot commented Jul 16, 2023

@zhifengle this pull request is now in conflict 😩

@mergify mergify bot added the conflict label Jul 16, 2023
@mergify mergify bot removed the conflict label Aug 23, 2023
@mergify
Copy link

mergify bot commented Aug 23, 2023

@zhifengle this pull request is now in conflict 😩

@mergify mergify bot added the conflict label Aug 23, 2023
@mergify mergify bot removed the conflict label Dec 19, 2023
Copy link

mergify bot commented Dec 19, 2023

@zhifengle this pull request is now in conflict 😩

@mergify mergify bot added the conflict label Dec 19, 2023
@zhifengle zhifengle closed this Dec 19, 2023
@mergify mergify bot removed the conflict label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug(bbcode): converterMap 在某些情况下不能正常工作
2 participants