Skip to content

Commit

Permalink
Merge pull request #23 from mccauli/coreymccourt/ch63811/refactor-and…
Browse files Browse the repository at this point in the history
…-migrate-validation-and-auto

Coreymccourt/ch63811/refactor and migrate validation and auto
  • Loading branch information
McCourtRC committed Nov 8, 2019
2 parents a60ec71 + 232aa88 commit b8d2211
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lib/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@ function timecodeToMicroseconds(timecode, fps) {
}

function extractStyling(text) {
let unformattedText = text.replace(/(?<!^)<br>/, '\n'); // <br> anywhere except front of line
unformattedText = unformattedText.replace(/{[^}]*}/g, ' ').replace(/\s\s+/, ' '); // {...}
unformattedText = unformattedText.replace(/<[^>]*>/g, ''); // <....>
let unformattedText = '';
if (text.search(/<br>/) && !text.startsWith('<br>')) {
unformattedText = text.replace(/<br>/, '\n');
}
const formattingTags = unformattedText.match(/<[^>]*>|{[^}]*}/g);
if (formattingTags && formattingTags.length) {
formattingTags.forEach(tag => {
if (tag.search(/{[^}]*}/) > -1) {
unformattedText = unformattedText.replace(tag, ' ').replace(/\s\s+/, ' ');
} else {
unformattedText = unformattedText.replace(tag, '');
}
});
}

return unformattedText.trim();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "subtitle-converter",
"version": "2.0.1",
"version": "2.0.2",
"description": "Convert subtitles from one format to another",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit b8d2211

Please sign in to comment.