-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: 使用innerHTML赋值后转小程序时,a标签转view标签+img转image标签时,把width和height写入style属性 #16780
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||
import { internalComponents } from '@tarojs/shared' | ||||||
import { internalComponents, isString } from '@tarojs/shared' | ||||||
|
||||||
export function makeMap ( | ||||||
str: string, | ||||||
|
@@ -17,6 +17,25 @@ | |||||
iframe: 'web-view' | ||||||
} | ||||||
|
||||||
interface SpecialMap { | ||||||
mapName: (props: Record<string, string | boolean>) => string | ||||||
} | ||||||
|
||||||
const specialElements = new Map<string, SpecialMap>([ | ||||||
['a', { | ||||||
mapName (props) { | ||||||
if (props.as && isString(props.as)) return props.as.toLowerCase() | ||||||
return !props.href || isString(props.href) && (/^javascript/.test(props.href)) ? 'view' : 'navigator' | ||||||
} | ||||||
}], | ||||||
]) | ||||||
|
||||||
export const getSpecialElementMapping = (tag: string, expectsLowerCase:boolean = true) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
tag = expectsLowerCase ? tag.toLowerCase() : tag | ||||||
return specialElements.get(tag) | ||||||
} | ||||||
|
||||||
|
||||||
const internalCompsList = Object.keys(internalComponents) | ||||||
.map(i => i.toLowerCase()) | ||||||
.join(',') | ||||||
|
@@ -25,7 +44,10 @@ | |||||
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) | ||||||
|
||||||
// specialElements | ||||||
export const isSpecialElements = makeMap('a', true) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
a 标签是行内元素啊
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.
a标签在H5下是行内元素。
但在转小程序时,会根据参数的差异,转view 或者navigator(直接用a标签的时候)。
如果是innerHTML里用a标签的话,就直接转的text之前。如果a里套了image,就展示不出来了。
这里就是把innerHTML里a标签的转换逻辑,跟直接用a标签基本对齐