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

拿到带有font-family的html字符串 使用BraftEditor.createEditorState(html)后 字体样式丢失 #775

Open
nannan0109 opened this issue May 20, 2020 · 8 comments

Comments

@nannan0109
Copy link

拿到带有font-family的html字符串 使用BraftEditor.createEditorState(html)后 字体样式丢失
例如:
<p><span style="font-family:STKaiti,KaiTi,sans-serif"><span style="font-size:40px">这里应该是楷体</span></span></p>
渲染到编辑器框里 丢失了楷体这个字体

@Mrtaochen
Copy link

同样遇到了 有没有解决方案呢

@itibbers
Copy link

itibbers commented Sep 1, 2020

蹲一个解决方案

@itibbers
Copy link

itibbers commented Sep 1, 2020

看了下源码,我是这样解决的:

const fontFamilies = [
  { name: '思源黑体', family: '思源黑体' },
  { name: '隶书', family: '隶书' },
  { name: '楷体', family: '楷体,sans-serif' },
]

// 需要把你自定义的字体作为options传入进去
BraftEditor.createEditorState(ele.innerHtml, { fontFamilies: fontFamilies })

@Mrtaochen
Copy link

Mrtaochen commented Sep 1, 2020 via email

@Ryan-lixuan
Copy link

Ryan-lixuan commented Nov 12, 2020

看了下原始码,我是这样解决的:

const  fontFamilies  =  [ 
  { 名称:'思源黑体'  家族:'思源黑体'  } 
  { 名称:'隶书'  家族:'隶书'  } 
  { 名称:'楷体'  家族:'楷体,sans-serif'  } 
]

//需要把你自定义的字体作为选项加入进去
BraftEditor.createEditorState (ELE.innerHTML的, {  fontFamilies:fontFamilies  } 

哇,谢谢大佬,困扰很久,终于解决

@hyl1374961656
Copy link

同一行文字在输入时切换字体顶部显示的字体不会变但是内容的字体是改变了的

@thelittlemaster
Copy link

同一行文字在输入时切换字体顶部显示的字体不会变但是内容的字体是改变了的

有没有解决办法呢,我也遇到了同样的问题。不仅是字体,字号也会出现同样的问题

@hyl1374961656
Copy link

同一行文字在输入时切换字体顶部显示的字体不会变但是内容的字体是改变了的

有没有解决办法呢,我也遇到了同样的问题。不仅是字体,字号也会出现同样的问题

没解决,作者好久都不更新了,建议换插件用吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants