From 8dc1e3b189f76931e43394c4732573b9885074ab Mon Sep 17 00:00:00 2001 From: Wesley Moxam Date: Tue, 13 Mar 2018 10:47:15 -0400 Subject: [PATCH 1/2] Modify to look for UML docs inside tags --- plantuml/content-script.js | 209 +++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 102 deletions(-) diff --git a/plantuml/content-script.js b/plantuml/content-script.js index 83a882c..98abaa9 100644 --- a/plantuml/content-script.js +++ b/plantuml/content-script.js @@ -1,102 +1,107 @@ -if (!document.doctype && - document.documentElement.namespaceURI == 'http://www.w3.org/1999/xhtml' && - document.body.textContent.substr(0, '@start'.length) == '@start') { - chrome.extension.sendRequest({ - command: 'showPageAction' - }); - var data = document.body.textContent; - var reload = true; - var shown = false; - var type = 'none'; - - function escapeHtml(text) { - return text - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); - } - - var showXhr; - var show = function(force) { - shown = shown || force; - if (showXhr) - showXhr.abort(); - - chrome.extension.sendRequest({ command: 'compress', data: data }, function(response) { - var url = [ - response.settings.server, - response.settings.type, - response.data - ].join('/'); - - switch (response.settings.type) { - case 'img': - document.body.innerHTML = [''].join(''); - break; - - case 'svg': - document.body.innerHTML = [''].join(''); - break; - - case 'txt': - document.body.innerHTML = ''; - showXhr = new XMLHttpRequest(); - showXhr.onreadystatechange = function() { - if (showXhr.readyState == 4 && showXhr.status != 404) { - document.body.innerHTML = ['
' + escapeHtml(showXhr.responseText) + '
'].join(''); - } - } - showXhr.open('GET', url); - showXhr.send(null); - break; - - default: - case 'none': - document.body.innerHTML = ['
' + escapeHtml(data) + '
']; - break; - } - }); - } - - if (location.protocol == 'file:') { - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState == 4 && xhr.status != 404 && (!shown || data != xhr.responseText)) { - data = xhr.responseText; - show(true); - } - }; - var update = function() { - if (!shown || reload) { - xhr.abort(); - xhr.open('GET', location.href + '?t=' + +new Date, true); - xhr.send(null); - } - }; - setInterval(update, 1000); - update(); - } else - show(true); - - chrome.extension.onMessage.addListener( - function(request, sender, sendResponse) { - /*console.log(request); - var oldSendResponse = sendResponse; - sendResponse = function() { - console.log.apply(console, arguments); - oldSendResponse.apply(this, arguments); - }*/ - - var command = request && request.command; - switch (command) { - case 'savedSettings': - reload = request.settings.reload; - show(); - break; - } - sendResponse(); - } - ); -} + +if(document.body.textContent.substr(0, '@startuml'.length) == '@startuml') { + translateUml(document.body); +} + +var c = document.querySelectorAll('code'); +var i; +for (i = 0; i < c.length; i++) { + if(c[i].textContent.substr(0, '@startuml'.length) == '@startuml') { + translateUml(c[i]) + } +} + +function translateUml(element) { + chrome.extension.sendRequest({ + command: 'showPageAction' + }); + + var data = element.textContent; + var reload = true; + var shown = false; + var type = 'none'; + + function escapeHtml(text) { + return text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + } + + var showXhr; + var show = function(force) { + shown = shown || force; + if (showXhr) + showXhr.abort(); + + chrome.extension.sendRequest({ command: 'compress', data: data }, function(response) { + var url = [ + response.settings.server, + response.settings.type, + response.data + ].join('/'); + + switch (response.settings.type) { + case 'img': + element.innerHTML = [''].join(''); + break; + + case 'svg': + element.innerHTML = [''].join(''); + break; + + case 'txt': + element.innerHTML = ''; + showXhr = new XMLHttpRequest(); + showXhr.onreadystatechange = function() { + if (showXhr.readyState == 4 && showXhr.status != 404) { + element.innerHTML = ['
' + escapeHtml(showXhr.responseText) + '
'].join(''); + } + } + showXhr.open('GET', url); + showXhr.send(null); + break; + + default: + case 'none': + element.innerHTML = ['
' + escapeHtml(data) + '
']; + break; + } + }); + } + + if (location.protocol == 'file:') { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4 && xhr.status != 404 && (!shown || data != xhr.responseText)) { + data = xhr.responseText; + show(true); + } + }; + var update = function() { + if (!shown || reload) { + xhr.abort(); + xhr.open('GET', location.href + '?t=' + +new Date, true); + xhr.send(null); + } + }; + setInterval(update, 1000); + update(); + } else + show(true); + + chrome.extension.onMessage.addListener( + function(request, sender, sendResponse) { + var command = request && request.command; + switch (command) { + case 'savedSettings': + reload = request.settings.reload; + show(); + break; + } + sendResponse(); + } + ); +} From edc81b052b4edca411cec86bc5c5543709a337ff Mon Sep 17 00:00:00 2001 From: Wesley Moxam Date: Wed, 28 Mar 2018 10:33:12 -0400 Subject: [PATCH 2/2] Adds local dev instructions --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f9f97b..2b6eae5 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,16 @@ Renders UML diagram as defined in a text file. For full syntax, see: http://plantuml.sourceforge.net/index.html +To install this development version: + +1. Clone this repo locally +2. Visit chrome://extensions/ +3. Ensure that 'Developer mode' is switched on +4. Click "Load Unpacked" +5. Select the PlantUML source directory + +To install the official version: + 1. Install the extension from Chrome Web Store. 2. Check "Allow access to file URLs" in chrome://extensions/. 3. Open local or remote text file with UML diagram definition in browser (the text starts with @startuml). @@ -19,4 +29,4 @@ This extension does not require any permissions. ## Credits -Credits go to Arnaud Roques, the author of the PlantUML. If you like this plugin, support the original author via the PayPal button on the PlantUML site (http://plantuml.sourceforge.net/index.html). \ No newline at end of file +Credits go to Arnaud Roques, the author of the PlantUML. If you like this plugin, support the original author via the PayPal button on the PlantUML site (http://plantuml.sourceforge.net/index.html).