mirror of
https://github.com/wekan/wekan.git
synced 2026-02-24 17:04:07 +01:00
Fix: img tag did not allow width and height.
Removed swipebox from markdown editor img tag and updated marked markdown to newest version. Thanks to hradec and xet7 ! Closes #2956
This commit is contained in:
parent
a6d702d1ab
commit
2b26bbe78a
216 changed files with 7529 additions and 16839 deletions
33
packages/markdown/marked/docs/.eslintrc.json
Normal file
33
packages/markdown/marked/docs/.eslintrc.json
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"extends": "standard",
|
||||
"plugins": [
|
||||
"standard"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 5,
|
||||
"sourceType": "script"
|
||||
},
|
||||
"rules": {
|
||||
"semi": ["error", "always"],
|
||||
"indent": ["error", 2, {
|
||||
"SwitchCase": 1,
|
||||
"VariableDeclarator": { "var": 2 },
|
||||
"outerIIFEBody": 0
|
||||
}],
|
||||
"operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }],
|
||||
"space-before-function-paren": ["error", "never"],
|
||||
"no-cond-assign": "off",
|
||||
"no-useless-escape": "off",
|
||||
"one-var": "off",
|
||||
"no-control-regex": "off",
|
||||
"no-prototype-builtins": "off",
|
||||
|
||||
"prefer-const": "off",
|
||||
"no-var": "off"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"browser": true,
|
||||
"amd": true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Authors
|
||||
|
||||
Marked takes an encompassing approach to its community. As such, you can think of these as [concentric circles](https://medium.com/the-node-js-collection/healthy-open-source-967fa8be7951), where each group encompases the following groups.
|
||||
Marked takes an encompassing approach to its community. As such, you can think of these as [concentric circles](https://medium.com/the-node-js-collection/healthy-open-source-967fa8be7951), where each group encompasses the following groups.
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
|
|
@ -170,7 +170,7 @@ To be removed: You can remove yourself through the [GitHub UI](https://help.gith
|
|||
A note on volunteering:
|
||||
|
||||
1. Please do not volunteer unless you believe you can demonstrate to your peers you can do the work required.
|
||||
2. Please do not overcommit yourself; we count on those committed to the project to be responsive. Really consider, with all you have going on, wehther you able to really commit to it.
|
||||
2. Please do not overcommit yourself; we count on those committed to the project to be responsive. Really consider, with all you have going on, whether you able to really commit to it.
|
||||
3. Don't let the previous frighten you away, it can always be changed later by you or your peers.
|
||||
|
||||
[Details on badges](#badges)
|
||||
|
|
@ -227,7 +227,7 @@ Badges? If you *want* 'em, we got 'em, and here's how you get 'em (and…dr
|
|||
</blockquote>
|
||||
</dd>
|
||||
<dt>Dr. Docs</dt>
|
||||
<dd>Someone who has contributed a great deal to the creation and maintainance of the non-code areas of marked.</dd>
|
||||
<dd>Someone who has contributed a great deal to the creation and maintenance of the non-code areas of marked.</dd>
|
||||
<dt>Eye for the CLI</dt>
|
||||
<dd>At this point? Pretty much anyone who can update that `man` file to the current Marked version without regression in the CLI tool itself.</dd>
|
||||
<dt>GitHub Guru</dt>
|
||||
|
|
@ -259,9 +259,9 @@ Badges? If you *want* 'em, we got 'em, and here's how you get 'em (and…dr
|
|||
|
||||
<dl>
|
||||
<dt>Defibrillator</dt>
|
||||
<dd>A contributor who stepped up to help bring Marked back to life by contriuting solutions to help Marked pass when compared against the CommonMark and GitHub Flavored Markdown specifications.</dd>
|
||||
<dd>A contributor who stepped up to help bring Marked back to life by contributing solutions to help Marked pass when compared against the CommonMark and GitHub Flavored Markdown specifications.</dd>
|
||||
<dt>Maker of the Marked mark</dt>
|
||||
<dd>This badge is given to the person or oganization credited with creating the logo (or logotype) used in Marked communications for a given period of time. **Maker of the Marked mark from 2017 to present**, for example.</dd>
|
||||
<dd>This badge is given to the person or organization credited with creating the logo (or logotype) used in Marked communications for a given period of time. **Maker of the Marked mark from 2017 to present**, for example.</dd>
|
||||
<dt>Release Wrangler</dt>
|
||||
<dd>This is a badge given to all Publishers.</dd>
|
||||
<dt>Snyk's Security Saint</dt>
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
- [ ] Make sure you are on the `master` branch.
|
||||
- [ ] Be sure to run `npm install` or `npm update`.
|
||||
- [ ] Create a branch.
|
||||
- [ ] Make as small a change as possible.
|
||||
- [ ] Run `npm test`, fix any broken things (for linting, you can run `npm run lint` to have the linter fix them for you).
|
||||
- [ ] Submit a PR.
|
||||
- [ ] Update code in `src` folder. (`lib` folder is for auto compiled code)
|
||||
- [ ] Run `npm run test:all`, fix any broken things (for linting, you can run `npm run lint` to have the linter fix them for you).
|
||||
- [ ] Run `npm run build:reset` to remove changes to compiled files.
|
||||
- [ ] Submit a Pull Request.
|
||||
|
||||
## Design principles
|
||||
|
||||
|
|
@ -30,16 +31,19 @@ The following table lists the ticket type labels we use when there is work to be
|
|||
|RR - refactor and re-engineer |Results in an improvement to developers using Marked (improved readability) or end-users (faster performance) or both. |
|
||||
|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](#/README.md#specifications) |
|
||||
|NFU - new feature (user requested) |A capability Marked does not currently provide but has been requested by users of Marked. |
|
||||
|NFE - new feature (should be an extension) |A capability Marked does not currently provide and is not part of a spec. |
|
||||
|
||||
## Test early, often, and everything
|
||||
|
||||
We try to write test cases to validate output (writing tests based on the [supported specifications](#/README.md#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness.
|
||||
|
||||
|Location |Description |
|
||||
|:-------------|:---------------------------------------------------|
|
||||
|/test/browser |For testing Marked in a client-side implementation. |
|
||||
|/test/new |Tests not related to the original `markdown.pl`. |
|
||||
|/test/original|Tests validating against the original `markdown.pl`.|
|
||||
|Location |Description |
|
||||
|:---------------------|:--------------------------------------------------------------------------------------------------------------|
|
||||
|/test/specs/commonmark|Tests for [CommonMark](https://spec.commonmark.org/current/) compliance |
|
||||
|/test/specs/gfm |Tests for [GFM](https://github.github.com/gfm/) compliance |
|
||||
|/test/specs/new |Tests not related to the original `markdown.pl`. |
|
||||
|/test/specs/original |Tests validating against the original `markdown.pl`. |
|
||||
|/test/specs/redos |Tests for [ReDOS](https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS) vulnerabilities|
|
||||
|
||||
If your test uses features or options, assuming `gfm` is set to `false`, for example, you can add [front-matter](https://www.npmjs.com/package/front-matter) to the top of
|
||||
your `.md` file
|
||||
|
|
@ -84,9 +88,8 @@ To check for (and fix) standardized syntax (lint):
|
|||
npm run lint
|
||||
```
|
||||
|
||||
To build your own minified version of Marked:
|
||||
To build your own es5, esm, and minified versions of Marked:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
## Overall strategy
|
||||
|
||||
**Master is always shippable:** We try to merge PRs in such a way that `master` is the only branch to really be concerned about *and* `master` can always be released. This allows smoother flow between new fetures, bug fixes, and so on. (Almost a continuous deployment setup, without automation.)
|
||||
**Master is always shippable:** We try to merge PRs in such a way that `master` is the only branch to really be concerned about *and* `master` can always be released. This allows smoother flow between new features, bug fixes, and so on. (Almost a continuous deployment setup, without automation.)
|
||||
|
||||
## Versioning
|
||||
|
||||
|
|
@ -20,5 +20,5 @@ We follow [semantic versioning](https://semver.org) where the following sequence
|
|||
What to expect while Marked is a zero-major (0.x.y):
|
||||
|
||||
1. The major will remain at zero; thereby, alerting consumers to the potentially volatile nature of the package.
|
||||
2. The minor will tend to be more analagous to a `major` release.
|
||||
3. The patch will tend to be more analagous to a `minor` release or a collection of bug fixes (patches).
|
||||
2. The minor will tend to be more analogous to a `major` release.
|
||||
3. The patch will tend to be more analogous to a `minor` release or a collection of bug fixes (patches).
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ These documentation pages are also rendered using marked 💯
|
|||
|
||||
<h2 id="usage">Usage</h2>
|
||||
|
||||
### Warning: 🚨 Marked does not [sanitize](https://marked.js.org/#/USING_ADVANCED.md#options) the output HTML by default 🚨
|
||||
### Warning: 🚨 Marked does not [sanitize](https://marked.js.org/#/USING_ADVANCED.md#options) the output HTML. Please use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the output HTML! 🚨
|
||||
|
||||
**CLI**
|
||||
|
||||
|
|
@ -72,8 +72,8 @@ We actively support the features of the following [Markdown flavors](https://git
|
|||
|Flavor |Version |
|
||||
|:----------------------------------------------------------|:----------|
|
||||
|The original markdown.pl |-- |
|
||||
|[CommonMark](http://spec.commonmark.org/0.28/) |0.28 |
|
||||
|[GitHub Flavored Markdown](https://github.github.com/gfm/) |0.28 |
|
||||
|[CommonMark](http://spec.commonmark.org/0.29/) |0.29 |
|
||||
|[GitHub Flavored Markdown](https://github.github.com/gfm/) |0.29 |
|
||||
|
||||
By supporting the above Markdown flavors, it's possible that Marked can help you use other flavors as well; however, these are not actively supported by the community.
|
||||
|
||||
|
|
|
|||
|
|
@ -14,18 +14,19 @@ marked(markdownString [,options] [,callback])
|
|||
|
||||
```js
|
||||
// Create reference instance
|
||||
var myMarked = require('marked');
|
||||
const marked = require('marked');
|
||||
|
||||
// Set options
|
||||
// `highlight` example uses `highlight.js`
|
||||
myMarked.setOptions({
|
||||
renderer: new myMarked.Renderer(),
|
||||
highlight: function(code) {
|
||||
return require('highlight.js').highlightAuto(code).value;
|
||||
marked.setOptions({
|
||||
renderer: new marked.Renderer(),
|
||||
highlight: function(code, language) {
|
||||
const hljs = require('highlight.js');
|
||||
const validLanguage = hljs.getLanguage(language) ? language : 'plaintext';
|
||||
return hljs.highlight(validLanguage, code).value;
|
||||
},
|
||||
pedantic: false,
|
||||
gfm: true,
|
||||
tables: true,
|
||||
breaks: false,
|
||||
sanitize: false,
|
||||
smartLists: true,
|
||||
|
|
@ -34,14 +35,14 @@ myMarked.setOptions({
|
|||
});
|
||||
|
||||
// Compile
|
||||
console.log(myMarked('I am using __markdown__.'));
|
||||
console.log(marked(markdownString));
|
||||
```
|
||||
|
||||
<h2 id="options">Options</h2>
|
||||
|
||||
|Member |Type |Default |Since |Notes |
|
||||
|:-----------|:---------|:--------|:--------|:-------------|
|
||||
|baseUrl |`string` |`null` |0.3.9 |A prefix url for any relative link. |
|
||||
|baseUrl |`string` |`null` |0.3.9 |A prefix url for any relative link. |
|
||||
|breaks |`boolean` |`false` |v0.2.7 |If true, add `<br>` on a single line break (copies GitHub). Requires `gfm` be `true`.|
|
||||
|gfm |`boolean` |`true` |v0.2.1 |If true, use approved [GitHub Flavored Markdown (GFM) specification](https://github.github.com/gfm/).|
|
||||
|headerIds |`boolean` |`true` |v0.4.0 |If true, include an `id` attribute when emitting headings (h1, h2, h3, etc).|
|
||||
|
|
@ -50,13 +51,12 @@ console.log(myMarked('I am using __markdown__.'));
|
|||
|langPrefix |`string` |`'language-'`|v0.3.0|A string to prefix the className in a `<code>` block. Useful for syntax highlighting.|
|
||||
|mangle |`boolean` |`true` |v0.3.4 |If true, autolinked email address is escaped with HTML character references.|
|
||||
|pedantic |`boolean` |`false` |v0.2.1 |If true, conform to the original `markdown.pl` as much as possible. Don't fix original markdown bugs or behavior. Turns off and overrides `gfm`.|
|
||||
|renderer |`object` |`new Renderer()`|v0.3.0|An object containing functions to render tokens to HTML. See [extensibility](USING_PRO.md) for more details.|
|
||||
|sanitize |`boolean` |`false` |v0.2.1 |If true, sanitize the HTML passed into `markdownString` with the `sanitizer` function.|
|
||||
|renderer |`object` |`new Renderer()`|v0.3.0|An object containing functions to render tokens to HTML. See [extensibility](/#/USING_PRO.md) for more details.|
|
||||
|sanitize |`boolean` |`false` |v0.2.1 |If true, sanitize the HTML passed into `markdownString` with the `sanitizer` function.<br>**Warning**: This feature is deprecated and it should NOT be used as it cannot be considered secure.<br>Instead use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the output HTML! |
|
||||
|sanitizer |`function`|`null` |v0.3.4 |A function to sanitize the HTML passed into `markdownString`.|
|
||||
|silent |`boolean` |`false` |v0.2.7 |If true, the parser does not throw any exception.|
|
||||
|smartLists |`boolean` |`false` |v0.2.8 |If true, use smarter list behavior than those found in `markdown.pl`.|
|
||||
|smartypants |`boolean` |`false` |v0.2.9 |If true, use "smart" typographic punctuation for things like quotes and dashes.|
|
||||
|tables |`boolean` |`true` |v0.2.7 |If true and `gfm` is true, use [GFM Tables extension](https://github.github.com/gfm/#tables-extension-).|
|
||||
|xhtml |`boolean` |`false` |v0.3.2 |If true, emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.|
|
||||
|
||||
<h2 id="highlight">Asynchronous highlighting</h2>
|
||||
|
|
@ -64,7 +64,7 @@ console.log(myMarked('I am using __markdown__.'));
|
|||
Unlike `highlight.js` the `pygmentize.js` library uses asynchronous highlighting. This example demonstrates that marked is agnostic when it comes to the highlighter you use.
|
||||
|
||||
```js
|
||||
myMarked.setOptions({
|
||||
marked.setOptions({
|
||||
highlight: function(code, lang, callback) {
|
||||
require('pygmentize-bundled') ({ lang: lang, format: 'html' }, code, function (err, result) {
|
||||
callback(err, result.toString());
|
||||
|
|
@ -72,7 +72,81 @@ myMarked.setOptions({
|
|||
}
|
||||
});
|
||||
|
||||
console.log(myMarked(markdownString));
|
||||
console.log(marked(markdownString));
|
||||
```
|
||||
|
||||
In both examples, `code` is a `string` representing the section of code to pass to the highlighter. In this example, `lang` is a `string` informing the highlighter what programming lnaguage to use for the `code` and `callback` is the `function` the asynchronous highlighter will call once complete.
|
||||
In both examples, `code` is a `string` representing the section of code to pass to the highlighter. In this example, `lang` is a `string` informing the highlighter what programming language to use for the `code` and `callback` is the `function` the asynchronous highlighter will call once complete.
|
||||
|
||||
<h2 id="workers">Workers</h2>
|
||||
|
||||
To prevent ReDoS attacks you can run marked on a worker and terminate it when parsing takes longer than usual.
|
||||
|
||||
Marked can be run in a [worker thread](https://nodejs.org/api/worker_threads.html) on a node server, or a [web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) in a browser.
|
||||
|
||||
### Node Worker Thread
|
||||
|
||||
```js
|
||||
// markedWorker.js
|
||||
|
||||
const marked = require('marked');
|
||||
const { parentPort } = require('worker_threads');
|
||||
|
||||
parentPort.on('message', (markdownString) => {
|
||||
parentPort.postMessage(marked(markdownString));
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// index.js
|
||||
|
||||
const { Worker } = require('worker_threads');
|
||||
const markedWorker = new Worker('./markedWorker.js');
|
||||
|
||||
const markedTimeout = setTimeout(() => {
|
||||
markedWorker.terminate();
|
||||
throw new Error('Marked took too long!');
|
||||
}, timeoutLimit);
|
||||
|
||||
markedWorker.on('message', (html) => {
|
||||
clearTimeout(markedTimeout);
|
||||
console.log(html);
|
||||
markedWorker.terminate();
|
||||
});
|
||||
|
||||
markedWorker.postMessage(markdownString);
|
||||
```
|
||||
|
||||
### Web Worker
|
||||
|
||||
> **NOTE**: Web Workers send the payload from `postMessage` in an object with the payload in a `.data` property
|
||||
|
||||
```js
|
||||
// markedWorker.js
|
||||
|
||||
importScripts('path/to/marked.min.js');
|
||||
|
||||
onmessage = (e) => {
|
||||
const markdownString = e.data
|
||||
postMessage(marked(markdownString));
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
// script.js
|
||||
|
||||
const markedWorker = new Worker('./markedWorker.js');
|
||||
|
||||
const markedTimeout = setTimeout(() => {
|
||||
markedWorker.terminate();
|
||||
throw new Error('Marked took too long!');
|
||||
}, timeoutLimit);
|
||||
|
||||
markedWorker.onmessage = (e) => {
|
||||
clearTimeout(markedTimeout);
|
||||
const html = e.data;
|
||||
console.log(html);
|
||||
markedWorker.terminate();
|
||||
};
|
||||
|
||||
markedWorker.postMessage(markdownString);
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
## Extending Marked
|
||||
|
||||
To champion the single-responsibility and open/closed prinicples, we have tried to make it relatively painless to extend marked. If you are looking to add custom functionality, this is the place to start.
|
||||
To champion the single-responsibility and open/closed principles, we have tried to make it relatively painless to extend marked. If you are looking to add custom functionality, this is the place to start.
|
||||
|
||||
<h2 id="renderer">The renderer</h2>
|
||||
|
||||
|
|
@ -10,14 +10,14 @@ The renderer is...
|
|||
|
||||
```js
|
||||
// Create reference instance
|
||||
var myMarked = require('marked');
|
||||
const marked = require('marked');
|
||||
|
||||
// Get reference
|
||||
var renderer = new myMarked.Renderer();
|
||||
const renderer = new marked.Renderer();
|
||||
|
||||
// Override function
|
||||
renderer.heading = function (text, level) {
|
||||
var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
|
||||
return `
|
||||
<h${level}>
|
||||
|
|
@ -29,7 +29,7 @@ renderer.heading = function (text, level) {
|
|||
};
|
||||
|
||||
// Run marked
|
||||
console.log(myMarked('# heading+', { renderer: renderer }));
|
||||
console.log(marked('# heading+', { renderer: renderer }));
|
||||
```
|
||||
|
||||
**Output:**
|
||||
|
|
@ -105,13 +105,13 @@ The parser is...
|
|||
You also have direct access to the lexer and parser if you so desire.
|
||||
|
||||
``` js
|
||||
var tokens = marked.lexer(text, options);
|
||||
console.log(marked.parser(tokens));
|
||||
const tokens = marked.lexer(text, options);
|
||||
console.log(marked.parser(tokens, options));
|
||||
```
|
||||
|
||||
``` js
|
||||
var lexer = new marked.Lexer(options);
|
||||
var tokens = lexer.lex(text);
|
||||
const lexer = new marked.Lexer(options);
|
||||
const tokens = lexer.lex(text);
|
||||
console.log(tokens);
|
||||
console.log(lexer.rules);
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* globals marked, unfetch, ES6Promise */
|
||||
/* globals marked, unfetch, ES6Promise, Promise */ // eslint-disable-line no-redeclare
|
||||
|
||||
if (!window.Promise) {
|
||||
window.Promise = ES6Promise;
|
||||
|
|
@ -7,7 +7,7 @@ if (!window.fetch) {
|
|||
window.fetch = unfetch;
|
||||
}
|
||||
|
||||
onunhandledrejection = function (e) {
|
||||
onunhandledrejection = function(e) {
|
||||
throw e.reason;
|
||||
};
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ Promise.all([
|
|||
setInitialText(),
|
||||
setInitialVersion()
|
||||
.then(setInitialOptions)
|
||||
]).then(function () {
|
||||
]).then(function() {
|
||||
handleInputChange();
|
||||
handleOutputChange();
|
||||
checkForChanges();
|
||||
|
|
@ -84,8 +84,8 @@ function setInitialText() {
|
|||
$markdownElem.value = search.text;
|
||||
} else {
|
||||
return fetch('./initial.md')
|
||||
.then(function (res) { return res.text(); })
|
||||
.then(function (text) {
|
||||
.then(function(res) { return res.text(); })
|
||||
.then(function(text) {
|
||||
if ($markdownElem.value === '') {
|
||||
$markdownElem.value = text;
|
||||
}
|
||||
|
|
@ -95,18 +95,18 @@ function setInitialText() {
|
|||
|
||||
function setInitialQuickref() {
|
||||
return fetch('./quickref.md')
|
||||
.then(function (res) { return res.text(); })
|
||||
.then(function (text) {
|
||||
.then(function(res) { return res.text(); })
|
||||
.then(function(text) {
|
||||
document.querySelector('#quickref').value = text;
|
||||
});
|
||||
}
|
||||
|
||||
function setInitialVersion() {
|
||||
return fetch('https://data.jsdelivr.com/v1/package/npm/marked')
|
||||
.then(function (res) {
|
||||
.then(function(res) {
|
||||
return res.json();
|
||||
})
|
||||
.then(function (json) {
|
||||
.then(function(json) {
|
||||
for (var i = 0; i < json.versions.length; i++) {
|
||||
var ver = json.versions[i];
|
||||
markedVersions[ver] = 'https://cdn.jsdelivr.net/npm/marked@' + ver + '/lib/marked.js';
|
||||
|
|
@ -116,20 +116,20 @@ function setInitialVersion() {
|
|||
$markedVerElem.appendChild(opt);
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
return fetch('https://api.github.com/repos/markedjs/marked/commits')
|
||||
.then(function (res) {
|
||||
.then(function(res) {
|
||||
return res.json();
|
||||
})
|
||||
.then(function (json) {
|
||||
markedVersions['master'] = 'https://cdn.jsdelivr.net/gh/markedjs/marked@' + json[0].sha + '/lib/marked.js';
|
||||
.then(function(json) {
|
||||
markedVersions.master = 'https://cdn.jsdelivr.net/gh/markedjs/marked@' + json[0].sha + '/lib/marked.js';
|
||||
})
|
||||
.catch(function () {
|
||||
.catch(function() {
|
||||
// do nothing
|
||||
// uses url without commit
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
.then(function() {
|
||||
if (search.version) {
|
||||
if (markedVersions[search.version]) {
|
||||
return search.version;
|
||||
|
|
@ -142,7 +142,7 @@ function setInitialVersion() {
|
|||
return search.version;
|
||||
case 'pr':
|
||||
return getPrCommit(match[2])
|
||||
.then(function (commit) {
|
||||
.then(function(commit) {
|
||||
if (!commit) {
|
||||
return 'master';
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ function setInitialVersion() {
|
|||
|
||||
return 'master';
|
||||
})
|
||||
.then(function (version) {
|
||||
.then(function(version) {
|
||||
$markedVerElem.value = version;
|
||||
})
|
||||
.then(updateVersion);
|
||||
|
|
@ -220,7 +220,7 @@ function handleAddVersion(e) {
|
|||
$commitVerElem.disabled = true;
|
||||
var pr = $commitVerElem.value.replace(/\D/g, '');
|
||||
getPrCommit(pr)
|
||||
.then(function (commit) {
|
||||
.then(function(commit) {
|
||||
$commitVerElem.disabled = false;
|
||||
if (!commit) {
|
||||
alert('That is not a valid PR');
|
||||
|
|
@ -271,12 +271,12 @@ function addCommitVersion(value, text, commit) {
|
|||
|
||||
function getPrCommit(pr) {
|
||||
return fetch('https://api.github.com/repos/markedjs/marked/pulls/' + pr + '/commits')
|
||||
.then(function (res) {
|
||||
.then(function(res) {
|
||||
return res.json();
|
||||
})
|
||||
.then(function (json) {
|
||||
.then(function(json) {
|
||||
return json[json.length - 1].sha;
|
||||
}).catch(function () {
|
||||
}).catch(function() {
|
||||
// return undefined
|
||||
});
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ function setDefaultOptions() {
|
|||
function setOptions(opts) {
|
||||
$optionsElem.value = JSON.stringify(
|
||||
opts,
|
||||
function (key, value) {
|
||||
function(key, value) {
|
||||
if (value && typeof value === 'object' && Object.getPrototypeOf(value) !== Object.prototype) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
@ -375,13 +375,13 @@ function updateVersion() {
|
|||
promise = Promise.resolve(markedVersionCache[$markedVerElem.value]);
|
||||
} else {
|
||||
promise = fetch(markedVersions[$markedVerElem.value])
|
||||
.then(function (res) { return res.text(); })
|
||||
.then(function (text) {
|
||||
.then(function(res) { return res.text(); })
|
||||
.then(function(text) {
|
||||
markedVersionCache[$markedVerElem.value] = text;
|
||||
return text;
|
||||
});
|
||||
}
|
||||
return promise.then(function (text) {
|
||||
return promise.then(function(text) {
|
||||
var script = document.createElement('script');
|
||||
script.textContent = text;
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ function messageWorker(message) {
|
|||
markedWorker.terminate();
|
||||
}
|
||||
markedWorker = new Worker('worker.js');
|
||||
markedWorker.onmessage = function (e) {
|
||||
markedWorker.onmessage = function(e) {
|
||||
clearTimeout(markedWorker.timeout);
|
||||
markedWorker.working = false;
|
||||
switch (e.data.task) {
|
||||
|
|
@ -500,7 +500,7 @@ function messageWorker(message) {
|
|||
delayTime = 10;
|
||||
checkForChanges();
|
||||
};
|
||||
markedWorker.onerror = markedWorker.onmessageerror = function (err) {
|
||||
markedWorker.onerror = markedWorker.onmessageerror = function(err) {
|
||||
clearTimeout(markedWorker.timeout);
|
||||
var error = 'There was an error in the Worker';
|
||||
if (err) {
|
||||
|
|
@ -526,7 +526,7 @@ function messageWorker(message) {
|
|||
}
|
||||
|
||||
function workerTimeout(seconds) {
|
||||
markedWorker.timeout = setTimeout(function () {
|
||||
markedWorker.timeout = setTimeout(function() {
|
||||
seconds++;
|
||||
markedWorker.onerror('Marked has taken longer than ' + seconds + ' second' + (seconds > 1 ? 's' : '') + ' to respond...');
|
||||
workerTimeout(seconds);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* globals marked, unfetch, ES6Promise */
|
||||
/* globals marked, unfetch, ES6Promise, Promise */ // eslint-disable-line no-redeclare
|
||||
if (!self.Promise) {
|
||||
self.importScripts('https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js');
|
||||
self.Promise = ES6Promise;
|
||||
|
|
@ -11,15 +11,15 @@ if (!self.fetch) {
|
|||
var versionCache = {};
|
||||
var currentVersion;
|
||||
|
||||
onunhandledrejection = function (e) {
|
||||
onunhandledrejection = function(e) {
|
||||
throw e.reason;
|
||||
};
|
||||
|
||||
onmessage = function (e) {
|
||||
onmessage = function(e) {
|
||||
if (e.data.version === currentVersion) {
|
||||
parse(e);
|
||||
} else {
|
||||
loadVersion(e.data.version).then(function () {
|
||||
loadVersion(e.data.version).then(function() {
|
||||
parse(e);
|
||||
});
|
||||
}
|
||||
|
|
@ -87,13 +87,13 @@ function loadVersion(ver) {
|
|||
promise = Promise.resolve(versionCache[ver]);
|
||||
} else {
|
||||
promise = fetch(ver)
|
||||
.then(function (res) { return res.text(); })
|
||||
.then(function (text) {
|
||||
.then(function(res) { return res.text(); })
|
||||
.then(function(text) {
|
||||
versionCache[ver] = text;
|
||||
return text;
|
||||
});
|
||||
}
|
||||
return promise.then(function (text) {
|
||||
return promise.then(function(text) {
|
||||
try {
|
||||
// eslint-disable-next-line no-new-func
|
||||
Function(text)();
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@
|
|||
<ul>
|
||||
<li><a href="#/USING_ADVANCED.md#options">Options</a></li>
|
||||
<li><a href="#/USING_ADVANCED.md#highlight">Highlighting</a></li>
|
||||
<li><a href="#/USING_ADVANCED.md#workers">Workers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue