Skip to content

Commit

Permalink
feat(video-module): add text alignment attribute (#429)
Browse files Browse the repository at this point in the history
- 在解析视频元素 HTML 时,优化了文本对齐方式的获取逻辑
- 此修改使得视频元素可以正确地继承父元素的文本对齐方式
- 更新了相关测试用例,增加了对文本对齐属性的检查
- #428
  • Loading branch information
arcovery authored Dec 13, 2024
1 parent 7c92198 commit cb16457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit cb16457

Please sign in to comment.