gitbookio / slate-edit-code Goto Github PK
View Code? Open in Web Editor NEWA Slate plugin for code block editing
Home Page: https://gitbookio.github.io/slate-edit-code/
License: Apache License 2.0
A Slate plugin for code block editing
Home Page: https://gitbookio.github.io/slate-edit-code/
License: Apache License 2.0
Don't work in local development, try to reproduce in an online environment but there is another bug.
https://stackblitz.com/edit/react-fh7kbo?file=index.js
It seems like in the latest version 0.13.2
there are not multiple code line blocks created in the editor, all of the code is put on a single block (in this case my lineType
option is set to code-line
) with newline characters ignored:
{
"kind": "block",
"type": "code",
"isVoid": false,
"data": {},
"nodes": [
{
"kind": "block",
"type": "code-line",
"isVoid": false,
"data": {},
"nodes": [
{
"kind": "text",
"leaves": [
{
"kind": "leaf",
"text": "type\ndescription\nname\n\nonDocumentCreate(document, settings, actor) {\n\n}\n\nonDocumentDelete() {\n\n}\n\nonCollectionCreate() {\n\n}",
"marks": []
}
]
}
]
}
]
}
When pressing backspace, sometimes the change is not reflected directly in Slate (even when nothing is done by the plugin: default behaviour).
It may be a bug in Slate.
Hi folks, thank you as always for the plugin! I was wondering if the toggle
and wrap
functions should take an optional data
to be able to pass in things like syntax (and thus allowing easier interoperability with slate-prism
).
My personal usecase is Github style markdown of three ~~~/``` followed by the language name. Using regex, I can capture the syntax proposed but can't use the wrap
or `toggle` functions to set the code block.
The other alternative would be to do an insertBlock
but since the wrap
& toggle
seem to be exposed utilities, it felt 'safer' to use those.
Thoughts?
An example should be published to GH Pages to showcase the plugin.
Hi,
Is it possible to add line numbers with this plugin?
Thanks.
I tested this in the example provided. This behavior was lost in the newest version.
What exactly do you have to do to insert a slate-edit-code block once this is installed and added as a plugin?
I assume it's not all blocks by default. If it is, tab behavior is not working properly (tab loses focus)
At first I thought it was weird wording as in "the Coding Edition of Slate", but I think it should be "editing"
And the description should use the singular of block, so "A Slate plugin to handle code block editing"
When I select a few paragraphs and toggleCodeBlock it only turns the first selected paragraph to code_block.
Expected behaviour would be all selected paragraph
s turned into code_block
.
This probably has something to do with the lines refactor: #10. The more basic Slate code-highlighting example does not have this issue: http://slatejs.org/#/code-highlighting
var line1;
var line2;
Hey, currently there is a default indentation defined as a const. Could you please maybe make it configurable via the options or export a function to set default indents?
When pressing Cmd-A or Ctrl-A, it select the whole text in the editor, if the cursor is in a code block, it should select only the code block.
Previously this functionality worked fine but with the upgrade to 0.13.2
and slate 0.30.X
if there are multiple code blocks in a document only the first one is displayed, the text content from subsequent blocks disappears.
This bug disappears when commenting out the slate-edit-code
plugin.
Just a note that the current version is not compatible with slate 0.15. The library expects Slate 0.14.
In case it was just a versioning issue, I tried changing the peer dependencies but I got this error:
Uncaught TypeError: rule.match is not a function(…)
I haven't investigated too much. Just wanted to give you a heads up.
Sunny
If you highlight a line and paste over it, it works perfectly.
If you highlight 2 or more lines and paste over them with text from anywhere besides the nodes you are pasting over, you'll get Uncaught Error: Could not find a node with key "###"
If you copy identical text or non-HTML (plaintext) over the nodes, it generally seems to work.
If you use Ctrl+A to select all contents of the codebox and paste, it seems to fail universally, even if you paste plaintext.
Slate made some changes to its core in version 0.22.0, which breaks this plugin. A good summary of the things that'll need updating can be seen here:
ianstormtaylor/slate#836.
Focus of editing is lost when pressing tab even if we force Slate to focus after the transformation: https://github.com/SamyPesse/slate-edit-code/blob/master/lib/onTab.js#L20
It may be related to the event being propagated to the document
or window
. Maybe calling event.stopPropagation()
will solve the issue.
A nice feature to add would be to wrap the expanded selection with {
or [
(depending on on the key pressed). Every time I'm writing on an online code editor, I'm missing it
Hi @Soreine @SamyPesse! Great plugin, and thank you as always for putting it out there!
On the lines of #5, another enhancement could be wrapping the expanded selection if the quote or double quotes is pressed.
Possible undefined text here
https://github.com/GitbookIO/slate-edit-code/blob/0.15.7/lib/handlers/onPaste.js#L34
When user is pressing Shift + Tab, it should reduce indent at the beginning for selected lines.
Can anyone let me know what the expected input for the function is? I tried passing just a string value of
(two spaces) but that didn't have any effect.
Using Ctrl+A
selects all contents in Slate now, rather than just the codeblock content.
The docs don't make this clear, but if I used Prism.js markup to render the code_block
block, will the indentation behavior work?
Right now in the schema it validates that there is only a single text node in code blocks, and it handles the non-text node case well, but if there are two text nodes in a code block then there's an infinite loop, since it doesn't handle that case by joining them.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.