Skip to content
Snippets Groups Projects
Commit a70ff9eb authored by chris's avatar chris
Browse files

LinkService

parent 00744342
No related branches found
No related tags found
1 merge request!45Develop
import { toggleMark } from "prosemirror-commands";
import { markActive } from "../../lib/Utils";
import Tools from "../../lib/Tools";
import { injectable } from "inversify";
import { icons } from "wax-prosemirror-components";
@injectable()
export default class Code extends Tools {
title = "Toggle code";
content = icons.code;
get run() {
return (state, dispatch) => {
toggleMark(state.config.schema.marks.code)(state, dispatch);
};
}
get active() {
return state => {
return markActive(state.config.schema.marks.code)(state);
};
}
}
import { toggleMark } from "prosemirror-commands";
import { markActive } from "../../lib/Utils";
import Tools from "../../lib/Tools";
import { injectable } from "inversify";
import { icons } from "wax-prosemirror-components";
@injectable()
export default class Strong extends Tools {
title = "Toggle strong";
content = icons.strong;
get run() {
return (state, dispatch) => {
toggleMark(state.config.schema.marks.strong)(state, dispatch);
};
}
get active() {
return state => {
return markActive(state.config.schema.marks.strong)(state);
};
}
}
export { default as Blockquote } from "./Blockquote";
export { default as Em } from "./Em";
// export { default as Code } from "./Code";
export { default as Link } from "./Link";
// export { default as Link } from "./Link";
export { default as SmallCaps } from "./SmallCaps";
export { default as StrikeThrough } from "./StrikeThrough";
// export { default as Strong } from "./Strong";
......
import Service from "wax-prosemirror-core/src/services/Service";
import { linkMark } from "wax-prosemirror-schema";
import Link from "./Link";
class LinkService extends Service {
boot() {
const createMark = this.container.get("CreateMark");
createMark({ link: linkMark });
}
register() {
this.container.bind("Link").to(Link);
}
}
export default LinkService;
import CodeService from "./CodeService/CodeService";
import StrongService from "./StrongService/StrongService";
export default [new CodeService(), new StrongService()];
import LinkService from "./LinkService/LinkService";
export default [new CodeService(), new StrongService(), new LinkService()];
......@@ -3,3 +3,4 @@ export { default as EditoriaSchema } from "./src/editoria/EditoriaSchema";
export { default as XpubSchema } from "./src/XpubSchema";
export { default as codeMark } from "./src/marks/codeMark";
export { default as strongMark } from "./src/marks/strongMark";
export { default as linkMark } from "./src/marks/linkMark";
......@@ -3,32 +3,32 @@ const emDOM = ["em", 0],
codeDOM = ["code", 0];
const marks = {
link: {
attrs: {
href: { default: null },
rel: { default: "" },
target: { default: "blank" },
title: { default: null }
},
inclusive: false,
parseDOM: [
{
tag: "a[href]",
getAttrs: dom => {
const href = dom.getAttribute("href");
const target = href && href.indexOf("#") === 0 ? "" : "blank";
return {
href: dom.getAttribute("href"),
title: dom.getAttribute("title"),
target
};
}
}
],
toDOM(node) {
return ["a", node.attrs, 0];
}
},
// link: {
// attrs: {
// href: { default: null },
// rel: { default: "" },
// target: { default: "blank" },
// title: { default: null }
// },
// inclusive: false,
// parseDOM: [
// {
// tag: "a[href]",
// getAttrs: dom => {
// const href = dom.getAttribute("href");
// const target = href && href.indexOf("#") === 0 ? "" : "blank";
// return {
// href: dom.getAttribute("href"),
// title: dom.getAttribute("title"),
// target
// };
// }
// }
// ],
// toDOM(node) {
// return ["a", node.attrs, 0];
// }
// },
em: {
parseDOM: [{ tag: "i" }, { tag: "em" }, { style: "font-style=italic" }],
toDOM() {
......
const link = {
attrs: {
href: { default: null },
rel: { default: "" },
target: { default: "blank" },
title: { default: null }
},
inclusive: false,
parseDOM: [
{
tag: "a[href]",
getAttrs: dom => {
const href = dom.getAttribute("href");
const target = href && href.indexOf("#") === 0 ? "" : "blank";
return {
href: dom.getAttribute("href"),
title: dom.getAttribute("title"),
target
};
}
}
],
toDOM(hook, next, node) {
hook.value = ["a", node.attrs, 0];
next();
}
};
export default link;
......@@ -15,3 +15,5 @@ const strong = {
next();
}
};
export default strong;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment