Append field with anchor to any block.
- Editor.js v2.20+
Get the package
$ npm i editorjs-anchor
Include module at your application
import AnchorTune from 'editorjs-anchor';
You can load a specific version of the package from jsDelivr CDN.
Require this script on a page with Editor.js.
<script src="https://cdn.jsdelivr.net/npm/editorjs-anchor"></script>
- Upload folder
dist
from repository - Add
dist/bundle.js
file to your page.
var editor = EditorJS({
// ...
tools: {
// ...
anchorTune: AnchorTune
},
tunes: ['anchorTune']
// ...
});
var editor = EditorJS({
// ...
tools: {
// ...
anchorTune: AnchorTune,
header: {
class: Header,
tunes: ['anchorTune']
}
}
// ...
});
You can add a localized string
new Editorjs({
// ...
tools: {
anchorTune: AnchorTune
},
i18n: {
tools: {
anchorTune: {
'Anchor': 'Якорь'
}
}
},
})
Example for Header block
{
"type": "header",
"data": {
"text": "Header",
"level": 2
},
"tunes": {
"anchorTune": {
"anchor": "header-anchor"
}
}
}
If the anchor field is empty, then the tune data will not be serialized into JSON.