rangy
rangy copied to clipboard
not working with npm and es6 import
I installed the rangy
by
Still could not find the module by import rangy from 'rangy';
Given the files seems installed.
.//node_modules/rangy
.//node_modules/rangy/lib/rangy-classapplier.js
.//node_modules/rangy/lib/rangy-core.js
.//node_modules/rangy/lib/rangy-highlighter.js
.//node_modules/rangy/lib/rangy-selectionsaverestore.js
.//node_modules/rangy/lib/rangy-serializer.js
.//node_modules/rangy/lib/rangy-textrange.js
+1 same problem here
Try something like this
import rangy from 'rangy/lib/rangy-core.js';
import rangyHighlight from 'rangy/lib/rangy-highlighter';
import rangyClassApplier from 'rangy/lib/rangy-classapplier';
import rangyTextRange from 'rangy/lib/rangy-textrange';
import rangySerializer from 'rangy/lib/rangy-serializer';
I found this syntax to be better:
import rangy from "rangy/lib/rangy-core.js"; import "rangy/lib/rangy-highlighter"; import "rangy/lib/rangy-classapplier"; import "rangy/lib/rangy-textrange"; import "rangy/lib/rangy-serializer";
..as then you can just use the rangy object for everything.
@John-Williams @LeCoupa
I still get undefined
for rangy. Are either of you using webpack or babel by chance?
@nicholascloud I used the code from @John-Williams on a webpack setup and it all worked fine
import rangy from 'rangy'
import 'rangy/lib/rangy-classapplier'
import 'rangy/lib/rangy-highlighter'
function highlightSelection (userSelection) {
rangy.init()
let highlighter = rangy.createHighlighter()
highlighter.addClassApplier(rangy.createClassApplier('mark', {
ignoreWhiteSpace: true,
tagNames: ['span', 'a']
}))
highlighter.highlightSelection('mark')
}
let selection = window.getSelection()
let rangeRepresentation = highlightSelection (selection.getRangeAt(0))
This wraps whatever the user has highlighted in a span with class mark
Can anyone please help me import this under node_modules? I'm not able to find any example to use browserified rangy for firefox extension
don't forget import 'rangy/lib/rangy-selectionsaverestore';
import rangy from "rangy/lib/rangy-core.js";
import "rangy/lib/rangy-highlighter";
import "rangy/lib/rangy-classapplier";
import "rangy/lib/rangy-textrange";
import "rangy/lib/rangy-serializer";
import 'rangy/lib/rangy-selectionsaverestore';