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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packages/utils/bbcode/__test__/html.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { STICKER_DOMAIN_URL } from '../constants';
import { renderNodes, renderNode, render } from '../html';
import { renderNodes, renderNode, render, renderWithParser } from '../html';
import { Parser } from '../parser';
import type { VNode } from '../types';

describe('html render vnode', () => {
Expand Down Expand Up @@ -239,6 +240,29 @@ describe('html render bbcode string', () => {
'<div class="codeHighlight"><pre>ss[b]加粗\n换行了[/b](bgm38) [/fafa [code]</pre></div>',
);
});

test('render code by custom converter, nested', () => {
const input = '[b][url]http://qq.com[/url][/b]';
expect(
render(input, {
url: (node) => {
return '[url]convert map[/url]';
},
}),
).toBe('<strong>[url]convert map[/url]</strong>');
});
test('render code with Parser, nested', () => {
const input = '[b]加粗[size=16]16px[img]http://chii.in/img/ico/bgm88-31.gif[/img][/size][/b]';
expect(
renderWithParser(new Parser(input, [], ['img']), {
url: (node) => {
return '[url]convert map[/url]';
},
}),
).toBe(
'<strong>加粗<span style="font-size:16px;line-height:16px">16px[img]http://chii.in/img/ico/bgm88-31.gif[/img]</span></strong>',
);
});
test('should render sticker', () => {
expect(render('(bgm01)')).toContain('/img/smiles/bgm/01.png');
expect(render('(bgm38)')).toContain('/img/smiles/tv/15.gif');
Expand Down
36 changes: 36 additions & 0 deletions packages/utils/bbcode/__test__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ describe('bbcode parser', () => {
];
expect(getNodes(input)).toEqual(expect.arrayContaining(tests));
});
test('ignore img bbcode', () => {
const input = `存放于其他网络服务器的图片:
[img]http://chii.in/img/ico/bgm88-31.gif[/img]`;
const tests: CodeNodeTypes[] = [
'存放于其他网络服务器的图片:\n',
'[img]http://chii.in/img/ico/bgm88-31.gif[/img]',
];
expect(new Parser(input, [], ['img']).parse()).toEqual(expect.arrayContaining(tests));
});
test('simple bbcode', () => {
const input = `我是[mask]马赛克文字[/mask]
[s]删除线文字[/s]
Expand Down Expand Up @@ -320,6 +329,33 @@ describe('bbcode parser', () => {
]),
);
});
test('merge tags with ignore case', () => {
const fn = (): boolean => true;
const tags = mergeTags(
[
'i',
'b',
{
name: 's',
schema: {
s: fn,
},
},
],
[
{
name: 'i',
schema: {
i: fn,
},
},
's',
'mybbcode',
],
['i', 's'],
);
expect(tags).toEqual(expect.arrayContaining(['b', 'mybbcode']));
});
test('subject bbcode', () => {
const tests: Array<[string, CodeNodeTypes[]]> = [
[
Expand Down
Loading