mirror of https://github.com/Kylart/KawAnime.git
Fixed closing tags for common tags
This commit is contained in:
parent
54aead3dab
commit
dee87fe03f
|
@ -49,7 +49,7 @@ export default function (subtitle, styles, info) {
|
|||
// We handle newline "manually". Hence, there is a need for
|
||||
// a masterId as to know which cues are initially the same.
|
||||
result.masterId = `${result.start}-${result.end}-${result.line}-${result.position}-${result.text}`
|
||||
result.text = result.text.replace(/\\N/g, '<br>')
|
||||
// result.text = result.text.replace(/\\N/g, '<br>')
|
||||
|
||||
// Style might ask for a rotation, this needs to be set as a key
|
||||
// for the cue. It seems the rotation axis is inversed too.
|
||||
|
|
|
@ -20,7 +20,7 @@ const re = {
|
|||
to: '<i>'
|
||||
},
|
||||
end: {
|
||||
from: /\\i0?/g,
|
||||
from: /\\i0/g,
|
||||
to: '</i>'
|
||||
}
|
||||
},
|
||||
|
@ -91,22 +91,6 @@ const handleNewline = (string) => {
|
|||
return string.replace(re.newline, '<br>')
|
||||
}
|
||||
|
||||
const handleCommon = (type, string) => {
|
||||
// Handles bold, italic and underline
|
||||
const re_ = re[type]
|
||||
let tag = null
|
||||
|
||||
if (re_.start.from.test(string)) {
|
||||
return re_.start.to
|
||||
}
|
||||
|
||||
if (re_.end.from.test(string)) {
|
||||
return re_.end.to
|
||||
}
|
||||
|
||||
return tag
|
||||
}
|
||||
|
||||
const handleFontSize = (string, info) => {
|
||||
const fontType = re.font.size.test(string) && string.match(re.font.size)[0]
|
||||
|
||||
|
@ -344,6 +328,7 @@ const getEnclosedTags = (string) => {
|
|||
|
||||
const handleEnclosedTags = (enclosedTags, cue, style, info) => {
|
||||
const cueStyle = {}
|
||||
let addedLength = 0
|
||||
|
||||
return enclosedTags.map(({ tags, index }, k) => {
|
||||
// Removing unsupported tags
|
||||
|
@ -352,17 +337,19 @@ const handleEnclosedTags = (enclosedTags, cue, style, info) => {
|
|||
// Handling common tags
|
||||
const types = ['bold', 'italic', 'underline', 'strike']
|
||||
types.forEach((type) => {
|
||||
const tag = handleCommon(type, string)
|
||||
const _re = re[type]
|
||||
const isStart = string.match(_re.start.from)
|
||||
const isEnd = string.match(_re.end.from)
|
||||
|
||||
if (!tag) return
|
||||
if (!isStart && !isEnd) return
|
||||
|
||||
const l = tag.length
|
||||
let tag = isStart
|
||||
? _re.start.to
|
||||
: _re.end.to
|
||||
|
||||
index += addedLength
|
||||
cue.text = cue.text.slice(0, index) + tag + cue.text.slice(index)
|
||||
|
||||
if (k !== enclosedTags.length - 1) {
|
||||
enclosedTags[k + 1].index += l
|
||||
}
|
||||
addedLength += tag.length - string.length
|
||||
})
|
||||
|
||||
// Font
|
||||
|
@ -415,7 +402,5 @@ export default function (cue, style, info) {
|
|||
}
|
||||
})
|
||||
|
||||
console.log(cue.text)
|
||||
|
||||
return cue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue