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

feat(video-module): 为视频元素添加文本对齐属性 #429

Merged
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
2 changes: 2 additions & 0 deletions packages/video-module/__tests__/parse-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('video - parse html', () => {
width: '500',
height: '300',
style: {},
textAlign: 'center',
children: [{ text: '' }], // void 元素有一个空 text
})
})
Expand All @@ -99,6 +100,7 @@ describe('video - parse html', () => {
width: 'auto',
height: 'auto',
style: {},
textAlign: 'center',
children: [{ text: '' }], // void 元素有一个空 text
})
})
Expand Down
10 changes: 7 additions & 3 deletions packages/video-module/src/module/parse-elem-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function genVideoElem(
width = 'auto',
height = 'auto',
style: videoStyle = {},
textAlign = 'center',
): VideoElement {
return {
type: 'video',
Expand All @@ -25,6 +26,7 @@ function genVideoElem(
height,
style,
children: [{ text: '' }], // void 元素有一个空 text
textAlign,
}
}

Expand All @@ -35,7 +37,7 @@ function parseHtml(elem: DOMElement, _children: Descendant[], _editor: IDomEdito
let width = 'auto'
let height = 'auto'
let style = {}

let textAlign = 'center'
// <iframe> 形式
const $iframe = $elem.find('iframe')

Expand All @@ -45,7 +47,8 @@ function parseHtml(elem: DOMElement, _children: Descendant[], _editor: IDomEdito
style = $iframe.attr('style') || ''
style = styleStringToObject(style)
src = $iframe[0].outerHTML
return genVideoElem(src, poster, width, height, style)
textAlign = styleStringToObject($elem.attr('style') || '')['text-align'] || 'center'
return genVideoElem(src, poster, width, height, style, textAlign)
}

// <video> 形式
Expand All @@ -64,7 +67,8 @@ function parseHtml(elem: DOMElement, _children: Descendant[], _editor: IDomEdito
poster = $video.attr('poster') || ''
style = $video.attr('style') || ''
style = styleStringToObject(style)
return genVideoElem(src, poster, width, height, style)
textAlign = styleStringToObject($elem.attr('style') || '')['text-align'] || 'center'
return genVideoElem(src, poster, width, height, style, textAlign)
}

export const parseHtmlConf = {
Expand Down
Loading