Skip to content

Commit

Permalink
Merge pull request #2011 from VisActor/fix/reg-s
Browse files Browse the repository at this point in the history
fix: fix regexp format for webpack 3 #2005
  • Loading branch information
Rui-Sun committed Jul 2, 2024
2 parents beeb4a8 + fc5eccb commit 0fd62e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions common/changes/@visactor/vtable/fix-reg-s_2024-07-01-03-22.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "fix: fix regexp format for webpack 3 #2005",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
8 changes: 6 additions & 2 deletions packages/vtable/src/event/listener/container-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ export function bindContainerDomListener(eventManager: EventManager) {
table.resize();
}
});

// const regex = /<tr[^>]*>(.*?)<\/tr>/gs; // 匹配<tr>标签及其内容
const regex = /<tr[^>]*>([\s\S]*?)<\/tr>/g; // for webpack3
// const cellRegex = /<td[^>]*>(.*?)<\/td>/gs; // 匹配<td>标签及其内容
const cellRegex = /<td[^>]*>([\s\S]*?)<\/td>/g; // for webpack3

function pasteHtmlToTable(item: ClipboardItem) {
const ranges = table.stateManager.select.ranges;
const selectRangeLength = ranges.length;
Expand All @@ -341,12 +347,10 @@ export function bindContainerDomListener(eventManager: EventManager) {
blob.text().then((pastedData: any) => {
// 解析html数据
if (pastedData && /(<table)|(<TABLE)/g.test(pastedData)) {
const regex = /<tr[^>]*>(.*?)<\/tr>/gs; // 匹配<tr>标签及其内容
// const matches = pastedData.matchAll(regex);
const matches = Array.from(pastedData.matchAll(regex));
for (const match of matches) {
const rowContent = match[1]; // 获取<tr>标签中的内容
const cellRegex = /<td[^>]*>(.*?)<\/td>/gs; // 匹配<td>标签及其内容
const cellMatches: RegExpMatchArray[] = Array.from(rowContent.matchAll(cellRegex)); // 获取<td>标签中的内容
const rowValues = cellMatches.map(cellMatch => {
return (
Expand Down

0 comments on commit 0fd62e8

Please sign in to comment.