@@ -40,10 +40,14 @@ var preProcessing = {
4040 } ,
4141
4242 /**
43- * Transforms <v> tags by adding a title attribute with the concatenated text and retaining other attributes.
43+ * Transforms <v> tags by extracting any non-attribute text as a `title` attribute,
44+ * retains existing attributes (except class), and preserves the class attribute if present.
45+ * Example: <v John class="foo" data-x="y"> becomes <v title="John" data-x="y" class="foo">
46+ *
47+ * @function
4448 * @memberof preProcessing
45- * @param {string } content - The content with processed <lang > tags.
46- * @returns {string } - The content with <v> tags transformed.
49+ * @param {string } content - The string content containing <v > tags to process .
50+ * @returns {string } The content with <v> tags transformed to include a title attribute and preserved attributes .
4751 */
4852 transformVTags : function ( content ) {
4953 return content . replace ( / < v \s + ( [ ^ > ] * ?) > / g, function ( _ , tagAttributes ) {
@@ -109,17 +113,26 @@ var postProcessing = {
109113 } ,
110114
111115 /**
112- * Post-processes <v> tags by converting class attributes to dot-separated class names.
116+ * * Post-processes <v> tags by converting class attributes, no matter where found in the attribute order, to dot-separated class names.
117+ * For example, <v class="foo bar" title="John"> becomes <v.foo.bar title="John">.
118+ * Removes the class attribute and appends other attributes after the class names.
119+ *
120+ * @function
113121 * @memberof postProcessing
114122 * @param {string } vttContent - The VTT content to be processed.
115123 * @returns {string } - The VTT content with processed <v> tags.
116124 */
117125 postprocessVTag : function ( vttContent ) {
118126 return vttContent . replace (
119- / < v c l a s s = " ( [ \w \s ] + ) " ( [ ^ > ] * ) > / g,
120- function ( _ , classNames , otherAttrs ) {
121- var classes = classNames . split ( " " ) . join ( "." ) ;
122- return "<v." + classes + otherAttrs + ">" ;
127+ / < v ( [ ^ > ] * ) c l a s s = " ( [ \w \s ] + ) " ( [ ^ > ] * ) > / g,
128+ function ( _ , beforeClass , classNames , afterClass ) {
129+ var classes = classNames . trim ( ) . split ( / \s + / ) . join ( "." ) ;
130+ // Rebuild the tag: <v.{classes}{other attributes}>
131+ // Remove class="..." from attributes
132+ var attrs = ( beforeClass + afterClass )
133+ . replace ( / \s * c l a s s = " [ \w \s ] + " / , "" )
134+ . trim ( ) ;
135+ return "<v." + classes + ( attrs ? " " + attrs : "" ) + ">" ;
123136 }
124137 ) ;
125138 } ,
0 commit comments