Skip to content

Commit

Permalink
image uri encoding fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren committed Dec 31, 2024
1 parent b6c79ae commit 972a00d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions script/md-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function displayText(text, element) {
text = fixHeadings(text);
var frontMatter = fetchFrontMatter(text);
text = wrapFrontMatter(text);
text = UriEncodeImages(text);
output = marked.parse(text);
// figure raw markdown address
var markdownFile = document.location.href.split('#').join("") + ".md"
Expand Down Expand Up @@ -82,6 +83,10 @@ function displayText(text, element) {
});
}

function UriEncodeImages(text) {
return text.replace(/\!\[(.*)\]\((.+)\)/g, function(match, p1, p2) { return "!["+p1+"]("+encodeURI(p2)+")"});
}

// ID and format front matter in format ---\nSTUFF\n---\n at start of document;
// https://jekyllrb.com/docs/front-matter/
function wrapFrontMatter(text) {
Expand Down

0 comments on commit 972a00d

Please sign in to comment.