{"id":11643,"date":"2020-07-19T19:03:18","date_gmt":"2020-07-19T23:03:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=11643"},"modified":"2020-07-19T19:04:33","modified_gmt":"2020-07-19T23:04:33","slug":"prettify-matlab-html","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2020\/07\/19\/prettify-matlab-html\/","title":{"rendered":"Prettify MATLAB HTML"},"content":{"rendered":"\r\n<div class=\"content\"><p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871\">Jiro<\/a>'s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/78059\">Prettify MATLAB html<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2638033\">Harry Dymond<\/a>.<\/p><p>By now, many of you are probably aware of <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/publishing-matlab-code.html#mw_59123666-e261-47ee-b79c-5539dc6a1f33\">Live Scripts<\/a> for creating shareable (and interactive) document. Before Live Scripts, you could <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/publishing-matlab-code.html#mw_5a3e8ba7-757e-4324-8319-8c2dd3d066e5\">publish<\/a> your MATLAB code to share with others. You use special mark-ups in the code comments to format your text. In general, we recommend Live Scripts, as it has the same capabilities and many more compared to publishing, such as adding <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-live-editor-tasks-to-a-live-script.html\">Live Editor Tasks<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-interactive-controls-to-a-live-script.html\">Interactive Controls<\/a>.<\/p><p>Those of you who are using .m MATLAB code files, I highly recommend you take a look at this entry by Harry. It includes a number of useful markups that you can include in your published HTML file. Harry includes a <b>very<\/b> comprehensive <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/mlc-downloads\/downloads\/ae68de69-2f6b-413d-9d93-a17c382acb4c\/93753787-b9f2-4161-bfb2-0961e3abd7a3\/previews\/prettify%20documentation\/html\/prettify_MATLAB_html_helpdoc.html\">help file<\/a>, so I encourage you to read through it to learn about all the features. That help file itself was also created with this entry.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_prettify_html\/prettify_html_example.png\" alt=\"\"> <\/p><p>Here are a few of the key features I really like:<\/p><div><ul><li>Ability to add toolbar buttons (shortcut) to make it easy to add markup tags<\/li><li>Collapsible sections<\/li><li>Internal links to jump to different sections within the document. This is possible with Live Scripts, but not with the standard <tt>publish<\/tt> function<\/li><li>Simple markup for changing font size, color, and defining custom CSS classes<\/li><\/ul><\/div><p><b>Comments<\/b><\/p><p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=11643#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/78059#comment\">comment<\/a> for Harry.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_09b4970a587d421d9b3e0f7a14facf98() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='09b4970a587d421d9b3e0f7a14facf98 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 09b4970a587d421d9b3e0f7a14facf98';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2020 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_09b4970a587d421d9b3e0f7a14facf98()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2020a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2020a<br><\/p><\/div><!--\r\n09b4970a587d421d9b3e0f7a14facf98 ##### SOURCE BEGIN #####\r\n%%\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871 Jiro>'s\r\n% Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/78059 Prettify\r\n% MATLAB html> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/2638033 Harry\r\n% Dymond>.\r\n%\r\n% By now, many of you are probably aware of\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/publishing-matlab-code.html#mw_59123666-e261-47ee-b79c-5539dc6a1f33\r\n% Live Scripts> for creating shareable (and interactive) document. Before\r\n% Live Scripts, you could\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/publishing-matlab-code.html#mw_5a3e8ba7-757e-4324-8319-8c2dd3d066e5\r\n% publish> your MATLAB code to share with others. You use special mark-ups\r\n% in the code comments to format your text. In general, we recommend Live\r\n% Scripts, as it has the same capabilities and many more compared to\r\n% publishing, such as adding\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-live-editor-tasks-to-a-live-script.html\r\n% Live Editor Tasks> and\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-interactive-controls-to-a-live-script.html\r\n% Interactive Controls>.\r\n%\r\n% Those of you who are using .m MATLAB code files, I highly recommend you\r\n% take a look at this entry by Harry. It includes a number of useful\r\n% markups that you can include in your published HTML file. Harry includes\r\n% a *very* comprehensive\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/mlc-downloads\/downloads\/ae68de69-2f6b-413d-9d93-a17c382acb4c\/93753787-b9f2-4161-bfb2-0961e3abd7a3\/previews\/prettify%20documentation\/html\/prettify_MATLAB_html_helpdoc.html\r\n% help file>, so I encourage you to read through it to learn about all the\r\n% features. That help file itself was also created with this entry.\r\n% \r\n% <<prettify_html_example.png>>\r\n%\r\n% Here are a few of the key features I really like:\r\n%\r\n% * Ability to add toolbar buttons (shortcut) to make it easy to add\r\n% markup tags\r\n% * Collapsible sections\r\n% * Internal links to jump to different sections within the document. This\r\n% is possible with Live Scripts, but not with the standard |publish|\r\n% function\r\n% * Simple markup for changing font size, color, and defining custom CSS\r\n% classes\r\n%\r\n% *Comments*\r\n%\r\n% Give it a try and let us know what you think\r\n% <http:\/\/blogs.mathworks.com\/pick\/?p=11643#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/78059#comment\r\n% comment> for Harry.\r\n\r\n##### SOURCE END ##### 09b4970a587d421d9b3e0f7a14facf98\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_prettify_html\/prettify_html_example.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\nJiro's Pick this week is Prettify MATLAB html by Harry Dymond.By now, many of you are probably aware of Live Scripts for creating shareable (and interactive) document. Before Live Scripts, you... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2020\/07\/19\/prettify-matlab-html\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11643"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=11643"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11643\/revisions"}],"predecessor-version":[{"id":11647,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11643\/revisions\/11647"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=11643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=11643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=11643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}