bangumi / frontend

https://next.bgm38.com/
BSD 3-Clause "New" or "Revised" License
104 stars 43 forks source link

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

Open trim21 opened 1 year ago

trim21 commented 1 year ago
  test('render code by custom converter, nested', () => {
    const input = '[b][url]qq[/url][/b]';
    expect(
      render(input, {
        url: (node) => {
          return '[url]convert map[/url]';
        },
      }),
    ).toBe('<strong>[url]convert map[/url]</strong>');
  });
 PASS  packages/website/src/hooks/use-pagination.spec.tsx
 FAIL  packages/utils/bbcode/__test__/html.test.ts
  ● html render bbcode string › render code by custom converter

    expect(received).toBe(expected) // Object.is equality

    Expected: "<strong>[url]convert map[/url]</strong>"
    Received: "<strong>[url]qq[/url]</strong>"

      249 |         },
      250 |       }),
    > 251 |     ).toBe(
          |       ^
      252 |       '<strong>[url]convert map[/url]</strong>',
      253 |     );
      254 |   });

      at Object.toBe (packages/utils/bbcode/__test__/html.test.ts:251:7)

也可以直接用这个 branch,这个case已经放在里面了 https://github.com/bangumi/frontend/compare/bbcode/convert-map-nested?expand=1

trim21 commented 1 year ago

@zhifengle 有兴趣修一下吗(

zhifengle commented 1 year ago

@zhifengle 有兴趣修一下吗(

好的,我处理一下

trim21 commented 1 year ago

正好还有个场景,希望parser再加一个参数可以忽略某些BBCODE标签,比如用户主页是不支持img标签的。

zhifengle commented 1 year ago

有个疑问 [url]qq[/url] 的使用场景是? 目前 Parser 是把 [url]qq[/url] 当作非法的 BBCode。 目前已修复 [url]http://qq.com[/url] 的情况

trim21 commented 1 year ago

这里是个convertMap没正常工作的例子,不是真正的使用场景。[url]http://qq.com[/url] 也可以