diff --git a/.gitmodules b/.gitmodules index 12c1135..f794180 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ -[submodule "lib/markdown-it-checkbox"] - path = lib/markdown-it-checkbox - url = https://github.com/mcecot/markdown-it-checkbox.git [submodule "lib/highlightjs"] path = lib/highlightjs url = https://github.com/components/highlightjs.git [submodule "lib/markdown-it"] path = lib/markdown-it url = https://github.com/markdown-it/markdown-it.git +[submodule "lib/markdown-it-checkbox"] + path = lib/markdown-it-checkbox + url = https://github.com/mcecot/markdown-it-checkbox.git diff --git a/LICENSE b/LICENSE index d0c5e6a..7ff8213 100644 --- a/LICENSE +++ b/LICENSE @@ -27,6 +27,30 @@ This Sofware is based on: ------------------------------------------------------------------------------ +Original markdown-viewer: i.e. some of ext/content.js (https://github.com/Thiht/markdown-viewer) + +Copyright (c) 2012-2013 Rousseau Thibaut + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +------------------------------------------------------------------------------ + highlightjs (https://github.com/isagalaev/highlight.js) Copyright (c) 2006, Ivan Sagalaev @@ -39,8 +63,8 @@ modification, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of highlight.js nor the names of its contributors - may be used to endorse or promote products derived from this software + * Neither the name of highlight.js nor the names of its contributors + may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY @@ -109,35 +133,49 @@ THE SOFTWARE. ------------------------------------------------------------------------------ -[Original code: i.e. some of ext/content.js] +markdown-mark (https://github.com/dcurtis/markdown-mark) -Copyright (c) 2012-2013 Rousseau Thibaut +DEDICATED TO THE PUBLIC DOMAIN BY DUSTIN CURTIS -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +The Markdown Mark has been dedicated to the public domain. It is protected by the Creative Commons CC0 Universal Public Domain Dedication license. You can read the entire license below or at http://creativecommons.org/publicdomain/zero/1.0/deed.en. -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +CC0 UNIVERSAL PUBLIC DOMAIN DEDICATION LICENSE -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: +a. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; +b. moral rights retained by the original author(s) and/or performer(s); +c. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; +rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; +d. rights protecting the extraction, dissemination, use and reuse of data in a Work; +e. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and +f. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. + +4. Limitations and Disclaimers. + +a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. +b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. +c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. +d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. ------------------------------------------------------------------------------ -[sss: css files] +SSS Simple Style Sheet (https://github.com/Thiht/sss) The MIT License (MIT) -Copyright (c) 2016 +Copyright (c) 2016 Thibaut Rousseau Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -157,4 +195,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- \ No newline at end of file +------------------------------------------------------------------------------ diff --git a/README.md b/README.md index 4ef3f5e..80d4824 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ Markdown (.md) file viewer [WebExtension](https://developer.mozilla.org/en-US/Ad ## Test * (Firefox won't install the generated .zip unless it's signed by Mozilla; you can test from the staging folder.) * Navigate to the staging folder and run `web-ext run`. -* Or install `staging/manifest.json` [temporarily in Firefox](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox). \ No newline at end of file +* Or install `staging/manifest.json` [temporarily in Firefox](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox). diff --git a/build.bat b/build.bat index f2a7f95..02741bf 100644 --- a/build.bat +++ b/build.bat @@ -10,13 +10,13 @@ lib\sss\sss.print.css ) do @call :copyfile %%f staging\%%f -@browserify .\ext\content.js^ +@call browserify .\ext\content.js^ + -r .\lib\highlightjs\highlight.pack.min.js:highlight.js^ -r .\lib\markdown-it\dist\markdown-it.min.js:markdown-it^ -r .\lib\markdown-it-checkbox\dist\markdown-it-checkbox.min.js:markdown-it-checkbox^ - -r .\lib\highlightjs\highlight.pack.min.js:highlight.js^ -o .\staging\ext\content.js -@web-ext build -s staging +@call web-ext build -s staging @goto :EOF :copyfile diff --git a/build.sh b/build.sh index 4c52aaa..8aa25ee 100644 --- a/build.sh +++ b/build.sh @@ -13,9 +13,9 @@ do done browserify ./ext/content.js\ + -r ./lib/highlightjs/highlight.pack.min.js:highlight.js\ -r ./lib/markdown-it/dist/markdown-it.min.js:markdown-it\ -r ./lib/markdown-it-checkbox/dist/markdown-it-checkbox.min.js:markdown-it-checkbox\ - -r ./lib/highlightjs/highlight.pack.min.js:highlight.js\ -o ./staging/ext/content.js web-ext build -s staging diff --git a/ext/208x128.png b/ext/208x128.png deleted file mode 100644 index 9470f08..0000000 Binary files a/ext/208x128.png and /dev/null differ diff --git a/ext/32x20.png b/ext/32x20.png deleted file mode 100644 index 863afc5..0000000 Binary files a/ext/32x20.png and /dev/null differ diff --git a/ext/48x30.png b/ext/48x30.png deleted file mode 100644 index c207a65..0000000 Binary files a/ext/48x30.png and /dev/null differ diff --git a/ext/66x40.png b/ext/66x40.png deleted file mode 100644 index 9d73e3e..0000000 Binary files a/ext/66x40.png and /dev/null differ diff --git a/ext/background.js b/ext/background.js index 07b3a41..a3f3d3c 100644 --- a/ext/background.js +++ b/ext/background.js @@ -2,7 +2,7 @@ const markdownFileExtension = /\.m(arkdown|kdn?|d(o?wn)?)(\?.*)?(#.*)?$/i; - if (changeInfo.status == 'complete' && markdownFileExtension.test(tab.url)) { + if (changeInfo.status === 'complete' && markdownFileExtension.test(tab.url)) { // Support loading additional scripts on demand by content script. browser.runtime.onMessage.addListener((message, sender, sendResponse) => { diff --git a/ext/content.js b/ext/content.js index 387c6f1..0533563 100644 --- a/ext/content.js +++ b/ext/content.js @@ -1,9 +1,9 @@ -function addStylesheet(path, media) { +function addStylesheet(href, media) { var style = document.createElement('link'); style.rel = 'stylesheet'; - if (media) { style.setAttribute('media', media); } style.type = 'text/css'; - style.href = browser.extension.getURL(path); + style.href = href; + if (media) { style.setAttribute('media', media); } document.head.appendChild(style); } @@ -11,7 +11,7 @@ function processMarkdown(textContent) { // Parse the content Markdown => HTML var hljs = require('highlight.js'); - + var md = require('markdown-it')({ html: true, linkify: true, @@ -26,7 +26,6 @@ function processMarkdown(textContent) { try { return hljs.highlightAuto(str).value; } catch (__) {} - return ''; // use external default escaping } }) @@ -36,9 +35,11 @@ function processMarkdown(textContent) { var html = md.render(textContent); // Style the page and code highlights. - addStylesheet('lib/sss/sss.css'); - addStylesheet('lib/sss/sss.print.css', 'print'); - addStylesheet('lib/highlightjs/styles/default.css'); + addStylesheet(browser.extension.getURL('lib/sss/sss.css')); + addStylesheet(browser.extension.getURL('lib/sss/sss.print.css'), 'print'); + addStylesheet(browser.extension.getURL('lib/highlightjs/styles/default.css')); + // User-defined stylesheet. + addStylesheet('_markdown.css'); // This is considered a good practice for mobiles. var viewport = document.createElement('meta'); @@ -90,12 +91,12 @@ function processMarkdown(textContent) { // Execute only if .md is unprocessed text. var body = document.body; -if (body.childNodes.length == 1 && - body.children.length == 1 && - body.children[0].nodeName.toUpperCase() == 'PRE') +if (body.childNodes.length === 1 && + body.children.length === 1 && + body.children[0].nodeName.toUpperCase() === 'PRE') { var textContent = body.textContent; body.textContent = ''; processMarkdown(textContent); -} \ No newline at end of file +} diff --git a/ext/markdown-mark.svg b/ext/markdown-mark.svg new file mode 100644 index 0000000..f3ed113 --- /dev/null +++ b/ext/markdown-mark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/lib/sss/LICENSE b/lib/sss/LICENSE deleted file mode 100644 index 853b46d..0000000 --- a/lib/sss/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/manifest.json b/manifest.json index 4f77ee5..1bdcb64 100644 --- a/manifest.json +++ b/manifest.json @@ -1,19 +1,17 @@ { "manifest_version": 2, - "name": "markdown-viewer-webext", - "version": "1.1.0", + "name": "Markdown Viewer Webext", + "version": "1.2.0", "homepage_url": "https://github.com/KeithLRobertson/markdown-viewer", - "description": "Displays markdown documents beautified.\n\nMarkdown is a lightweight markup language which uses plain text to describe formatting information, such as # Heading, 1. numbered list, *bold*, etc. This add-on identifies markdown documents by the extension in the URL (.md, .markdown, etc.). When you navigate to a markdown document, if the content is plain text, this add-on formats it into HTML (with headings, bold text, etc.) as described in the document and displays it directly in your browser.\n\nA markdown document can contain Unicode characters, but it must begin with a Byte Order Marker for those characters to display correctly.", - + "description": "Displays markdown documents beautified in your browser.", + "permissions": [ "activeTab", "tabs", "" ], "icons": { - "32": "ext/32x20.png", - "48": "ext/48x30.png", - "66": "ext/66x40.png", - "208": "ext/208x128.png" + "48": "ext/markdown-mark.svg", + "96": "ext/markdown-mark.svg" }, "background": { diff --git a/test/_markdown.css b/test/_markdown.css new file mode 100644 index 0000000..5cf3d4c --- /dev/null +++ b/test/_markdown.css @@ -0,0 +1 @@ +h1 { font-weight: 700; color: #00a } diff --git a/test/test-file.md b/test/test-file.md index f5794c4..2672e8f 100644 --- a/test/test-file.md +++ b/test/test-file.md @@ -1,9 +1,12 @@ -# Title 1 -## Title 2 -### Title 3 -#### Title 4 -##### Title 5 -###### Title 6 +# Heading 1 +## Heading 2 +### Heading 3 +#### Heading 4 +##### Heading 5 +###### Heading 6 + +Markdown Viewer Webext now supports local styles in a file _markdown.css alongside the .md files. +This is used here to format the top-level heading in bold blue text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, @@ -12,39 +15,37 @@ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. -Unicode: éè +Unicode: âêîôûŵŷ äëïöüẅÿ àèìòùẁỳ áéíóúẃý Вот какой-то текст. **bold** *italic* -~~strike~~ - -multipe_underscores_in_text_without_parsing +~~strikethrough~~ -* item 1 -* item 2 -* item 3 +multiple_underscores_in_text_without_parsing -1. item 1 -2. item 2 -3. item 3 +Unordered lists with: +- asterisk +- dash +- or plus +- [ ] Can contain checkboxes, unchecked +- [X] or checked -| Header | Header | Header | -|--------|--------|--------| -| Cell | Cell | Cell | -| Cell | Cell | Cell | -| Cell | Cell | Cell | +Ordered lists: +1. start with numbers. +2. any number will do +3. if you like | Left-Aligned | Center Aligned | Right Aligned | | :------------ |:---------------:| -----:| -| col 3 is | some wordy text | $1600 | +| col 1 is | some wordy text | $1600 | | col 2 is | centered | $12 | | zebra stripes | are neat | $1 | -https://addons.mozilla.org/fr/firefox/addon/markdown-viewer/ +[Link to Markdown Viewer (on AMO)](https://addons.mozilla.org/firefox/addon/markdown-viewer-webext/) -[link (markdown-viewer on AMO)](https://addons.mozilla.org/fr/firefox/addon/markdown-viewer/) +https://addons.mozilla.org/firefox/addon/markdown-viewer-webext/ [relative link](hello-world.md) @@ -61,10 +62,10 @@ function myFunction() { ![Large image (should be resized)](http://lorempixel.com/1200/200/) -HTML is allowed +HTML is supported -But scripts (into script tags ot inline) aren't +But scripts (in script elements or from events) are not accepted - +