Updated conten formatting.

This commit is contained in:
Grzegorz Leoniec 2019-01-28 11:07:13 +01:00
parent 35ce1fda07
commit 35d609a50f
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377
2 changed files with 23 additions and 47 deletions

View File

@ -78,45 +78,6 @@ blockquote {
}
}
.hc-editor-content {
h1,
h2,
h3,
h4,
h5,
h6 {
&:not(:first-child) {
margin-top: 2rem;
}
}
p {
&:not(:last-child) {
margin-top: 0;
margin-bottom: 0;
}
}
dl,
ol,
ul,
blockquote,
pre,
table {
&:not(:first-child) {
margin-top: 15px;
}
}
*:first-child {
margin-top: 0;
}
*:last-child {
margin-bottom: 0;
}
// avoid double breaks
br + p {
margin-top: 0;
}
}
hr {
border: 0;
width: 100%;

View File

@ -15,18 +15,33 @@ export default class EventHandler extends Extension {
},
transformPastedHTML(html) {
html = html
.replace(/(<br\s*\/*>\s*){2,}/gim, '<br/>')
// remove all tags with "space only"
.replace(/<[a-z-]+>[\s]+<\/[a-z-]+>/gim, '')
// remove all iframes
.replace(
/<\/(p|div|th|tr)>\s*(<br\s*\/*>\s*)+\s*<(p|div|th|tr)>/gim,
'</p><p>'
)
.replace(
/<(p|div|th|tr)>\s*(<br\s*\/*>\s*)+\s*<\/(p|div|th|tr)>/gim,
/(<iframe(?!.*?src=(['"]).*?\2)[^>]*)(>)[^>]*\/*>/gim,
''
)
.replace(/<(p|div|th|tr)>\s*/gim, '<p>')
.replace(/\s*<\/(p|div|th|tr)>/gim, '</p>')
.replace(/[\n]{3,}/gim, '\n\n')
.replace(/(\r\n|\n\r|\r|\n)/g, '<br>')
// replace all p tags with line breaks (and spaces) only by single linebreaks
// limit linebreaks to max 2 (equivalent to html "br" linebreak)
.replace(/(<br ?\/?>\s*){2,}/gim, '<br>')
// remove additional linebreaks after p tags
.replace(
/<\/(p|div|th|tr)>\s*(<br ?\/?>\s*)+\s*<(p|div|th|tr)>/gim,
'</p><p>'
)
// remove additional linebreaks inside p tags
.replace(
/<[a-z-]+>(<[a-z-]+>)*\s*(<br ?\/?>\s*)+\s*(<\/[a-z-]+>)*<\/[a-z-]+>/gim,
''
)
// remove additional linebreaks when first child inside p tags
.replace(/<p>(\s*<br ?\/?>\s*)+/gim, '<p>')
// remove additional linebreaks when last child inside p tags
.replace(/(\s*<br ?\/?>\s*)+<\/p>/gim, '</p>')
// console.log('#### transformPastedHTML', html)
return html
}