codemirror

adding syntax highlighting to Jupyter notebook cell magic

不羁岁月 提交于 2019-11-30 15:37:05
问题 I'm trying to figure out how to activate CodeMirror syntax highlighting for a CodeMirror-supported language (cypher) within a cell for a custom Jupyter cell magic ( %%mymagic ). The magic isn't associated with a special kernel - it just runs Python commands that process the string entered into the cell that I want to highlight. From what I can tell, this ostensibly can be done using something like from notebook.services.config.manager import ConfigManager cm = ConfigManager() cm.update(

Codemirror Auto Format after setValue

只愿长相守 提交于 2019-11-30 15:02:52
http://liveweave.com/UxEJ0s I'm using Codemirror for my app. I noticed if I select all the text and press SHIFT+Tab it will auto align my code making it easier to read. Here's an example of what my app currently renders... <ul> <li> <font color="#f90000"> Apples </font> </li> <li> <font color="#ff9a3d"> Oranges </font> </li> </ul> Here's what I'm trying to get it to render. <ul> <li> <font color="#f90000"> Apples </font> </li> <li> <font color="#ff9a3d"> Oranges </font> </li> </ul> EDIT : Does anyone know if there's a way to do this without selecting the whole code manually in Codemirror? Why?

How can I set the value of a CodeMirror editor using Javascript?

放肆的年华 提交于 2019-11-30 13:08:43
问题 I try to set id4 in the following code: <div id="id1"> <div id="id2"> <div id="id3"> <textarea id="id4"></textarea> </div> </div> </div> By using this code: document.getElementById('id4').value = "..."; And this: document.getElementById('id3').getElementsByTagName('textarea')[0].value = "..."; But nothing works. UPDATED: The textarea is replaced by CodeMirror editor. How do I set value to it? Thanks a lot for the help! 回答1: The way to do this has changed slightly since the release of 3.0. It

CodeMirror HTML mode not working

£可爱£侵袭症+ 提交于 2019-11-30 10:53:57
I'm trying to style code samples with CodeMirror, but it works partially - it applies the selected theme to the textarea but the syntax is not highlighted. There is my page: <textarea id="template-html" name="code" class="CodeMirror"> <!DOCTYPE html> <foobar> <blah>Enter your xml here and press the button below to display it as highlighted by the CodeMirror XML mode</blah> <tag2 foo="2" bar="bar" /> </foobar> </textarea> <link rel="stylesheet" type="text/css" href="/site.com/css/codemirror/codemirror.css"> <link rel="stylesheet" type="text/css" href="/site.com/css/codemirror/theme/ambiance.css

实现一个掘金Style的文章编辑器

房东的猫 提交于 2019-11-30 04:15:27
前言 我是一个掘金重度用户,不仅经常在掘金上挖掘含金量高的文章,偶尔还在掘金上创作技术文章。相信读者们也对掘金非常满意,尤其是它的文章编辑器,不仅支持Markdown编辑,而且还支持代码高亮、分屏预览、自动保存等等。本文将用React+CodeMirror+Showdown实现一个类似于掘金编辑器的单页应用。 动图效果 先不说那么多,先上动图效果吧。 布局 下面是掘金文章编辑器的布局。 可以看到,编辑器主要由5个部分组成: 顶部栏 左侧Markdown编辑器 左侧底部 右侧预览 右侧底部 我们首先需要做的是将各个位置摆放出来。 创建一个文件叫 Demo.tsx ,输入以下内容。(我们先不管怎么构建一个React+Typescript应用,这里只看逻辑) import React from 'react'; // 引入样式 import style from './Demo.scss'; const Demo: React.FC = () => { return ( <div className={style.articleEdit}> <div className={style.topBar}> 顶部栏 </div> <div className={style.main}> <div className={style.editor}> <div className={style

Inserting a new text at given cursor position

狂风中的少年 提交于 2019-11-30 01:34:23
问题 I am working on customizing the codemirror for my new language mode. As part of this new mode implementation, I am writing a new tool bar where user can select some text and say insert. This command should insert the text where user was typing just before clicking on tool bar. I could not find any API level support to do so. If there is any other way can someone help me out on this? Basically get the current cursor positio- line number and position at which cursor is currently present. May be

Get CodeMirror instance

家住魔仙堡 提交于 2019-11-29 22:19:01
I want to get an instance of CodeMirror (it is binded to a textarea '#code'). From an onclick-event I want to add a value to the current value of the CodeMirror instance. How can this be achieved? From the docs I can't seem to find anything to get an instance and bind it to a loca var in javascript. ashatte Another method I have found elsewhere is as follows: //Get a reference to the CodeMirror editor var editor = document.querySelector('.CodeMirror').CodeMirror; This works well when you are creating the CodeMirror instance dynamically or replacing an existing DOM element with a CodeMirror

Codemirror Auto Format after setValue

孤街浪徒 提交于 2019-11-29 20:36:53
问题 http://liveweave.com/UxEJ0s I'm using Codemirror for my app. I noticed if I select all the text and press SHIFT+Tab it will auto align my code making it easier to read. Here's an example of what my app currently renders... <ul> <li> <font color="#f90000"> Apples </font> </li> <li> <font color="#ff9a3d"> Oranges </font> </li> </ul> Here's what I'm trying to get it to render. <ul> <li> <font color="#f90000"> Apples </font> </li> <li> <font color="#ff9a3d"> Oranges </font> </li> </ul> EDIT :

CodeMirror HTML mode not working

放肆的年华 提交于 2019-11-29 16:11:41
问题 I'm trying to style code samples with CodeMirror, but it works partially - it applies the selected theme to the textarea but the syntax is not highlighted. There is my page: <textarea id="template-html" name="code" class="CodeMirror"> <!DOCTYPE html> <foobar> <blah>Enter your xml here and press the button below to display it as highlighted by the CodeMirror XML mode</blah> <tag2 foo="2" bar="bar" /> </foobar> </textarea> <link rel="stylesheet" type="text/css" href="/site.com/css/codemirror

React Hooks useState+useEffect+event gives stale state

与世无争的帅哥 提交于 2019-11-29 14:08:35
问题 I'm trying to use an event emitter with React useEffect and useState , but it always gets the initial state instead of the updated state. It works if I call the event handler directly, even with a setTimeout . If I pass the value to the useEffect() 2nd argument, it makes it work, however this causes a resubscription to the event emitter every time the value changes (which is triggered off of keystrokes). What am I doing wrong? I've tried useState , useRef , useReducer , and useCallback , and