mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Update replacements.js-substitute
about function substitute when (content.opf > manifest > item > href) is an encode-uri: '%E4%B8%AD%E6%96%87' but the content's source is not: '中文' need decode to substitute blob successfully
This commit is contained in:
parent
f09089cf77
commit
51e3f768f5
1 changed files with 7 additions and 0 deletions
|
@ -128,6 +128,13 @@ export function replaceLinks(contents, fn) {
|
||||||
export function substitute(content, urls, replacements) {
|
export function substitute(content, urls, replacements) {
|
||||||
urls.forEach(function(url, i){
|
urls.forEach(function(url, i){
|
||||||
if (url && replacements[i]) {
|
if (url && replacements[i]) {
|
||||||
|
// when (content.opf > manifest > item > href) is a encodeURI, but the content's source is not
|
||||||
|
try {
|
||||||
|
let decodeUri = window.decodeURIComponent(url);
|
||||||
|
content = content.replace(new RegExp(decodeUri, "g"), replacements[i]);
|
||||||
|
} catch (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
// Account for special characters in the file name.
|
// Account for special characters in the file name.
|
||||||
// See https://stackoverflow.com/a/6318729.
|
// See https://stackoverflow.com/a/6318729.
|
||||||
url = url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
url = url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue