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)
### Added
- Spoiler and strikethrough buttons (https://github.com/flarum/markdown/pulls/30)
### Fixed
- 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)
### Fixed
- 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)
### Changed
- Compatibility with Flarum v1.0.0.
- 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)
### Fixed
- Toolbar buttons submits the form
- Tooltips generate a deprecation warning
### Removed
- 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)
### Added
- 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)
### Added
- Editor Driver support ([ba3e1fb](https://github.com/flarum/markdown/commit/ba3e1fb528ce7e85bde27753f6c1cce3b03fe9d3))
### Changed
- 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)
### Fixed
- 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)
### Changed
- 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)
### Changed
- Switch image and link defaults (#11)
- Updated mithril to version 2
- Load language strings correctly on en-/disable
### Removed
- 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)
### Changed
- Updated JS dependencies
### Fixed
- 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)
### Fixed
- 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)
### Added
- The toolbar now has an image button (#8)
### Fixed
- Unusable toolbar in IE11 (#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)
### 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))

View File

@ -1,39 +1,41 @@
{
"name": "flarum/markdown",
"description": "Allow posts to be formatted with Markdown.",
"type": "flarum-extension",
"keywords": ["formatting"],
"license": "MIT",
"support": {
"issues": "https://github.com/flarum/core/issues",
"source": "https://github.com/flarum/markdown",
"forum": "https://discuss.flarum.org"
},
"homepage": "https://flarum.org",
"funding": [
{
"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"
}
}
"name": "flarum/markdown",
"description": "Allow posts to be formatted with Markdown.",
"type": "flarum-extension",
"keywords": [
"formatting"
],
"license": "MIT",
"support": {
"issues": "https://github.com/flarum/core/issues",
"source": "https://github.com/flarum/markdown",
"forum": "https://discuss.flarum.org"
},
"homepage": "https://flarum.org",
"funding": [
{
"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"
}
}
}
}

View File

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

View File

@ -1,6 +1,7 @@
{
"private": true,
"name": "@flarum/markdown",
"prettier": "@flarum/prettier-config",
"dependencies": {
"flarum-webpack-config": "^1.0.0",
"webpack": "^4.46.0",
@ -8,7 +9,13 @@
},
"scripts": {
"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 {
view(vnode) {
return <div class="MarkdownToolbar">
{vnode.children}
</div>;
return <div class="MarkdownToolbar">{vnode.children}</div>;
}
}

View File

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

View File

@ -1381,12 +1381,21 @@ __metadata:
version: 0.0.0-use.local
resolution: "@flarum/markdown@workspace:."
dependencies:
"@flarum/prettier-config": ^1.0.0
flarum-webpack-config: ^1.0.0
prettier: ^2.5.1
webpack: ^4.46.0
webpack-cli: ^4.9.1
languageName: unknown
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":
version: 1.1.2
resolution: "@gar/promisify@npm:1.1.2"
@ -4753,6 +4762,15 @@ __metadata:
languageName: node
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":
version: 2.0.1
resolution: "process-nextick-args@npm:2.0.1"

View File

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