feat: add prettier formatting

This commit is contained in:
David Wheatley 2021-12-29 13:17:02 +01:00
parent 252cd8455b
commit 81b27ede28
8 changed files with 112 additions and 65 deletions

View File

@ -3,85 +3,104 @@
## [1.1.0](https://github.com/flarum/markdown/compare/v1.0.1...v1.1.0) ## [1.1.0](https://github.com/flarum/markdown/compare/v1.0.1...v1.1.0)
### Added ### Added
- Spoiler and strikethrough buttons (https://github.com/flarum/markdown/pulls/30) - Spoiler and strikethrough buttons (https://github.com/flarum/markdown/pulls/30)
### Fixed ### Fixed
- Browser/system shortcuts triggering when applying editor style from shortcut (https://github.com/flarum/markdown/pulls/32) - Browser/system shortcuts triggering when applying editor style from shortcut (https://github.com/flarum/markdown/pulls/32)
## [1.0.1](https://github.com/flarum/markdown/compare/v1.0.0...v1.0.1) ## [1.0.1](https://github.com/flarum/markdown/compare/v1.0.0...v1.0.1)
### Fixed ### Fixed
- Link button is not visible on the markdown toolbar (https://github.com/flarum/markdown/pull/29) - Link button is not visible on the markdown toolbar (https://github.com/flarum/markdown/pull/29)
## [1.0.0](https://github.com/flarum/markdown/compare/v0.1.0-beta.16.1...v1.0.0) ## [1.0.0](https://github.com/flarum/markdown/compare/v0.1.0-beta.16.1...v1.0.0)
### Changed ### Changed
- Compatibility with Flarum v1.0.0. - Compatibility with Flarum v1.0.0.
- GitHub markdown toolbar moves to flarum/core (https://github.com/flarum/markdown/pull/28) - GitHub markdown toolbar moves to flarum/core (https://github.com/flarum/markdown/pull/28)
- Simplification of toolbar and button system (https://github.com/flarum/markdown/pull/28) - Simplification of toolbar and button system (https://github.com/flarum/markdown/pull/28)
### Fixed ### Fixed
- Toolbar buttons submits the form - Toolbar buttons submits the form
- Tooltips generate a deprecation warning - Tooltips generate a deprecation warning
### Removed ### Removed
- Dropped mdarea (https://github.com/flarum/markdown/pull/28) - Dropped mdarea (https://github.com/flarum/markdown/pull/28)
## [0.1.0-beta.16.1](https://github.com/flarum/markdown/compare/v0.1.0-beta.16...v0.1.0-beta.16.1) ## [0.1.0-beta.16.1](https://github.com/flarum/markdown/compare/v0.1.0-beta.16...v0.1.0-beta.16.1)
### Added ### Added
- Admin setting to disable mdarea (https://github.com/flarum/markdown/pull/27) - Admin setting to disable mdarea (https://github.com/flarum/markdown/pull/27)
## [0.1.0-beta.16](https://github.com/flarum/markdown/compare/v0.1.0-beta.15...v0.1.0-beta.16) ## [0.1.0-beta.16](https://github.com/flarum/markdown/compare/v0.1.0-beta.15...v0.1.0-beta.16)
### Added ### Added
- Editor Driver support ([ba3e1fb](https://github.com/flarum/markdown/commit/ba3e1fb528ce7e85bde27753f6c1cce3b03fe9d3)) - Editor Driver support ([ba3e1fb](https://github.com/flarum/markdown/commit/ba3e1fb528ce7e85bde27753f6c1cce3b03fe9d3))
### Changed ### Changed
- Updated admin category from formatting to feature (https://github.com/flarum/markdown/pull/25) - Updated admin category from formatting to feature (https://github.com/flarum/markdown/pull/25)
- Moved locale files from translation pack to extension (https://github.com/flarum/markdown/pull/21) - Moved locale files from translation pack to extension (https://github.com/flarum/markdown/pull/21)
### Fixed ### Fixed
- Double quote marks cause inconvenience typing ([6d8ea34](https://github.com/flarum/markdown/commit/6d8ea342061fdd2ab267cee93b9f5ade69149123)) - Double quote marks cause inconvenience typing ([6d8ea34](https://github.com/flarum/markdown/commit/6d8ea342061fdd2ab267cee93b9f5ade69149123))
## [0.1.0-beta.15](https://github.com/flarum/markdown/compare/v0.1.0-beta.14...v0.1.0-beta.15) ## [0.1.0-beta.15](https://github.com/flarum/markdown/compare/v0.1.0-beta.14...v0.1.0-beta.15)
### Changed ### Changed
- Updated composer.json and admin javascript for new admin area. - Updated composer.json and admin javascript for new admin area.
## [0.1.0-beta.14](https://github.com/flarum/markdown/compare/v0.1.0-beta.13...v0.1.0-beta.14) ## [0.1.0-beta.14](https://github.com/flarum/markdown/compare/v0.1.0-beta.13...v0.1.0-beta.14)
### Changed ### Changed
- Switch image and link defaults (#11) - Switch image and link defaults (#11)
- Updated mithril to version 2 - Updated mithril to version 2
- Load language strings correctly on en-/disable - Load language strings correctly on en-/disable
### Removed ### Removed
- Support for IE 11 (#18) - Support for IE 11 (#18)
## [0.1.0-beta.13](https://github.com/flarum/markdown/compare/v0.1.0-beta.12...v0.1.0-beta.13) ## [0.1.0-beta.13](https://github.com/flarum/markdown/compare/v0.1.0-beta.12...v0.1.0-beta.13)
### Changed ### Changed
- Updated JS dependencies - Updated JS dependencies
### Fixed ### Fixed
- Fixed not hiding other html entities than mentions (#14) - Fixed not hiding other html entities than mentions (#14)
## [0.1.0-beta.12](https://github.com/flarum/markdown/compare/v0.1.0-beta.10...v0.1.0-beta.12) ## [0.1.0-beta.12](https://github.com/flarum/markdown/compare/v0.1.0-beta.10...v0.1.0-beta.12)
### Fixed ### Fixed
- Mentions could be seen within spoiler blocks (#13) - Mentions could be seen within spoiler blocks (#13)
## [0.1.0-beta.10](https://github.com/flarum/markdown/compare/v0.1.0-beta.9...v0.1.0-beta.10) ## [0.1.0-beta.10](https://github.com/flarum/markdown/compare/v0.1.0-beta.9...v0.1.0-beta.10)
### Added ### Added
- The toolbar now has an image button (#8) - The toolbar now has an image button (#8)
### Fixed ### Fixed
- Unusable toolbar in IE11 (#8) - Unusable toolbar in IE11 (#8)
- Tabbing out of the post composer was not possible (#8) - Tabbing out of the post composer was not possible (#8)
## [0.1.0-beta.9](https://github.com/flarum/markdown/compare/v0.1.0-beta.8...v0.1.0-beta.9) ## [0.1.0-beta.9](https://github.com/flarum/markdown/compare/v0.1.0-beta.8...v0.1.0-beta.9)
### Fixed ### Fixed
- Markdown toolbar did not work on IE11 ([31c064f](https://github.com/flarum/markdown/commit/31c064f0c6c945083bc0ebc50cb3e44a676f40e2) and [e762293](https://github.com/flarum/markdown/commit/e7622938b1422e89a50feeb52c9c9ef7b38db95a)) - Markdown toolbar did not work on IE11 ([31c064f](https://github.com/flarum/markdown/commit/31c064f0c6c945083bc0ebc50cb3e44a676f40e2) and [e762293](https://github.com/flarum/markdown/commit/e7622938b1422e89a50feeb52c9c9ef7b38db95a))

View File

@ -1,39 +1,41 @@
{ {
"name": "flarum/markdown", "name": "flarum/markdown",
"description": "Allow posts to be formatted with Markdown.", "description": "Allow posts to be formatted with Markdown.",
"type": "flarum-extension", "type": "flarum-extension",
"keywords": ["formatting"], "keywords": [
"license": "MIT", "formatting"
"support": { ],
"issues": "https://github.com/flarum/core/issues", "license": "MIT",
"source": "https://github.com/flarum/markdown", "support": {
"forum": "https://discuss.flarum.org" "issues": "https://github.com/flarum/core/issues",
}, "source": "https://github.com/flarum/markdown",
"homepage": "https://flarum.org", "forum": "https://discuss.flarum.org"
"funding": [ },
{ "homepage": "https://flarum.org",
"type": "website", "funding": [
"url": "https://flarum.org/donate/" {
} "type": "website",
], "url": "https://flarum.org/donate/"
"require": {
"flarum/core": "^1.1"
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
},
"flarum-extension": {
"title": "Markdown",
"category": "feature",
"icon": {
"image": "icon.svg",
"backgroundColor": "#000",
"backgroundSize": "100%",
"backgroundRepeat": "no-repeat",
"backgroundPosition": "center",
"color": "#fff"
}
}
} }
],
"require": {
"flarum/core": "^1.1"
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
},
"flarum-extension": {
"title": "Markdown",
"category": "feature",
"icon": {
"image": "icon.svg",
"backgroundColor": "#000",
"backgroundSize": "100%",
"backgroundRepeat": "no-repeat",
"backgroundPosition": "center",
"color": "#fff"
}
}
}
} }

View File

@ -0,0 +1,2 @@
.yarn
dist

View File

@ -1,6 +1,7 @@
{ {
"private": true, "private": true,
"name": "@flarum/markdown", "name": "@flarum/markdown",
"prettier": "@flarum/prettier-config",
"dependencies": { "dependencies": {
"flarum-webpack-config": "^1.0.0", "flarum-webpack-config": "^1.0.0",
"webpack": "^4.46.0", "webpack": "^4.46.0",
@ -8,7 +9,13 @@
}, },
"scripts": { "scripts": {
"dev": "webpack --mode development --watch", "dev": "webpack --mode development --watch",
"build": "webpack --mode production" "build": "webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src"
}, },
"packageManager": "yarn@3.1.1" "packageManager": "yarn@3.1.1",
"devDependencies": {
"@flarum/prettier-config": "^1.0.0",
"prettier": "^2.5.1"
}
} }

View File

@ -2,8 +2,6 @@ import Component from 'flarum/common/Component';
export default class MarkdownToolbar extends Component { export default class MarkdownToolbar extends Component {
view(vnode) { view(vnode) {
return <div class="MarkdownToolbar"> return <div class="MarkdownToolbar">{vnode.children}</div>;
{vnode.children}
</div>;
} }
} }

View File

@ -18,33 +18,33 @@ import MarkdownButton from './components/MarkdownButton';
const modifierKey = navigator.userAgent.match(/Macintosh/) ? '⌘' : 'ctrl'; const modifierKey = navigator.userAgent.match(/Macintosh/) ? '⌘' : 'ctrl';
const styles = { const styles = {
'header': { prefix: '### ' }, header: { prefix: '### ' },
'bold': { prefix: '**', suffix: '**', trimFirst: true }, bold: { prefix: '**', suffix: '**', trimFirst: true },
'italic': { prefix: '_', suffix: '_', trimFirst: true }, italic: { prefix: '_', suffix: '_', trimFirst: true },
'strikethrough': { prefix: '~~', suffix: '~~', trimFirst: true }, strikethrough: { prefix: '~~', suffix: '~~', trimFirst: true },
'quote': { prefix: '> ', multiline: true, surroundWithNewlines: true }, quote: { prefix: '> ', multiline: true, surroundWithNewlines: true },
'code': { prefix: '`', suffix: '`', blockPrefix: '```', blockSuffix: '```' }, code: { prefix: '`', suffix: '`', blockPrefix: '```', blockSuffix: '```' },
'link': { prefix: '[', suffix: '](https://)', replaceNext: 'https://', scanFor: 'https?://' }, link: { prefix: '[', suffix: '](https://)', replaceNext: 'https://', scanFor: 'https?://' },
'image': { prefix: '![', suffix: '](https://)', replaceNext: 'https://', scanFor: 'https?://' }, image: { prefix: '![', suffix: '](https://)', replaceNext: 'https://', scanFor: 'https?://' },
'unordered_list': { prefix: '- ', multiline: true, surroundWithNewlines: true }, unordered_list: { prefix: '- ', multiline: true, surroundWithNewlines: true },
'ordered_list': { prefix: '1. ', multiline: true, orderedList: true }, ordered_list: { prefix: '1. ', multiline: true, orderedList: true },
'spoiler': { prefix: '>!', suffix: '!<', blockPrefix: '>! ', multiline: true, trimFirst: true } spoiler: { prefix: '>!', suffix: '!<', blockPrefix: '>! ', multiline: true, trimFirst: true },
} };
const applyStyle = (id) => { const applyStyle = (id) => {
// This is a nasty hack that breaks encapsulation of the editor. // This is a nasty hack that breaks encapsulation of the editor.
// In future releases, we'll need to tweak the editor driver interface // In future releases, we'll need to tweak the editor driver interface
// to support triggering events like this. // to support triggering events like this.
styleSelectedText(app.composer.editor.el, styles[id]); styleSelectedText(app.composer.editor.el, styles[id]);
} };
function makeShortcut(id, key) { function makeShortcut(id, key) {
return function (e) { return function (e) {
if (e.key === key && (e.metaKey && modifierKey === '⌘' || e.ctrlKey && modifierKey === 'ctrl')) { if (e.key === key && ((e.metaKey && modifierKey === '⌘') || (e.ctrlKey && modifierKey === 'ctrl'))) {
e.preventDefault(); e.preventDefault();
applyStyle(id); applyStyle(id);
} }
} };
} }
app.initializers.add('flarum-markdown', function (app) { app.initializers.add('flarum-markdown', function (app) {
@ -60,14 +60,15 @@ app.initializers.add('flarum-markdown', function (app) {
const makeApplyStyle = (id) => { const makeApplyStyle = (id) => {
return () => applyStyle(id); return () => applyStyle(id);
} };
items.add('markdown', ( items.add(
<MarkdownToolbar for={this.textareaId} setShortcutHandler={handler => shortcutHandler = handler}> 'markdown',
<MarkdownToolbar for={this.textareaId} setShortcutHandler={(handler) => (shortcutHandler = handler)}>
<MarkdownButton title={tooltip('header')} icon="fas fa-heading" onclick={makeApplyStyle('header')} /> <MarkdownButton title={tooltip('header')} icon="fas fa-heading" onclick={makeApplyStyle('header')} />
<MarkdownButton title={tooltip('bold', 'b')} icon="fas fa-bold" onclick={makeApplyStyle('bold')} /> <MarkdownButton title={tooltip('bold', 'b')} icon="fas fa-bold" onclick={makeApplyStyle('bold')} />
<MarkdownButton title={tooltip('italic', 'i')} icon="fas fa-italic" onclick={makeApplyStyle('italic')} /> <MarkdownButton title={tooltip('italic', 'i')} icon="fas fa-italic" onclick={makeApplyStyle('italic')} />
<MarkdownButton title={tooltip('strikethrough')} icon="fas fa-strikethrough" onclick={makeApplyStyle('strikethrough')} /> <MarkdownButton title={tooltip('strikethrough')} icon="fas fa-strikethrough" onclick={makeApplyStyle('strikethrough')} />
<MarkdownButton title={tooltip('quote')} icon="fas fa-quote-left" onclick={makeApplyStyle('quote')} /> <MarkdownButton title={tooltip('quote')} icon="fas fa-quote-left" onclick={makeApplyStyle('quote')} />
<MarkdownButton title={tooltip('spoiler')} icon="fas fa-exclamation-triangle" onclick={makeApplyStyle('spoiler')} /> <MarkdownButton title={tooltip('spoiler')} icon="fas fa-exclamation-triangle" onclick={makeApplyStyle('spoiler')} />
<MarkdownButton title={tooltip('code')} icon="fas fa-code" onclick={makeApplyStyle('code')} /> <MarkdownButton title={tooltip('code')} icon="fas fa-code" onclick={makeApplyStyle('code')} />
@ -75,7 +76,8 @@ app.initializers.add('flarum-markdown', function (app) {
<MarkdownButton title={tooltip('image')} icon="fas fa-image" onclick={makeApplyStyle('image')} /> <MarkdownButton title={tooltip('image')} icon="fas fa-image" onclick={makeApplyStyle('image')} />
<MarkdownButton title={tooltip('unordered_list')} icon="fas fa-list-ul" onclick={makeApplyStyle('unordered_list')} /> <MarkdownButton title={tooltip('unordered_list')} icon="fas fa-list-ul" onclick={makeApplyStyle('unordered_list')} />
<MarkdownButton title={tooltip('ordered_list')} icon="fas fa-list-ol" onclick={makeApplyStyle('ordered_list')} /> <MarkdownButton title={tooltip('ordered_list')} icon="fas fa-list-ol" onclick={makeApplyStyle('ordered_list')} />
</MarkdownToolbar> </MarkdownToolbar>,
), 100); 100
);
}); });
}); });

View File

@ -1381,12 +1381,21 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@flarum/markdown@workspace:." resolution: "@flarum/markdown@workspace:."
dependencies: dependencies:
"@flarum/prettier-config": ^1.0.0
flarum-webpack-config: ^1.0.0 flarum-webpack-config: ^1.0.0
prettier: ^2.5.1
webpack: ^4.46.0 webpack: ^4.46.0
webpack-cli: ^4.9.1 webpack-cli: ^4.9.1
languageName: unknown languageName: unknown
linkType: soft linkType: soft
"@flarum/prettier-config@npm:^1.0.0":
version: 1.0.0
resolution: "@flarum/prettier-config@npm:1.0.0"
checksum: 2035b97dcd02f2ebcb9f0f88111adbf176fbb31132c4e0a2a5387cec14619ef0f8ac3418c14a0730de1d14765b2bc7c53aa3eea6b28949da93ceb3c1c229195a
languageName: node
linkType: hard
"@gar/promisify@npm:^1.0.1": "@gar/promisify@npm:^1.0.1":
version: 1.1.2 version: 1.1.2
resolution: "@gar/promisify@npm:1.1.2" resolution: "@gar/promisify@npm:1.1.2"
@ -4753,6 +4762,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"prettier@npm:^2.5.1":
version: 2.5.1
resolution: "prettier@npm:2.5.1"
bin:
prettier: bin-prettier.js
checksum: 21b9408476ea1c544b0e45d51ceb94a84789ff92095abb710942d780c862d0daebdb29972d47f6b4d0f7ebbfb0ffbf56cc2cfa3e3e9d1cca54864af185b15b66
languageName: node
linkType: hard
"process-nextick-args@npm:~2.0.0": "process-nextick-args@npm:~2.0.0":
version: 2.0.1 version: 2.0.1
resolution: "process-nextick-args@npm:2.0.1" resolution: "process-nextick-args@npm:2.0.1"

View File

@ -23,4 +23,3 @@ span.spoiler {
visibility: hidden; visibility: hidden;
} }
} }