DEV: Extend plugin API for uploads (#8440)

* DEV: Add API to alter uploads Markdown

* DEV: Extract data attributes from image / download Markdown

For example '[test|attachment|hello=world]' will generate an 'a' element
with a data attribute: 'data-hello=world'.

This commit also makes MarkdownIt to transform '|attachment' into
'class="attachment"'. This transformation used to be a part of the
process which resolves short URLs (i.e. upload://).

* DEV: Export imageNameFromFileName
This commit is contained in:
Dan Ungureanu
2019-12-09 16:20:03 +02:00
committed by GitHub
parent ebe6fa95be
commit aa24be1a9a
8 changed files with 118 additions and 64 deletions

View File

@ -7,6 +7,7 @@ import {
applyCachedInlineOnebox,
deleteCachedInlineOnebox
} from "pretty-text/inline-oneboxer";
import { extractDataAttribute } from "pretty-text/engines/discourse-markdown-it";
QUnit.module("lib:pretty-text");
@ -1365,3 +1366,11 @@ QUnit.test("emoji - emojiSet", assert => {
`<p><img src="/images/emoji/twitter/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`
);
});
QUnit.test("extractDataAttribute", assert => {
assert.deepEqual(extractDataAttribute("foo="), ["data-foo", ""]);
assert.deepEqual(extractDataAttribute("foo=bar"), ["data-foo", "bar"]);
assert.notOk(extractDataAttribute("foo?=bar"));
assert.notOk(extractDataAttribute("https://discourse.org/?q=hello"));
});