|
1 | | -# markdown-viewer |
2 | | -Markdown (.md) file viewer [WebExtension](https://developer.mozilla.org/en-US/Add-ons/WebExtensions) for your browser. |
| 1 | +# markdown-viewer |
| 2 | + |
| 3 | +Markdown (.md file) Viewer [WebExtension](https://developer.mozilla.org/en-US/Add-ons/WebExtensions). |
| 4 | +Displays markdown documents beatified in your browser. |
| 5 | + |
| 6 | +Markdown is a lightweight markup language which uses plain text to describe formatting information, such as `# Heading`, `1. numbered lists`, `**bold**`, etc. |
| 7 | +This add-on identifies markdown documents by the extension in the URL (one of .markdown, .md, .mdown, .mdwn, .mkd, .mkdn). |
| 8 | +When you navigate to a markdown document, if the content is plain text, not already styled (by GitHub for example), this add-on formats |
| 9 | +it into HTML (with headings, ordered lists, bold text, etc.) using markup from the document and displays it directly in your browser. |
| 10 | + |
| 11 | +## Unicode Characters |
| 12 | + |
| 13 | +So, non-ASCII characters in your document aren't displaying correctly? Special characters like " **á** " appear as " **á** "? |
| 14 | +This is a problem of character encoding, which concerns converting a file (a sequence of octets) into text (a sequence of characters) and back. |
| 15 | +By the time Firefox activates the Markdown Viewer Web Extension for your document, the file is already converted into text, correctly or incorrectly. |
| 16 | +If the file begins with a Byte Order Marker (BOM), a pseudo-character which tells how the file is encoded, then Firefox will see it and use that encoding. |
| 17 | +Otherwise, Firefox may have decoded the file with the wrong encoding. |
| 18 | +Although UTF-8 is the modern _de facto_ standard encoding, Firefox defaults to using your system's regional encoding, yielding incorrect results. |
| 19 | + |
| 20 | +Some extensions have worked around this by re-loading the file and explicitly decoding it as UTF-8, but it is a pain to do so. |
| 21 | +Plus, this extension is intended to be a light and simple wrapper around the markdown-to-HTML converter, markdown-it. |
| 22 | + |
| 23 | +When the markdown document is obtained from a web site, the site should return a Content-Type header which specifies the encoding. |
| 24 | +If it does not and the file lacks a BOM, you're out of luck. Contact the web site owner. |
| 25 | + |
| 26 | +When the markdown is loaded from a local file, there are no HTML headers to lean on. |
| 27 | +Fortunately, Firefox now has a setting which allows specifying that you want to use UTF-8 for local files without a BOM. |
| 28 | +Go to about:config, search for `intl.charset.fallback.utf8_for_file`, and set its value to `true`. It should look better now. |
| 29 | + |
| 30 | +## Viewing Original Markdown |
| 31 | + |
| 32 | +To keep it simple, the extension does not support on and off states. |
| 33 | +If the document has one of the supported extensions, it should convert. |
| 34 | +Some web sites however, like raw.githubusercontent.com, return CORS headers, in which case Firefox will not inject this extension's content scripts, so it cannot convert the document. |
| 35 | + |
| 36 | +If you're viewing pretty markdown and you want to see the original source text, right-click and select "View Page Source". |
| 37 | +(Make sure you don't have any text selected to see that option.) |
| 38 | +Of course, you can also (Ctrl-S) save the document to a file and open it in any text editor. |
| 39 | + |
| 40 | +## Saving Converted Markdown |
| 41 | + |
| 42 | +If you would like to save the HTML-converted text, it is possible to do so in the desktop versions of Firefox. |
| 43 | +* Open developer tools with F12. |
| 44 | +* In the Inspector tab, select the `<html>` root element. |
| 45 | +* Right-click > Copy > Outer HTML. |
| 46 | +* Paste the text into your favorite text editor and save. |
| 47 | + |
| 48 | +## Custom Appearance |
| 49 | + |
| 50 | +You don't like how the styled markdown looks? |
| 51 | +Using CSS, you can customize the appearance any way you like it. |
| 52 | +View Add-ons (about:addons), and click Options for the Markdown Viewer. |
| 53 | +There is a box to enter your Custom CSS text. (Sorry, there is not currently a "user-friendly" drop-down option.) |
| 54 | +As the instructions there state, click or tab out of the text box to save your changes. |
| 55 | +The CSS is not validated, so you may want to create your CSS outside the options page (or lift it from a site that you like), and paste it in. |
| 56 | +If you have entered some changes that you don't want to keep, refresh the options page to discard changes. |
| 57 | + |
| 58 | +For example to assign a maximum width root element in the styled markdown: |
| 59 | + |
| 60 | +```css |
| 61 | +.markdownRoot { |
| 62 | + margin: 0 auto; |
| 63 | + max-width: 888px; |
| 64 | + padding: 45px; |
| 65 | + border: lightgrey thin solid; |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +## "Can You Add This Feature?" |
| 70 | + |
| 71 | +This is an open-source project with the most liberal usage and change license there is. |
| 72 | +Please feel free to modify it to meet your needs, and to contribute your improvement back to the community. |
| 73 | + |
| 74 | +Think only experts can do that? |
| 75 | +Although I am a programmer, I can only just make my way around JavaScript, and I'm a total beginner with the WebExtension browser plugin API. |
| 76 | +I needed a markdown viewer, and the plugin API which the existing add-on had used was deprecated and removed, so I adapted that add-on to the new technology. |
| 77 | + |
| 78 | +I expect the feature set to grow, not from a single author, but by the contributions of users like you who need some additional capabilities. |
| 79 | +Several features have been added by community contributors who needed them, which include: |
| 80 | + |
| 81 | +* checkbox support |
| 82 | +* anchored headers |
| 83 | +* reload maintaining scroll location |
| 84 | +* custom CSS |
| 85 | + |
| 86 | +Many thanks to them and to our future contributors. Pull requests are welcomed. |
| 87 | + |
| 88 | +## To Build The Extension |
3 | 89 |
|
4 | | -## Build |
5 | 90 | * Required: |
6 | 91 | * [nodejs](https://nodejs.org/) with npm |
7 | 92 | * [web-ext](https://github.com/mozilla/web-ext/) (npm install -g web-ext) |
8 | 93 | * Run `build.bat` (Windows) or `build.sh` (Linux) |
9 | 94 |
|
10 | | -## Test |
11 | | -* (Firefox won't install the generated .zip unless it's signed by Mozilla; you can test from the staging folder.) |
12 | | -* Navigate to the staging folder and run `web-ext run`. |
13 | | -* Or install `staging/manifest.json` [temporarily in Firefox](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox). |
| 95 | +## To Test The Extension |
| 96 | + |
| 97 | +Firefox won't install the generated `.zip` file permanently until it's signed by Mozilla. |
| 98 | +You can test any changes using the cloned project files. |
| 99 | + |
| 100 | +* In a command prompt, navigate to the project root folder (containing the `manifest.json`) and run `web-ext run`. |
| 101 | +* Or to install the extension [temporarily in Firefox](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox): |
| 102 | + * First, uninstall this add-on if you have it already |
| 103 | + * Navigate to "about:debugging" |
| 104 | + * Click "Load Temporary Add-on" |
| 105 | + * Navigate to the project root folder and open the `manifest.json` file. |
0 commit comments