![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@wikifactory/slate-edit-code
Advanced tools
A Slate plugin to handle code block editing.
npm install @wikifactory/slate-edit-code
Mod means Ctrl on Windows/Linux and Command on Mac.
This plugin uses the following structure for code blocks:
<code_block>
<code_line>A code block is made of</code_line>
<code_line>several code lines</code_line>
</code_block>
Texts inside code_blocks
that contain newlines \n
are automatically split into the appropriate number of code_lines
.
import EditCode from 'slate-edit-code'
const plugins = [
EditCode()
]
containerType = 'code_block' : string
— The type of the code containerslineType = 'code_line' : string
— The type of the code linesexitBlockType = 'paragraph' : null | string
— Mod+Enter will exit the code container, into the given block type. Backspace at start of an empty code container will convert it to the given block type. Pass null
to disable this behavior.onExit: (Editor) => void | Editor
— Change to do when the user hits Mod+Enter. Defaults to exiting the code block, into a new exitBlockType
block.selectAll = true : boolean
— True to select all code inside a code container on Mod+AallowMarks = false : boolean
— False disallow marks in code blocks by normalizing them away.getIndent: (Value) => string
— Returns the indent unit as a string. The current value is passed as context.Some behavior implemented by this plugins have no corresponding option. While there is an option selectAll
to disable the behavior on Mod+A
, If you would like to fine tune these behavior, you can always redefine the exported onKeyDown
function.
The following example disable all indent behavior
import EditCode from '@wikifactory/slate-edit-code'
const options = { ... };
const basePlugin = EditCode(options);
const customPlugin = {
...basePlugin,
onKeyDown(event, editor, next) {
if (event.key === 'Tab') {
// Bypass the original plugin behavior on `Tab`
return ...;
} else {
return basePlugin.onKeyDown(event, editor, next);
}
}
}
// Use customPlugin later on
@wikifactory/slate-edit-code
exports utilities, accessible like so:
const plugin = EditCode()
// Access exported utilities there
plugin.utils
utils.deserializeCode
plugin.utils.deserializeCode(text: String) => Block
Split a text string into lines, and deserialize them to a code_container
Block
, with one children code_line
Block
per line.
changes.toggleCodeBlock
plugin.changes.toggleCodeBlock(editor: Editor, type: String) => Editor
Toggle a block into a code block or a normal block (defined by type
).
changes.wrapCodeBlockByKey
plugin.changes.wrapCodeBlockByKey(editor: Editor, key: String) => Editor
Convert a block (paragraph, etc) into a code block.
changes.wrapCodeBlock
plugin.changes.wrapCodeBlock(editor: Editor) => Editor
Convert current block (paragraph, etc) into a code block.
changes.unwrapCodeBlockByKey
plugin.changes.unwrapCodeBlockByKey(editor: Editor, key: String, type: String) => Editor
Convert a code block into a normal block (paragraph, etc).
changes.unwrapCodeBlock
plugin.changes.unwrapCodeBlock(editor: Editor, type: String) => Editor
Convert current code block into a normal block (paragraph, etc).
FAQs
A Slate plugin to handle code blocks editing.
The npm package @wikifactory/slate-edit-code receives a total of 1,444 weekly downloads. As such, @wikifactory/slate-edit-code popularity was classified as popular.
We found that @wikifactory/slate-edit-code demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.