More fixes related to #363
This commit is contained in:
@@ -16,7 +16,7 @@ import { fencedCodePlugin } from "./fenced_code.ts";
|
||||
|
||||
export function cleanModePlugins(editor: Client) {
|
||||
return [
|
||||
linkPlugin(),
|
||||
linkPlugin(editor),
|
||||
directivePlugin(),
|
||||
blockquotePlugin(),
|
||||
admonitionPlugin(editor),
|
||||
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
import { decoratorStateField } from "./util.ts";
|
||||
|
||||
import type { Client } from "../client.ts";
|
||||
import { resolvePath } from "$sb/lib/resolve.ts";
|
||||
import { folderName, resolve } from "../../common/path.ts";
|
||||
import { resolveAttachmentPath, resolvePath } from "$sb/lib/resolve.ts";
|
||||
|
||||
class InlineImageWidget extends WidgetType {
|
||||
constructor(
|
||||
@@ -77,11 +76,8 @@ export function inlineImagesPlugin(client: Client) {
|
||||
let url = imageRexexResult.groups.url;
|
||||
const title = imageRexexResult.groups.title;
|
||||
|
||||
const currentPage = client.currentPage!;
|
||||
const currentFolder = folderName(currentPage);
|
||||
|
||||
if (url.indexOf("://") === -1 && !url.startsWith("/")) {
|
||||
url = resolve(currentFolder, decodeURI(url));
|
||||
url = resolveAttachmentPath(client.currentPage!, decodeURI(url));
|
||||
}
|
||||
widgets.push(
|
||||
Decoration.widget({
|
||||
|
||||
+11
-2
@@ -1,3 +1,5 @@
|
||||
import { resolveAttachmentPath } from "$sb/lib/resolve.ts";
|
||||
import { Client } from "../client.ts";
|
||||
import { Decoration, syntaxTree } from "../deps.ts";
|
||||
import {
|
||||
decoratorStateField,
|
||||
@@ -5,7 +7,7 @@ import {
|
||||
isCursorInRange,
|
||||
} from "./util.ts";
|
||||
|
||||
export function linkPlugin() {
|
||||
export function linkPlugin(client: Client) {
|
||||
return decoratorStateField((state) => {
|
||||
const widgets: any[] = [];
|
||||
|
||||
@@ -31,7 +33,14 @@ export function linkPlugin() {
|
||||
return;
|
||||
}
|
||||
const cleanAnchor = anchorPart.substring(1); // cut off the initial [
|
||||
const cleanLink = linkPart.substring(0, linkPart.length - 1); // cut off the final )
|
||||
let cleanLink = linkPart.substring(0, linkPart.length - 1); // cut off the final )
|
||||
|
||||
if (!cleanLink.includes("://")) {
|
||||
cleanLink = resolveAttachmentPath(
|
||||
client.currentPage!,
|
||||
decodeURI(cleanLink),
|
||||
);
|
||||
}
|
||||
|
||||
// Hide the start [
|
||||
widgets.push(
|
||||
|
||||
@@ -9,8 +9,7 @@ import { renderMarkdownToHtml } from "../../plugs/markdown/markdown_render.ts";
|
||||
import { ParseTree } from "$sb/lib/tree.ts";
|
||||
import { lezerToParseTree } from "../../common/markdown_parser/parse_tree.ts";
|
||||
import type { Client } from "../client.ts";
|
||||
import { resolvePath } from "$sb/lib/resolve.ts";
|
||||
import { folderName, resolve } from "../../common/path.ts";
|
||||
import { resolveAttachmentPath } from "$sb/lib/resolve.ts";
|
||||
|
||||
class TableViewWidget extends WidgetType {
|
||||
constructor(
|
||||
@@ -39,14 +38,9 @@ class TableViewWidget extends WidgetType {
|
||||
// Annotate every element with its position so we can use it to put
|
||||
// the cursor there when the user clicks on the table.
|
||||
annotationPositions: true,
|
||||
translateUrls: (url, type) => {
|
||||
translateUrls: (url) => {
|
||||
if (!url.includes("://")) {
|
||||
if (type === "image" && !url.startsWith("/")) {
|
||||
// Make relative to current folder
|
||||
url = resolve(folderName(this.editor.currentPage!), decodeURI(url));
|
||||
} else if (type === "link") { // link
|
||||
url = resolvePath(this.editor.currentPage!, decodeURI(url), true);
|
||||
}
|
||||
url = resolveAttachmentPath(this.editor.currentPage!, decodeURI(url));
|
||||
}
|
||||
|
||||
return url;
|
||||
|
||||
Reference in New Issue
Block a user