- Docs (JSDocs) Switch to JS-based config file
- Leverage syntax highlighting reporting of JSDoc to lint our code (npm version does not seem to reflect that on Github, so we use Github version we need)
- Docs (ESLint): Apply most of our ESLint rules (except `no-undefined` and `padded-blocks`) to sample code blocks
master
Brett Zamir 2018-10-31 02:43:45 +08:00
parent bcf31405fc
commit afa5576ed1
7 changed files with 170 additions and 65 deletions

83
docs/jsdoc-config.js Normal file
View File

@ -0,0 +1,83 @@
/* eslint-env node */
'use strict';
module.exports = {
plugins: ['plugins/markdown'],
markdown: {
// "The highlighter function should escape the code block's contents and wrap them in <pre><code> tags"
highlight (code, language) {
function ret () {
// Default:
return '<pre><code>' + code + ' in this language: ' + language + '</code></pre>';
}
if (language !== 'js') { // E.g., we have one URL in some tutorial Markdown
return ret();
}
// Programmatic ESLint API: https://eslint.org/docs/developer-guide/nodejs-api
const {CLIEngine} = require('eslint');
const cli = new CLIEngine({
useEslintrc: true,
rules: {
'no-undef': 0, // Many variables in examples will be undefined
'padded-blocks': 0 // Can look nicer
}
});
// Undo escaping done by node_modules/jsdoc/lib/jsdoc/util/markdown.js
code = code
.replace(/\s+$/, '')
.replace(/&#39;/g, "'")
.replace(/(https?):\\\/\\\//g, '$1://')
.replace(/\{@[^}\r\n]+\}/g, function (wholeMatch) {
return wholeMatch.replace(/&quot;/g, '"');
});
// lint the supplied text and optionally set
// a filename that is displayed in the report
const report = cli.executeOnText(code + '\n');
if (!report.errorCount && !report.warningCount) {
return ret();
}
// Although we don't get the file, at least we can report the source code
const {messages} = report.results[0];
messages.forEach(({message, line, column, severity, ruleId}) => {
console.log(`${ruleId}: ${message} (Severity: ${severity}; ${line}:${column})`);
});
console.log('\n' + code);
return ret();
},
tags: []
},
recurseDepth: 10,
source: {
exclude: [
'node_modules',
'dist',
'firefox-extension',
'opera-widget',
'screencasts',
'test'
],
excludePattern: 'svgedit-config-*|build-html.js|rollup*|external/babel-polyfill|extensions/mathjax|imagelib/jquery.min.js|jspdf/jspdf.min.js|jspdf/underscore-min.js|jquery-ui|jquery.min.js|jquerybbq|js-hotkeys'
},
sourceType: 'module',
tags: {
allowUnknownTags: false
},
templates: {
cleverLinks: true,
monospaceLinks: false,
default: {
layoutFile: 'docs/layout.tmpl'
}
},
opts: {
recurse: true,
verbose: true,
destination: 'docs/jsdoc',
tutorials: 'docs/tutorials'
}
};

View File

@ -1,35 +0,0 @@
{
"plugins": ["plugins/markdown"],
"markdown": {
"tags": []
},
"recurseDepth": 10,
"source": {
"exclude": [
"node_modules",
"dist",
"firefox-extension",
"opera-widget",
"screencasts",
"test"
],
"excludePattern": "svgedit-config-*|build-html.js|rollup*|external/babel-polyfill|extensions/mathjax|imagelib/jquery.min.js|jspdf/jspdf.min.js|jspdf/underscore-min.js|jquery-ui|jquery.min.js|jquerybbq|js-hotkeys"
},
"sourceType": "module",
"tags": {
"allowUnknownTags": false
},
"templates": {
"cleverLinks": true,
"monospaceLinks": false,
"default": {
"layoutFile": "docs/layout.tmpl"
}
},
"opts":{
"recurse": true,
"verbose": true,
"destination": "docs/jsdoc",
"tutorials": "docs/tutorials"
}
}

View File

@ -136,13 +136,13 @@ As a URL parameter, one can pre-load an SVG file in the following manner:
```js
// Data URI
'?source=' + encodeURIComponent('data:image/svg+xml;utf8,' + /*...*/);
location.href += '?source=' + encodeURIComponent('data:image/svg+xml;utf8,' + svgText);
// Data URI (base 64):
'?source=' + encodeURIComponent('data:image/svg+xml;base64,' + /* ... */); // data%3Aimage%2Fsvg%2Bxml%3Bbase64%2C ...
location.href += '?source=' + encodeURIComponent('data:image/svg+xml;base64,' + svgTextAsBase64); // data%3Aimage%2Fsvg%2Bxml%3Bbase64%2C ...
// Local URL:
'?url=' + encodeURIComponent('images/logo.svg'); // images%2Flogo.svg
location.href += '?url=' + encodeURIComponent('images/logo.svg'); // images%2Flogo.svg
```
**Note:** There is currently a bug that prevents data URIs ending with

View File

@ -8,9 +8,9 @@ the SVG file differently:
### Example
```js
svgEditor.setCustomHandlers({
save (win, data) {
// Save svg
}
save (win, data) {
// Save svg
}
});
```

View File

@ -76,14 +76,14 @@ export default {
name: 'helloworld',
init () {
return {
svgicons: 'extensions/helloworld-icon.xml',
buttons: [{...}],
mouseDown () {
...
},
mouseUp (opts) {
...
}
svgicons: 'extensions/helloworld-icon.xml',
buttons: [{ /* ... */ }],
mouseDown () {
// ...
},
mouseUp (opts) {
// ...
}
};
}
};
@ -149,6 +149,7 @@ const localeStrings = await importSetGlobalDefault(url, {
});
// Use `localeStrings`
console.log(localeStrings);
})();
```

84
package-lock.json generated
View File

@ -1131,7 +1131,7 @@
},
"async": {
"version": "0.2.6",
"resolved": "http://registry.npmjs.org/async/-/async-0.2.6.tgz",
"resolved": "https://registry.npmjs.org/async/-/async-0.2.6.tgz",
"integrity": "sha1-rT83PZJJrjJIgVZVgryQ4VKrvWg=",
"dev": true
},
@ -1883,7 +1883,7 @@
},
"regjsgen": {
"version": "0.2.0",
"resolved": "http://registry.npmjs.org/regjsgen/-/regjsgen-0.2.0.tgz",
"resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.2.0.tgz",
"integrity": "sha1-bAFq3qxVT3WCP+N6wFuS1aTtsfc=",
"dev": true
},
@ -3400,6 +3400,12 @@
"integrity": "sha1-pls+QtC3HPxYXrd0+ZQ8jZuRsMI=",
"dev": true
},
"entities": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz",
"integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==",
"dev": true
},
"errno": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz",
@ -5922,9 +5928,8 @@
"dev": true
},
"jsdoc": {
"version": "3.5.5",
"resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.5.5.tgz",
"integrity": "sha512-6PxB65TAU4WO0Wzyr/4/YhlGovXl0EVYfpKbpSroSj0qBxT4/xod/l40Opkm38dRHRdQgdeY836M0uVnJQG7kg==",
"version": "git+https://github.com/jsdoc3/jsdoc.git#b21427343c7294bbf1f14c718a390f3e955e37cb",
"from": "git+https://github.com/jsdoc3/jsdoc.git#b21427343c7294bbf1f14c718a390f3e955e37cb",
"dev": true,
"requires": {
"babylon": "7.0.0-beta.19",
@ -5933,6 +5938,8 @@
"escape-string-regexp": "~1.0.5",
"js2xmlparser": "~3.0.0",
"klaw": "~2.0.0",
"markdown-it": "~8.3.1",
"markdown-it-named-headers": "~0.0.4",
"marked": "~0.3.6",
"mkdirp": "~0.5.1",
"requizzle": "~0.2.1",
@ -6295,6 +6302,15 @@
"type-check": "~0.3.2"
}
},
"linkify-it": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz",
"integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=",
"dev": true,
"requires": {
"uc.micro": "^1.0.1"
}
},
"linux-platform-info": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/linux-platform-info/-/linux-platform-info-0.0.3.tgz",
@ -6519,6 +6535,28 @@
"integrity": "sha512-WWC0ZuMzCyDHYCasEGs4IPvLyTGftYwh6wIEOULOF0HXcqZlhwRzrK0w2VUlxWA98xnvb/jszw4ZSkJ6ADpM6Q==",
"dev": true
},
"markdown-it": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.3.2.tgz",
"integrity": "sha512-4J92IhJq1kGoyXddwzzfjr9cEKGexBfFsZooKYMhMLLlWa4+dlSPDUUP7y+xQOCebIj61aLmKlowg//YcdPP1w==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"entities": "~1.1.1",
"linkify-it": "^2.0.0",
"mdurl": "^1.0.1",
"uc.micro": "^1.0.3"
}
},
"markdown-it-named-headers": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/markdown-it-named-headers/-/markdown-it-named-headers-0.0.4.tgz",
"integrity": "sha1-gu/CgyQkCmsed7mq5QF3HV81HB8=",
"dev": true,
"requires": {
"string": "^3.0.1"
}
},
"markdown-table": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/markdown-table/-/markdown-table-1.1.2.tgz",
@ -6584,6 +6622,12 @@
"extend": "3.0.2"
}
},
"mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
"integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=",
"dev": true
},
"meow": {
"version": "3.7.0",
"resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
@ -8882,6 +8926,12 @@
"integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=",
"dev": true
},
"string": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/string/-/string-3.3.3.tgz",
"integrity": "sha1-XqIRzZLSKOGEKUmQpsyXs2anfLA=",
"dev": true
},
"string-range": {
"version": "1.2.2",
"resolved": "http://registry.npmjs.org/string-range/-/string-range-1.2.2.tgz",
@ -9190,7 +9240,7 @@
"dependencies": {
"pify": {
"version": "2.3.0",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"dev": true
}
@ -9378,7 +9428,7 @@
},
"core-js": {
"version": "1.2.7",
"resolved": "http://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=",
"dev": true
}
@ -9505,7 +9555,7 @@
},
"core-js": {
"version": "1.2.7",
"resolved": "http://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=",
"dev": true
},
@ -9534,37 +9584,37 @@
},
"testcafe-reporter-json": {
"version": "2.1.0",
"resolved": "http://registry.npmjs.org/testcafe-reporter-json/-/testcafe-reporter-json-2.1.0.tgz",
"resolved": "https://registry.npmjs.org/testcafe-reporter-json/-/testcafe-reporter-json-2.1.0.tgz",
"integrity": "sha1-gLm1pt/y7h3h+R4mcHBsFHLmQAY=",
"dev": true
},
"testcafe-reporter-list": {
"version": "2.1.0",
"resolved": "http://registry.npmjs.org/testcafe-reporter-list/-/testcafe-reporter-list-2.1.0.tgz",
"resolved": "https://registry.npmjs.org/testcafe-reporter-list/-/testcafe-reporter-list-2.1.0.tgz",
"integrity": "sha1-n6ifcbl9Pf5ktDAtXiJ97mmuxrk=",
"dev": true
},
"testcafe-reporter-minimal": {
"version": "2.1.0",
"resolved": "http://registry.npmjs.org/testcafe-reporter-minimal/-/testcafe-reporter-minimal-2.1.0.tgz",
"resolved": "https://registry.npmjs.org/testcafe-reporter-minimal/-/testcafe-reporter-minimal-2.1.0.tgz",
"integrity": "sha1-Z28DVHY0FDxurzq1KGgnOkvr9CE=",
"dev": true
},
"testcafe-reporter-spec": {
"version": "2.1.1",
"resolved": "http://registry.npmjs.org/testcafe-reporter-spec/-/testcafe-reporter-spec-2.1.1.tgz",
"resolved": "https://registry.npmjs.org/testcafe-reporter-spec/-/testcafe-reporter-spec-2.1.1.tgz",
"integrity": "sha1-gVb87Q9RMkhlWa1WC8gGdkaSdew=",
"dev": true
},
"testcafe-reporter-xunit": {
"version": "2.1.0",
"resolved": "http://registry.npmjs.org/testcafe-reporter-xunit/-/testcafe-reporter-xunit-2.1.0.tgz",
"resolved": "https://registry.npmjs.org/testcafe-reporter-xunit/-/testcafe-reporter-xunit-2.1.0.tgz",
"integrity": "sha1-5tZsVyzhWvJmcGrw/WELKoQd1EM=",
"dev": true
},
"text-encoding": {
"version": "0.6.4",
"resolved": "http://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz",
"resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz",
"integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=",
"dev": true
},
@ -9815,6 +9865,12 @@
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
"dev": true
},
"uc.micro": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.5.tgz",
"integrity": "sha512-JoLI4g5zv5qNyT09f4YAvEZIIV1oOjqnewYg5D38dkQljIzpPT296dbIGvKro3digYI1bkb7W6EP1y4uDlmzLg==",
"dev": true
},
"ultron": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",

View File

@ -15,7 +15,7 @@
"build-config": "rollup -c rollup-config.config.js",
"types-doc": "node jsdoc-check-overly-generic-types.js",
"open-es-allext": "opn http://localhost:8000/editor/svg-editor-es.html?extensions=ext-arrows.js,ext-closepath.js,ext-foreignobject.js,ext-helloworld.js,ext-mathjax.js,ext-php_savefile.js,ext-server_moinsave.js,ext-server_opensave.js,ext-webappfind.js,ext-xdomain-messaging.js",
"build-doc": "rm -rf docs/jsdoc/*;jsdoc --pedantic -c docs/jsdoc-config.json editor",
"build-doc": "rm -rf docs/jsdoc/*;jsdoc --pedantic -c docs/jsdoc-config.js editor",
"build-html": "node build-html.js",
"compress-images": "imageoptim 'chrome-app/*.png' && imageoptim 'editor/extensions/*.png' && imageoptim 'editor/spinbtn/*.png' && imageoptim 'editor/jgraduate/images/*.{png,gif}' && imageoptim 'editor/images/*.png'",
"copy-deps": "cp node_modules/load-stylesheets/dist/index-es.js editor/external/load-stylesheets/index-es.js && cp node_modules/@babel/polyfill/dist/polyfill.min.js editor/external/@babel/polyfill/polyfill.min.js && cp node_modules/@babel/polyfill/dist/polyfill.js editor/external/@babel/polyfill/polyfill.js && cp node_modules/jamilih/dist/jml-es.js editor/external/jamilih/jml-es.js && cp node_modules/query-result/esm/index.js editor/external/query-result/esm/index.js && cp node_modules/qr-manipulation/dist/index-es.js editor/external/qr-manipulation/dist/index-es.js",
@ -91,7 +91,7 @@
"find-in-files": "^0.5.0",
"imageoptim-cli": "^2.0.3",
"jamilih": "^0.43.0",
"jsdoc": "^3.5.5",
"jsdoc": "https://github.com/jsdoc3/jsdoc#b21427343c7294bbf1f14c718a390f3e955e37cb",
"load-stylesheets": "^0.7.0",
"node-static": "^0.7.11",
"opn-cli": "^3.1.0",