@@ -2697,4 +2697,335 @@ describe('html to snapshot', () => {
26972697 } ) ;
26982698 expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
26992699 } ) ;
2700+
2701+ test ( 'block level element in b should not be treated as inline' , async ( ) => {
2702+ const html = template ( `<b><p><span>aaa</span></p></b>` ) ;
2703+ const blockSnapshot : BlockSnapshot = {
2704+ type : 'block' ,
2705+ id : 'matchesReplaceMap[0]' ,
2706+ flavour : 'affine:note' ,
2707+ props : {
2708+ xywh : '[0,0,800,95]' ,
2709+ background : DefaultTheme . noteBackgrounColor ,
2710+ index : 'a0' ,
2711+ hidden : false ,
2712+ displayMode : NoteDisplayMode . DocAndEdgeless ,
2713+ } ,
2714+ children : [
2715+ {
2716+ type : 'block' ,
2717+ id : 'matchesReplaceMap[1]' ,
2718+ flavour : 'affine:paragraph' ,
2719+ props : {
2720+ type : 'text' ,
2721+ text : {
2722+ '$blocksuite:internal:text$' : true ,
2723+ delta : [
2724+ {
2725+ insert : 'aaa' ,
2726+ } ,
2727+ ] ,
2728+ } ,
2729+ } ,
2730+ children : [ ] ,
2731+ } ,
2732+ ] ,
2733+ } ;
2734+
2735+ const htmlAdapter = new HtmlAdapter ( createJob ( ) , provider ) ;
2736+ const rawBlockSnapshot = await htmlAdapter . toBlockSnapshot ( {
2737+ file : html ,
2738+ } ) ;
2739+ expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
2740+ } ) ;
2741+
2742+ describe ( 'strong element' , ( ) => {
2743+ test ( 'should not be bold when font-weight is normal' , async ( ) => {
2744+ const html = template ( `<span style="font-weight: normal;">aaa</span>` ) ;
2745+ const blockSnapshot : BlockSnapshot = {
2746+ type : 'block' ,
2747+ id : 'matchesReplaceMap[0]' ,
2748+ flavour : 'affine:note' ,
2749+ props : {
2750+ xywh : '[0,0,800,95]' ,
2751+ background : DefaultTheme . noteBackgrounColor ,
2752+ index : 'a0' ,
2753+ hidden : false ,
2754+ displayMode : NoteDisplayMode . DocAndEdgeless ,
2755+ } ,
2756+ children : [
2757+ {
2758+ type : 'block' ,
2759+ id : 'matchesReplaceMap[1]' ,
2760+ flavour : 'affine:paragraph' ,
2761+ props : {
2762+ type : 'text' ,
2763+ text : {
2764+ '$blocksuite:internal:text$' : true ,
2765+ delta : [
2766+ {
2767+ insert : 'aaa' ,
2768+ } ,
2769+ ] ,
2770+ } ,
2771+ } ,
2772+ children : [ ] ,
2773+ } ,
2774+ ] ,
2775+ } ;
2776+
2777+ const htmlAdapter = new HtmlAdapter ( createJob ( ) , provider ) ;
2778+ const rawBlockSnapshot = await htmlAdapter . toBlockSnapshot ( {
2779+ file : html ,
2780+ } ) ;
2781+ expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
2782+ } ) ;
2783+
2784+ test ( 'should be bold when font-weight is bold or 500-900 ' , async ( ) => {
2785+ const html = template (
2786+ `<p><span style="font-weight: bold;">aaa</span><span style="font-weight: 100;">aaa</span><span style="font-weight: 500;">bbb</span><span style="font-weight: 200;">bbb</span><span style="font-weight: 600;">ccc</span><span style="font-weight: 300;">ccc</span><span style="font-weight: 700;">ddd</span></p>`
2787+ ) ;
2788+ const blockSnapshot : BlockSnapshot = {
2789+ type : 'block' ,
2790+ id : 'matchesReplaceMap[0]' ,
2791+ flavour : 'affine:note' ,
2792+ props : {
2793+ xywh : '[0,0,800,95]' ,
2794+ background : DefaultTheme . noteBackgrounColor ,
2795+ index : 'a0' ,
2796+ hidden : false ,
2797+ displayMode : NoteDisplayMode . DocAndEdgeless ,
2798+ } ,
2799+ children : [
2800+ {
2801+ type : 'block' ,
2802+ id : 'matchesReplaceMap[1]' ,
2803+ flavour : 'affine:paragraph' ,
2804+ props : {
2805+ type : 'text' ,
2806+ text : {
2807+ '$blocksuite:internal:text$' : true ,
2808+ delta : [
2809+ {
2810+ attributes : {
2811+ bold : true ,
2812+ } ,
2813+ insert : 'aaa' ,
2814+ } ,
2815+ {
2816+ insert : 'aaa' ,
2817+ } ,
2818+ {
2819+ attributes : {
2820+ bold : true ,
2821+ } ,
2822+ insert : 'bbb' ,
2823+ } ,
2824+ {
2825+ insert : 'bbb' ,
2826+ } ,
2827+ {
2828+ attributes : {
2829+ bold : true ,
2830+ } ,
2831+ insert : 'ccc' ,
2832+ } ,
2833+ {
2834+ insert : 'ccc' ,
2835+ } ,
2836+ {
2837+ attributes : {
2838+ bold : true ,
2839+ } ,
2840+ insert : 'ddd' ,
2841+ } ,
2842+ ] ,
2843+ } ,
2844+ } ,
2845+ children : [ ] ,
2846+ } ,
2847+ ] ,
2848+ } ;
2849+
2850+ const htmlAdapter = new HtmlAdapter ( createJob ( ) , provider ) ;
2851+ const rawBlockSnapshot = await htmlAdapter . toBlockSnapshot ( {
2852+ file : html ,
2853+ } ) ;
2854+ expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
2855+ } ) ;
2856+ } ) ;
2857+
2858+ test ( 'should be italic when tag is i or em or span with style font-style: italic' , async ( ) => {
2859+ const html = template (
2860+ `<p><i>aaa</i><span>aaa</span><em>bbb</em><span>bbb</span><span style="font-style: italic;">ccc</span></p>`
2861+ ) ;
2862+ const blockSnapshot : BlockSnapshot = {
2863+ type : 'block' ,
2864+ id : 'matchesReplaceMap[0]' ,
2865+ flavour : 'affine:note' ,
2866+ props : {
2867+ xywh : '[0,0,800,95]' ,
2868+ background : DefaultTheme . noteBackgrounColor ,
2869+ index : 'a0' ,
2870+ hidden : false ,
2871+ displayMode : NoteDisplayMode . DocAndEdgeless ,
2872+ } ,
2873+ children : [
2874+ {
2875+ type : 'block' ,
2876+ id : 'matchesReplaceMap[1]' ,
2877+ flavour : 'affine:paragraph' ,
2878+ props : {
2879+ type : 'text' ,
2880+ text : {
2881+ '$blocksuite:internal:text$' : true ,
2882+ delta : [
2883+ {
2884+ attributes : {
2885+ italic : true ,
2886+ } ,
2887+ insert : 'aaa' ,
2888+ } ,
2889+ {
2890+ insert : 'aaa' ,
2891+ } ,
2892+ {
2893+ attributes : {
2894+ italic : true ,
2895+ } ,
2896+ insert : 'bbb' ,
2897+ } ,
2898+ {
2899+ insert : 'bbb' ,
2900+ } ,
2901+ {
2902+ attributes : {
2903+ italic : true ,
2904+ } ,
2905+ insert : 'ccc' ,
2906+ } ,
2907+ ] ,
2908+ } ,
2909+ } ,
2910+ children : [ ] ,
2911+ } ,
2912+ ] ,
2913+ } ;
2914+
2915+ const htmlAdapter = new HtmlAdapter ( createJob ( ) , provider ) ;
2916+ const rawBlockSnapshot = await htmlAdapter . toBlockSnapshot ( {
2917+ file : html ,
2918+ } ) ;
2919+ expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
2920+ } ) ;
2921+
2922+ test ( 'should be underline when tag is u or span with style text-decoration: underline' , async ( ) => {
2923+ const html = template (
2924+ `<p><u>aaa</u><span>aaa</span><span style="text-decoration: underline;">bbb</span></p>`
2925+ ) ;
2926+ const blockSnapshot : BlockSnapshot = {
2927+ type : 'block' ,
2928+ id : 'matchesReplaceMap[0]' ,
2929+ flavour : 'affine:note' ,
2930+ props : {
2931+ xywh : '[0,0,800,95]' ,
2932+ background : DefaultTheme . noteBackgrounColor ,
2933+ index : 'a0' ,
2934+ hidden : false ,
2935+ displayMode : NoteDisplayMode . DocAndEdgeless ,
2936+ } ,
2937+ children : [
2938+ {
2939+ type : 'block' ,
2940+ id : 'matchesReplaceMap[1]' ,
2941+ flavour : 'affine:paragraph' ,
2942+ props : {
2943+ type : 'text' ,
2944+ text : {
2945+ '$blocksuite:internal:text$' : true ,
2946+ delta : [
2947+ {
2948+ attributes : {
2949+ underline : true ,
2950+ } ,
2951+ insert : 'aaa' ,
2952+ } ,
2953+ {
2954+ insert : 'aaa' ,
2955+ } ,
2956+ {
2957+ attributes : {
2958+ underline : true ,
2959+ } ,
2960+ insert : 'bbb' ,
2961+ } ,
2962+ ] ,
2963+ } ,
2964+ } ,
2965+ children : [ ] ,
2966+ } ,
2967+ ] ,
2968+ } ;
2969+
2970+ const htmlAdapter = new HtmlAdapter ( createJob ( ) , provider ) ;
2971+ const rawBlockSnapshot = await htmlAdapter . toBlockSnapshot ( {
2972+ file : html ,
2973+ } ) ;
2974+ expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
2975+ } ) ;
2976+
2977+ test ( 'should be strike when tag is del or span with style text-decoration: line-through' , async ( ) => {
2978+ const html = template (
2979+ `<p><del>aaa</del><span>aaa</span><span style="text-decoration: line-through;">bbb</span></p>`
2980+ ) ;
2981+ const blockSnapshot : BlockSnapshot = {
2982+ type : 'block' ,
2983+ id : 'matchesReplaceMap[0]' ,
2984+ flavour : 'affine:note' ,
2985+ props : {
2986+ xywh : '[0,0,800,95]' ,
2987+ background : DefaultTheme . noteBackgrounColor ,
2988+ index : 'a0' ,
2989+ hidden : false ,
2990+ displayMode : NoteDisplayMode . DocAndEdgeless ,
2991+ } ,
2992+ children : [
2993+ {
2994+ type : 'block' ,
2995+ id : 'matchesReplaceMap[1]' ,
2996+ flavour : 'affine:paragraph' ,
2997+ props : {
2998+ type : 'text' ,
2999+ text : {
3000+ '$blocksuite:internal:text$' : true ,
3001+ delta : [
3002+ {
3003+ attributes : {
3004+ strike : true ,
3005+ } ,
3006+ insert : 'aaa' ,
3007+ } ,
3008+ {
3009+ insert : 'aaa' ,
3010+ } ,
3011+ {
3012+ attributes : {
3013+ strike : true ,
3014+ } ,
3015+ insert : 'bbb' ,
3016+ } ,
3017+ ] ,
3018+ } ,
3019+ } ,
3020+ children : [ ] ,
3021+ } ,
3022+ ] ,
3023+ } ;
3024+
3025+ const htmlAdapter = new HtmlAdapter ( createJob ( ) , provider ) ;
3026+ const rawBlockSnapshot = await htmlAdapter . toBlockSnapshot ( {
3027+ file : html ,
3028+ } ) ;
3029+ expect ( nanoidReplacement ( rawBlockSnapshot ) ) . toEqual ( blockSnapshot ) ;
3030+ } ) ;
27003031} ) ;
0 commit comments