From 7e5d37f3fda1b1441a31b7af02999bc4a41e7767 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 31 Mar 2017 18:25:03 +0100 Subject: [PATCH] Add context injector for pdf --- md_pdf/assets/context.js | 20 ++++++++++++++++++++ md_pdf/assets/footer.html | 3 ++- md_pdf/assets/header.html | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 md_pdf/assets/context.js diff --git a/md_pdf/assets/context.js b/md_pdf/assets/context.js new file mode 100644 index 0000000..bb59599 --- /dev/null +++ b/md_pdf/assets/context.js @@ -0,0 +1,20 @@ +function subst() { + var vars = {}; + var query_strings_from_url = document.location.search.substring(1).split('&'); + for (var query_string in query_strings_from_url) { + if (query_strings_from_url.hasOwnProperty(query_string)) { + var temp_var = query_strings_from_url[query_string].split('=', 2); + vars[temp_var[0]] = decodeURI(temp_var[1]); + } + } + + var css_selector_classes = Object.keys(vars); + for (var css_class in css_selector_classes) { + if (css_selector_classes.hasOwnProperty(css_class)) { + var element = document.getElementsByClassName(css_selector_classes[css_class]); + for (var j = 0; j < element.length; ++j) { + element[j].textContent = vars[css_selector_classes[css_class]]; + } + } + } +} diff --git a/md_pdf/assets/footer.html b/md_pdf/assets/footer.html index bda5794..5b5aad1 100644 --- a/md_pdf/assets/footer.html +++ b/md_pdf/assets/footer.html @@ -2,7 +2,8 @@ + - + diff --git a/md_pdf/assets/header.html b/md_pdf/assets/header.html index f2a2694..e8b7db6 100644 --- a/md_pdf/assets/header.html +++ b/md_pdf/assets/header.html @@ -2,7 +2,8 @@ + - +