-
Notifications
You must be signed in to change notification settings - Fork 43
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
fix #230 #232
Conversation
feat(utils): allow Parser to ignore tag
base分支错了... |
packages/utils/bbcode/convert.ts
Outdated
@@ -151,6 +151,12 @@ function toVNode( | |||
return vnode; | |||
} | |||
|
|||
let UserConverterFnMap: Record<string, ConverterFn> = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好不要这么写吧,跟现在一样是纯函数比较好...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成类了
不用close啊,base分支可以直接改的 |
以为不能改,顺手就关了 |
Preview DeploymentSites https://pr-232-sites--bangumi-next.netlify.app Storybook https://pr-232-storybook--bangumi-next.netlify.app |
Codecov ReportAttention:
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. |
如果传进来的converterFn需要转换children呢…? |
定义了 url 的映射转化,嵌套 children 都是使用这个映射规则。有新的自定义需求,继续在 convertMap 里面设置 |
我的意思是,这里传进来的convert fn有可能需要转换children吧? 比如你内置的convert fn调用了toVNode转换子节点,但是convert FN现在没法使用当前converter的toVNode |
toVNode只是一个通用的工具函数,使用自定义转化函数后,toVNode 就没有使用。 |
不能吧…这个转换是森林的各个树的顶部开始遍历,按照现在的PR的情况,如果一个节点被convert map进行处理的话,他的子节点是不会被Converter处理的。 你考虑一下,实现一个user convert,所有的size tag的size都+1,然后处理一个size里面有b,u,mask等元素的BBCODE片段?
这里期待的转换结果是 |
你的子节点是在内置的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 |
🤔我觉得有可能会有不忽略的情况? 其实我现在都没想到convert map在什么情况下会用到… |
这个只是保留的功能。对于高频使用的自定义 tag,直接在 convert.ts 源码里面添加。毕竟这个不是对外用的包。 |
这个只要给convertfn加一个converter参数就可以解决了吧…到底convert map的convertfn用不用converter来转子节点就是后面的事情了,而且也不需要改test,只需要改一下type和Converter.convert |
@zhifengle this pull request is now in conflict 😩 |
@zhifengle this pull request is now in conflict 😩 |
@zhifengle this pull request is now in conflict 😩 |
@zhifengle this pull request is now in conflict 😩 |
feat(utils): allow Parser to ignore tag
fix #230