Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
react-ag-qeditor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lib
react-ag-qeditor
Commits
1c8111c2
Commit
1c8111c2
authored
May 06, 2025
by
Яков
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update table insert
parent
b5e2da0e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
69 deletions
+0
-69
QEditor.jsx
src/QEditor.jsx
+0
-69
No files found.
src/QEditor.jsx
View file @
1c8111c2
...
@@ -455,54 +455,6 @@ const QEditor = ({
...
@@ -455,54 +455,6 @@ const QEditor = ({
// }
// }
// }
// }
}
}
function
cleanWordHtml
(
html
)
{
return
html
// Удаляем MS Office специфичные теги
.
replace
(
/<
(
!|meta|link|style|o:
[^
>
]
+
)
>/gi
,
''
)
// Удаляем ненужные атрибуты
.
replace
(
/
\s(
class|style|lang
)
=
(
"|'
)[^
"'
]
*
(
"|'
)
/gi
,
''
)
// Заменяем MS теги на стандартные
.
replace
(
/<
(\/?)
v:
[^
>
]
+>/g
,
'<$1span>'
)
// Удаляем пустые параграфы
.
replace
(
/<p
[^
>
]
*>
(
|
\s)
*<
\/
p>/g
,
''
)
}
function
parseWordTable
(
html
)
{
const
doc
=
new
DOMParser
().
parseFromString
(
html
,
'text/html'
)
const
tables
=
doc
.
querySelectorAll
(
'table'
)
if
(
!
tables
.
length
)
return
null
const
table
=
tables
[
0
]
const
rows
=
[]
table
.
querySelectorAll
(
'tr'
).
forEach
(
tr
=>
{
const
cells
=
[]
tr
.
querySelectorAll
(
'td, th'
).
forEach
(
td
=>
{
cells
.
push
({
type
:
'tableCell'
,
content
:
[{
type
:
'paragraph'
,
content
:
td
.
textContent
?
[{
type
:
'text'
,
text
:
td
.
textContent
}]
:
[]
}]
})
})
rows
.
push
({
type
:
'tableRow'
,
content
:
cells
})
})
return
{
type
:
'table'
,
content
:
[
{
type
:
'tableRow'
,
content
:
rows
[
0
].
content
.
map
(()
=>
({
type
:
'tableHeader'
}))
},
...
rows
]
}
}
const
editor
=
useEditor
({
const
editor
=
useEditor
({
extensions
:
[
extensions
:
[
...
@@ -573,27 +525,6 @@ const QEditor = ({
...
@@ -573,27 +525,6 @@ const QEditor = ({
wrap
.
querySelectorAll
(
'.atma-editor-toolbar-s'
).
forEach
(
function
(
s
)
{
wrap
.
querySelectorAll
(
'.atma-editor-toolbar-s'
).
forEach
(
function
(
s
)
{
s
.
classList
.
remove
(
'show'
)
s
.
classList
.
remove
(
'show'
)
})
})
},
editorProps
:
{
handlePaste
:
(
view
,
event
)
=>
{
const
html
=
event
.
clipboardData
?.
getData
(
'text/html'
)
console
.
log
(
html
);
// Если вставляется таблица из Word
if
(
html
?.
includes
(
'urn:schemas-microsoft-com:office:word'
))
{
const
cleanedHtml
=
cleanWordHtml
(
html
)
// Функция очистки (см. ниже)
const
tr
=
view
.
state
.
tr
tr
.
replaceSelectionWith
(
view
.
state
.
schema
.
nodeFromJSON
({
type
:
'table'
,
content
:
parseWordTable
(
cleanedHtml
)
// Функция парсинга таблицы
}))
view
.
dispatch
(
tr
)
return
true
// Отменяем стандартную обработку
}
},
transformPastedHTML
(
html
)
{
return
cleanWordHtml
(
html
)
}
}
}
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment