Skip to content

Commit

Permalink
fix(block-tools): more robust formatting detection on copy paste in S…
Browse files Browse the repository at this point in the history
…afari (#5485)

* fix(block-tools): more robust formatting detection on copy paste in safari

Signed-off-by: Fred Carlsen <[email protected]>

* fixup! fix(block-tools): more robust formatting detection on copy paste in safari

Signed-off-by: Fred Carlsen <[email protected]>

---------

Signed-off-by: Fred Carlsen <[email protected]>
  • Loading branch information
sjelfull authored Jan 11, 2024
1 parent a281061 commit 0cec72b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions packages/@sanity/block-tools/src/HtmlDeserializer/rules/gdocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@ const LIST_CONTAINER_TAGS = Object.keys(HTML_LIST_CONTAINER_TAGS)
// font-style:italic seems like the most important rule for italic / emphasis in their html
function isEmphasis(el: Node): boolean {
const style = isElement(el) && el.getAttribute('style')
return /font-style:italic/.test(style || '')
return /font-style\s*:\s*italic/.test(style || '')
}

// font-weight:700 seems like the most important rule for bold in their html
function isStrong(el: Node): boolean {
const style = isElement(el) && el.getAttribute('style')
return /font-weight:700/.test(style || '')
return /font-weight\s*:\s*700/.test(style || '')
}

// text-decoration seems like the most important rule for underline in their html
function isUnderline(el: Node): boolean {
if (!isElement(el) || tagName(el.parentNode) === 'a') {
return false
}

const style = isElement(el) && el.getAttribute('style')
return /text-decoration:underline/.test(style || '')

return /text-decoration\s*:\s*underline/.test(style || '')
}

// text-decoration seems like the most important rule for strike-through in their html
function isStrikethrough(el: Node): boolean {
const style = isElement(el) && el.getAttribute('style')
return /text-decoration:line-through/.test(style || '')
return /text-decoration\s*:\s*line-through/.test(style || '')
}

// Check for attribute given by the gdocs preprocessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@
},
{
"_type": "span",
"marks": ["randomKey0", "underline"],
"marks": ["randomKey0"],
"text": "Lorem Lorem",
"_key": "randomKey881"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@
},
{
"_type": "span",
"marks": ["randomKey0", "underline"],
"marks": ["randomKey0"],
"text": "Lorem Lorem",
"_key": "randomKey881"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@
},
{
"_type": "span",
"marks": ["randomKey0", "underline"],
"marks": ["randomKey0"],
"text": "Lorem Lorem",
"_key": "randomKey991"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@
},
{
"_type": "span",
"marks": ["randomKey0", "underline"],
"marks": ["randomKey0"],
"text": "Lorem Lorem",
"_key": "randomKey611"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@
},
{
"_type": "span",
"marks": ["randomKey0", "underline"],
"marks": ["randomKey0"],
"text": "Lorem Lorem",
"_key": "randomKey611"
},
Expand Down

2 comments on commit 0cec72b

@vercel
Copy link

@vercel vercel bot commented on 0cec72b Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio.sanity.build
performance-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 0cec72b Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.