Skip to content

Commit

Permalink
feature(bbcode-dataprocessor): Fix & enable Hyperlink Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pkliesch committed Aug 24, 2023
1 parent 91a1ca1 commit 10006f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { boldRule } from "./Bold";
import { italicRule } from "./Italic";
import { underlineRule } from "./Underline";
import { hyperlinkRule } from "./Hyperlink";

export interface HTML2BBCodeRule {
id: string;
toData: (node: Node, content: string) => string | undefined;
}

export const defaultRules: HTML2BBCodeRule[] = [boldRule, italicRule, underlineRule];
export const defaultRules: HTML2BBCodeRule[] = [boldRule, italicRule, underlineRule, hyperlinkRule];
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { HTML2BBCodeRule } from "./DefaultRules";
import { isElement } from "@coremedia/ckeditor5-dom-support";

export const hyperlinkRule: HTML2BBCodeRule = {
id: "Hyperlink",
toData: (node, content: string) => {
if (!isHyperlink(node)) {
return undefined;
}
return `[url]${content}[/url]`;
if (!isElement(node)) {
return `[url]${content}[/url]`;
}
const href = node.getAttribute("href");
return `[url=${href}]${content}[/url]`;
},
};

Expand Down

0 comments on commit 10006f5

Please sign in to comment.