Skip to content

Commit d0ccd05

Browse files
committed
v,c tag work
1 parent d483e2f commit d0ccd05

4 files changed

Lines changed: 199 additions & 94 deletions

File tree

‎build/ableplayer.dist.js‎

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7504,13 +7504,60 @@ var AblePlayerInstances = [];
75047504
};
75057505

75067506
AblePlayer.prototype.sanitizeVttData = function (vttData) {
7507-
// Function to preprocess <c> tags
7508-
function preprocessCTag(vttData) {
7509-
return vttData.replace(/<c\.([\w.]+)>/g, function (match, classNames) {
7510-
var classes = classNames.split(".").join(" ");
7511-
return '<c class="' + classes + '">';
7512-
});
7507+
// Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
7508+
// Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
7509+
function processAndPreprocessTags(html) {
7510+
// First, preprocess <v.word.word> and <c.word.word> tags
7511+
var preprocessedHtml = html.replace(
7512+
/<(v|c)\.([\w\.]+)([^>]*)>/g,
7513+
function (match, tag, words, otherAttrs) {
7514+
var classAttr = words.split(".").join(" ");
7515+
return "<" + tag + ' class="' + classAttr + '"' + otherAttrs + ">";
7516+
}
7517+
);
7518+
7519+
// Then, process <v> tags to add title attribute and handle class attribute correctly
7520+
var processedHtml = preprocessedHtml.replace(
7521+
/<v\s+([^>]*?)>/g,
7522+
function (match, p1) {
7523+
// Extract class attribute if present
7524+
var classMatch = p1.match(/class="([^"]*)"/);
7525+
var classAttr = classMatch ? classMatch[0] : "";
7526+
7527+
// Remove class attribute from p1 to process the title
7528+
var p1WithoutClass = p1.replace(/class="[^"]*"/, "").trim();
7529+
7530+
// Split the remaining content by spaces
7531+
var parts = p1WithoutClass.split(/\s+/);
7532+
var attributes = [];
7533+
var titleParts = [];
7534+
7535+
// Separate attributes and title parts
7536+
parts.forEach(function (part) {
7537+
if (part.indexOf("=") !== -1) {
7538+
attributes.push(part);
7539+
} else {
7540+
titleParts.push(part);
7541+
}
7542+
});
7543+
7544+
// Construct the new <v> tag
7545+
var title = titleParts.join(" ");
7546+
var newTag =
7547+
'<v title="' +
7548+
title +
7549+
'" ' +
7550+
attributes.join(" ") +
7551+
" " +
7552+
classAttr +
7553+
">";
7554+
return newTag;
7555+
}
7556+
);
7557+
7558+
return processedHtml;
75137559
}
7560+
75147561
// Function to postprocess <c> tags
75157562
function postprocessCTag(vttData) {
75167563
return vttData.replace(
@@ -7521,33 +7568,20 @@ var AblePlayerInstances = [];
75217568
}
75227569
);
75237570
}
7524-
// Function to process <v> tags
7525-
function processVTag(vttData) {
7526-
return vttData.replace(/<v\s+([^>]*?)>/g, function (match, p1) {
7527-
// Split the content by spaces
7528-
var parts = p1.split(/\s+/);
7529-
var attributes = [];
7530-
var titleParts = [];
7531-
7532-
// Separate attributes and title parts
7533-
parts.forEach(function (part) {
7534-
if (part.indexOf("=") !== -1) {
7535-
attributes.push(part);
7536-
} else {
7537-
titleParts.push(part);
7538-
}
7539-
});
75407571

7541-
// Construct the new <v> tag
7542-
var title = titleParts.join(" ");
7543-
var newTag = '<v title="' + title + '" ' + attributes.join(" ") + ">";
7544-
return newTag;
7545-
});
7572+
// Function to postprocess <v> tags
7573+
function postprocessVTag(vttData) {
7574+
return vttData.replace(
7575+
/<v class="([\w\s]+)"([^>]*)>/g,
7576+
function (match, classNames, otherAttrs) {
7577+
var classes = classNames.split(" ").join(".");
7578+
return "<v." + classes + otherAttrs + ">";
7579+
}
7580+
);
75467581
}
7547-
// Preprocess <c> tags before sanitizing
7548-
vttData = preprocessCTag(vttData);
7549-
// Process <v> tags before sanitizing
7550-
vttData = processVTag(vttData);
7582+
7583+
// Process <v> and <c> attribute processing
7584+
vttData = processAndPreprocessTags(vttData);
75517585

75527586
// Configure DOMPurify
75537587
var config = {
@@ -7561,6 +7595,7 @@ var AblePlayerInstances = [];
75617595

75627596
// Postprocessing after sanitizing
75637597
sanitizedVttData = postprocessCTag(sanitizedVttData);
7598+
sanitizedVttData = postprocessVTag(sanitizedVttData);
75647599

75657600
sanitizedVttData = sanitizedVttData.replace(/--&gt;/g, "-->");
75667601

‎build/ableplayer.js‎

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7504,13 +7504,60 @@ var AblePlayerInstances = [];
75047504
};
75057505

75067506
AblePlayer.prototype.sanitizeVttData = function (vttData) {
7507-
// Function to preprocess <c> tags
7508-
function preprocessCTag(vttData) {
7509-
return vttData.replace(/<c\.([\w.]+)>/g, function (match, classNames) {
7510-
var classes = classNames.split(".").join(" ");
7511-
return '<c class="' + classes + '">';
7512-
});
7507+
// Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
7508+
// Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
7509+
function processAndPreprocessTags(html) {
7510+
// First, preprocess <v.word.word> and <c.word.word> tags
7511+
var preprocessedHtml = html.replace(
7512+
/<(v|c)\.([\w\.]+)([^>]*)>/g,
7513+
function (match, tag, words, otherAttrs) {
7514+
var classAttr = words.split(".").join(" ");
7515+
return "<" + tag + ' class="' + classAttr + '"' + otherAttrs + ">";
7516+
}
7517+
);
7518+
7519+
// Then, process <v> tags to add title attribute and handle class attribute correctly
7520+
var processedHtml = preprocessedHtml.replace(
7521+
/<v\s+([^>]*?)>/g,
7522+
function (match, p1) {
7523+
// Extract class attribute if present
7524+
var classMatch = p1.match(/class="([^"]*)"/);
7525+
var classAttr = classMatch ? classMatch[0] : "";
7526+
7527+
// Remove class attribute from p1 to process the title
7528+
var p1WithoutClass = p1.replace(/class="[^"]*"/, "").trim();
7529+
7530+
// Split the remaining content by spaces
7531+
var parts = p1WithoutClass.split(/\s+/);
7532+
var attributes = [];
7533+
var titleParts = [];
7534+
7535+
// Separate attributes and title parts
7536+
parts.forEach(function (part) {
7537+
if (part.indexOf("=") !== -1) {
7538+
attributes.push(part);
7539+
} else {
7540+
titleParts.push(part);
7541+
}
7542+
});
7543+
7544+
// Construct the new <v> tag
7545+
var title = titleParts.join(" ");
7546+
var newTag =
7547+
'<v title="' +
7548+
title +
7549+
'" ' +
7550+
attributes.join(" ") +
7551+
" " +
7552+
classAttr +
7553+
">";
7554+
return newTag;
7555+
}
7556+
);
7557+
7558+
return processedHtml;
75137559
}
7560+
75147561
// Function to postprocess <c> tags
75157562
function postprocessCTag(vttData) {
75167563
return vttData.replace(
@@ -7521,33 +7568,20 @@ var AblePlayerInstances = [];
75217568
}
75227569
);
75237570
}
7524-
// Function to process <v> tags
7525-
function processVTag(vttData) {
7526-
return vttData.replace(/<v\s+([^>]*?)>/g, function (match, p1) {
7527-
// Split the content by spaces
7528-
var parts = p1.split(/\s+/);
7529-
var attributes = [];
7530-
var titleParts = [];
7531-
7532-
// Separate attributes and title parts
7533-
parts.forEach(function (part) {
7534-
if (part.indexOf("=") !== -1) {
7535-
attributes.push(part);
7536-
} else {
7537-
titleParts.push(part);
7538-
}
7539-
});
75407571

7541-
// Construct the new <v> tag
7542-
var title = titleParts.join(" ");
7543-
var newTag = '<v title="' + title + '" ' + attributes.join(" ") + ">";
7544-
return newTag;
7545-
});
7572+
// Function to postprocess <v> tags
7573+
function postprocessVTag(vttData) {
7574+
return vttData.replace(
7575+
/<v class="([\w\s]+)"([^>]*)>/g,
7576+
function (match, classNames, otherAttrs) {
7577+
var classes = classNames.split(" ").join(".");
7578+
return "<v." + classes + otherAttrs + ">";
7579+
}
7580+
);
75467581
}
7547-
// Preprocess <c> tags before sanitizing
7548-
vttData = preprocessCTag(vttData);
7549-
// Process <v> tags before sanitizing
7550-
vttData = processVTag(vttData);
7582+
7583+
// Process <v> and <c> attribute processing
7584+
vttData = processAndPreprocessTags(vttData);
75517585

75527586
// Configure DOMPurify
75537587
var config = {
@@ -7561,6 +7595,7 @@ var AblePlayerInstances = [];
75617595

75627596
// Postprocessing after sanitizing
75637597
sanitizedVttData = postprocessCTag(sanitizedVttData);
7598+
sanitizedVttData = postprocessVTag(sanitizedVttData);
75647599

75657600
sanitizedVttData = sanitizedVttData.replace(/--&gt;/g, "-->");
75667601

‎build/ableplayer.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/track.js‎

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,60 @@
424424
};
425425

426426
AblePlayer.prototype.sanitizeVttData = function (vttData) {
427-
// Function to preprocess <c> tags
428-
function preprocessCTag(vttData) {
429-
return vttData.replace(/<c\.([\w.]+)>/g, function (match, classNames) {
430-
var classes = classNames.split(".").join(" ");
431-
return '<c class="' + classes + '">';
432-
});
427+
// Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
428+
// Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
429+
function processAndPreprocessTags(html) {
430+
// First, preprocess <v.word.word> and <c.word.word> tags
431+
var preprocessedHtml = html.replace(
432+
/<(v|c)\.([\w\.]+)([^>]*)>/g,
433+
function (match, tag, words, otherAttrs) {
434+
var classAttr = words.split(".").join(" ");
435+
return "<" + tag + ' class="' + classAttr + '"' + otherAttrs + ">";
436+
}
437+
);
438+
439+
// Then, process <v> tags to add title attribute and handle class attribute correctly
440+
var processedHtml = preprocessedHtml.replace(
441+
/<v\s+([^>]*?)>/g,
442+
function (match, p1) {
443+
// Extract class attribute if present
444+
var classMatch = p1.match(/class="([^"]*)"/);
445+
var classAttr = classMatch ? classMatch[0] : "";
446+
447+
// Remove class attribute from p1 to process the title
448+
var p1WithoutClass = p1.replace(/class="[^"]*"/, "").trim();
449+
450+
// Split the remaining content by spaces
451+
var parts = p1WithoutClass.split(/\s+/);
452+
var attributes = [];
453+
var titleParts = [];
454+
455+
// Separate attributes and title parts
456+
parts.forEach(function (part) {
457+
if (part.indexOf("=") !== -1) {
458+
attributes.push(part);
459+
} else {
460+
titleParts.push(part);
461+
}
462+
});
463+
464+
// Construct the new <v> tag
465+
var title = titleParts.join(" ");
466+
var newTag =
467+
'<v title="' +
468+
title +
469+
'" ' +
470+
attributes.join(" ") +
471+
" " +
472+
classAttr +
473+
">";
474+
return newTag;
475+
}
476+
);
477+
478+
return processedHtml;
433479
}
480+
434481
// Function to postprocess <c> tags
435482
function postprocessCTag(vttData) {
436483
return vttData.replace(
@@ -441,33 +488,20 @@
441488
}
442489
);
443490
}
444-
// Function to process <v> tags
445-
function processVTag(vttData) {
446-
return vttData.replace(/<v\s+([^>]*?)>/g, function (match, p1) {
447-
// Split the content by spaces
448-
var parts = p1.split(/\s+/);
449-
var attributes = [];
450-
var titleParts = [];
451-
452-
// Separate attributes and title parts
453-
parts.forEach(function (part) {
454-
if (part.indexOf("=") !== -1) {
455-
attributes.push(part);
456-
} else {
457-
titleParts.push(part);
458-
}
459-
});
460491

461-
// Construct the new <v> tag
462-
var title = titleParts.join(" ");
463-
var newTag = '<v title="' + title + '" ' + attributes.join(" ") + ">";
464-
return newTag;
465-
});
492+
// Function to postprocess <v> tags
493+
function postprocessVTag(vttData) {
494+
return vttData.replace(
495+
/<v class="([\w\s]+)"([^>]*)>/g,
496+
function (match, classNames, otherAttrs) {
497+
var classes = classNames.split(" ").join(".");
498+
return "<v." + classes + otherAttrs + ">";
499+
}
500+
);
466501
}
467-
// Preprocess <c> tags before sanitizing
468-
vttData = preprocessCTag(vttData);
469-
// Process <v> tags before sanitizing
470-
vttData = processVTag(vttData);
502+
503+
// Process <v> and <c> attribute processing
504+
vttData = processAndPreprocessTags(vttData);
471505

472506
// Configure DOMPurify
473507
var config = {
@@ -481,6 +515,7 @@
481515

482516
// Postprocessing after sanitizing
483517
sanitizedVttData = postprocessCTag(sanitizedVttData);
518+
sanitizedVttData = postprocessVTag(sanitizedVttData);
484519

485520
sanitizedVttData = sanitizedVttData.replace(/--&gt;/g, "-->");
486521

0 commit comments

Comments
 (0)