From cfb4a4490f442e2d0638a7d95bed428a73d57d10 Mon Sep 17 00:00:00 2001 From: hardenzheng <18740459807@163.com> Date: Wed, 23 Oct 2024 14:42:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=20=E5=AF=B9=E4=BA=8EinnerHTML?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E5=B0=8F=E7=A8=8B=E5=BA=8F,=20a=3D>?= =?UTF-8?q?text=20=E5=8F=98=E6=88=90=20a=3D>view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-runtime/src/dom-external/inner-html/tags.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/taro-runtime/src/dom-external/inner-html/tags.ts b/packages/taro-runtime/src/dom-external/inner-html/tags.ts index 62886d506ec7..7447b2a269fd 100644 --- a/packages/taro-runtime/src/dom-external/inner-html/tags.ts +++ b/packages/taro-runtime/src/dom-external/inner-html/tags.ts @@ -25,7 +25,7 @@ const internalCompsList = Object.keys(internalComponents) export const isMiniElements = makeMap(internalCompsList, true) // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements -export const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true) +export const isInlineElements = makeMap('i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true) // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements -export const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true) +export const isBlockElements = makeMap('a,address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true) From b81a8f90607e2f50502f7e59e645f2d0719a74d3 Mon Sep 17 00:00:00 2001 From: hardenzheng <18740459807@163.com> Date: Wed, 23 Oct 2024 14:59:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=AF=B9=E4=BA=8EinnerHTML=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E5=B0=8F=E7=A8=8B=E5=BA=8F,=20img=3D>image?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=9C=89width=E5=92=8Cheig?= =?UTF-8?q?ht=EF=BC=8C=E6=8A=8A=E8=BF=992=E4=B8=AA=E5=80=BC=E5=86=99?= =?UTF-8?q?=E5=85=A5style=E5=B1=9E=E6=80=A7=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dom-external/inner-html/parser.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/taro-runtime/src/dom-external/inner-html/parser.ts b/packages/taro-runtime/src/dom-external/inner-html/parser.ts index 683846e7ea09..8a9f60f42254 100644 --- a/packages/taro-runtime/src/dom-external/inner-html/parser.ts +++ b/packages/taro-runtime/src/dom-external/inner-html/parser.ts @@ -47,7 +47,7 @@ export interface Element extends Node { attributes: string[] } -export interface ParsedTaroElement extends TaroElement{ +export interface ParsedTaroElement extends TaroElement { h5tagName?: string } @@ -127,6 +127,20 @@ function format ( parent?.appendChild(text) return text } + // img标签,把width和height写入style + if (child.tagName === 'img') { + let styleText = '' + for (let i = 0; i < child.attributes.length; i++) { + const attr = child.attributes[i] + const [key, value] = splitEqual(attr) + if (key === 'width' || key === 'height') { + styleText += `${key}:${value};` + } else if (key === 'style') { + styleText = `${styleText}${value};` + } + } + child.attributes.push(`style=${styleText.replace(/['"]/g, '')}`) + } const el: ParsedTaroElement = document.createElement(getTagName(child.tagName)) el.h5tagName = child.tagName