From 7a0f8beafc64d37e34611c5d7746d1d1b396e74b Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Wed, 14 Jun 2023 17:33:29 +1200 Subject: [PATCH] feat: Add clean svg ids view (#160) Fixes #159 --- www/clean-svg-ids.html | 155 +++++++++++++++++++++++++++++++++++ www/scripts/clean-svg-ids.js | 91 ++++++++++++++++++++ www/sitemap.xml | 4 + 3 files changed, 250 insertions(+) create mode 100644 www/clean-svg-ids.html create mode 100644 www/scripts/clean-svg-ids.js diff --git a/www/clean-svg-ids.html b/www/clean-svg-ids.html new file mode 100644 index 0000000..bd89a98 --- /dev/null +++ b/www/clean-svg-ids.html @@ -0,0 +1,155 @@ + + + + + IETF Author Tools - Clean SVG ids + + + + + + +
+ +
+
+
+
+

IETF Author Tools - Clean SVG ids

+
+
+ +
+
+
+

+ This services users kramdown-rfc's clean-svg-id tool to fix duplicate values in SVG id attributes. The resulting XML will not have any duplicate SVG ids. +

+ + +
+
+
+
+ +
+
+ +
+
+
+

+ +

+
+
+
    +
    +
    +
    +
    +

    + +

    +
    +
    +
      +
      +
      +
      +
      +
      +
      +
      + + + + + + + + diff --git a/www/scripts/clean-svg-ids.js b/www/scripts/clean-svg-ids.js new file mode 100644 index 0000000..0d28816 --- /dev/null +++ b/www/scripts/clean-svg-ids.js @@ -0,0 +1,91 @@ +const alertError = document.getElementById('alertError'); +const buttonDownload = document.getElementById('buttonDownload'); +const buttonOpen = document.getElementById('buttonOpen'); +const formFile = document.getElementById('formFile'); +const messageError = document.getElementById('messageError'); +const accordionItemWarnings = document.getElementById('accordionItemWarnings'); +const accordionItemErrors = document.getElementById('accordionItemErrors'); +const listWarnings = document.getElementById('listWarnings'); +const listErrors = document.getElementById('listErrors'); +const buttonClean = document.getElementById('buttonClean'); + +reset(); + +// enable Bootstrap/Popper tooltips +var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); +var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { + return new bootstrap.Tooltip(tooltipTriggerEl); +}); + +formFile.addEventListener('change', reset); +buttonClean.addEventListener('click', clean); + +function reset() { + alertError.style.display = 'none'; + buttonDownload.style.display = 'none'; + buttonDownload.setAttribute('download', ''); + buttonDownload.href = '#'; + buttonOpen.style.display = 'none'; + buttonOpen.href = '#'; + messageError.innerHTML = ''; + accordionValidation.style.display = 'none'; + accordionItemWarnings.style.display = 'none'; + accordionItemErrors.style.display = 'none'; + listWarnings.innerHTML = ''; + listErrors.innerHTML = ''; + resetButtons(); +} + +function resetButtons() { + buttonClean.disabled = false; + buttonClean.innerText = buttonClean.dataset.title; +} + +function disableButtons() { + buttonClean.disabled = true; +} + +function clean(event) { + reset(); + + buttonClean.innerHTML = '' + buttonClean.innerHTML; + disableButtons(); + + const formData = new FormData(); + const file = formFile.files[0]; + + formData.append('file', file); + + //const apiCall = 'https://author-tools.ietf.org/api2/clean_svg_ids'; + const apiCall = 'http://localhost:8888/api/clean_svg_ids'; + + const request = new Request(apiCall, { + method: 'POST', + body: formData + }); + + fetch(request) + .then(function(response) { return response.json(); }) + .then(function(json) { + resetButtons(); + if (json.error) { + alertError.style.display = 'block'; + messageError.innerHTML = json.error; + } + if (json.url && json.url.length > 0) { + // file rendering is successful + download_url = json.url + '?download=1' + buttonDownload.style.display = 'block'; + buttonDownload.setAttribute('download', download_url); + buttonDownload.href = download_url; + buttonOpen.style.display = 'block'; + buttonOpen.setAttribute('href', json.url); + buttonOpen.href = json.url; + } + }) + .catch((error) => { + resetButtons(); + alertError.style.display = 'block'; + messageError.innerHTML = error; + }); +} diff --git a/www/sitemap.xml b/www/sitemap.xml index df4a59d..9377593 100644 --- a/www/sitemap.xml +++ b/www/sitemap.xml @@ -22,6 +22,10 @@ https://author-tools.ietf.org/svgcheck 1.00 + + https://author-tools.ietf.org/clean_svg_ids + 1.00 + https://author-tools.ietf.org/doc/ 0.90