FEATURE: Add base62 sha1 to cooked data attribute

* FEATURE: Add base62 sha1 to data attribute in `Post#cooked`.

* FIX: Use `Upload#short_url` when quoting an image.
This commit is contained in:
Guo Xiang Tan
2019-06-11 09:15:45 +08:00
committed by Sam
parent bd538f7437
commit 06d974d55c
6 changed files with 27 additions and 8 deletions

View File

@@ -45,6 +45,7 @@ function rule(state) {
case "img":
if (mapped) {
token.attrs[srcIndex][1] = mapped.url;
token.attrs.push(["data-base62-sha1", mapped.base62_sha1]);
} else {
token.attrs[srcIndex][1] = state.md.options.discourse.getURL(
"/images/transparent.png"
@@ -73,7 +74,12 @@ function rule(state) {
export function setup(helper) {
const opts = helper.getOptions();
if (opts.previewing) helper.whiteList(["img.resizable"]);
helper.whiteList(["img[data-orig-src]", "a[data-orig-href]"]);
helper.whiteList([
"img[data-orig-src]",
"img[data-base62-sha1]",
"a[data-orig-href]"
]);
helper.registerPlugin(md => {
md.core.ruler.push("upload-protocol", rule);