Bhargava 6063bd1724 Help Project:
1. Initial Commit - a boiler plate code and POC to realize the concept of context
sensitive help
2. Frontend code written in ReactJS
3. Backend code written in Java, Spring Boot Framework
4. Frontend Start:
        pre-requisites : node, npm
	npm run dev  ==> to start the frontend vite server
5. Backend Start:
	pre-requisites : java, mvn
        mvn spring-boot:run  ==> to start the backend server
6. Visit http://localhost:5173/ for basic demo of help, press F1 in textboxes
7. Visit http://localhost:5173/editor and enter "admin123" to add/modify texts.

Happy Coding !!!

Thank you,
Bhargava.
2025-07-04 15:54:13 +05:30

43 lines
1.1 KiB
JavaScript

import Inline from '../blots/inline';
class Link extends Inline {
static create(value) {
let node = super.create(value);
value = this.sanitize(value);
node.setAttribute('href', value);
node.setAttribute('rel', 'noopener noreferrer');
node.setAttribute('target', '_blank');
return node;
}
static formats(domNode) {
return domNode.getAttribute('href');
}
static sanitize(url) {
return sanitize(url, this.PROTOCOL_WHITELIST) ? url : this.SANITIZED_URL;
}
format(name, value) {
if (name !== this.statics.blotName || !value) return super.format(name, value);
value = this.constructor.sanitize(value);
this.domNode.setAttribute('href', value);
}
}
Link.blotName = 'link';
Link.tagName = 'A';
Link.SANITIZED_URL = 'about:blank';
Link.PROTOCOL_WHITELIST = ['http', 'https', 'mailto', 'tel'];
function sanitize(url, protocols) {
let anchor = document.createElement('a');
anchor.href = url;
let protocol = anchor.href.slice(0, anchor.href.indexOf(':'));
return protocols.indexOf(protocol) > -1;
}
export { Link as default, sanitize };