sublime 中 react 代码的语法高亮显示
syntax highlighting for react code in sublime
我开始用 sublime text 编写一些基本的 React 代码。这是我的语法突出显示的样子。它部分突出显示。有什么建议的 sublime 插件可以用来查看完整的语法高亮显示吗?
import React, { Component } from 'react'
import { connect } from 'react-redux' // <-- is the glue between react and redux
import { bindActionCreators } from 'redux'
import { selectBook } from '../actions/index'
// there is no intrinsic connection between React and Redux
// they are two seperate libraries
// they are connected using a seperate library called ReactRedux
// container? its a React component that hasa direct connection to state managed by Redux
class BookList extends Component {
constructor(props) {
super(props)
//this.props = props;
}
renderList() {
return this.props.books.map((book) => {
return (
<li key={book.title} className="list-group-item">{book.title}</li>
)
})
}
render() {
return (
<ul className="list-group col-sm-4">
{this.renderList()}
</ul>
)
}
}
// function is the glue between react and redux
function mapStateToProps(state) {
// Whatever gets retrieved from here will show up as props inside
// of book-list
return {
books: state.books
}
}
// anything returned from this function will end up as props on the BookList container
function mapDispatchToProps(dispatch) {
return bindActionCreators({selectBook: selectBook}, dispatch)
}
// Promote BookList from a component to a container - it needs to know
// about this new dispatch method, selectBook. Make it available as a prop
export default connect(mapStateToProps, mapDispatchToProps)(BookList);
编辑:[修复了一些不正确的语法,添加了代码文本]
安装 babel 修复了语法高亮。
在 sublime3 上安装 babel 的步骤:
- 对于windows: 按Ctrl+Shift+P For mac: Cmd+Shift+P
- 然后键入
install
和selectPackage control: Install Package
- 然后输入
Babel
和select'Babel-Snippets'
。稍后它会安装 babel。
- 然后在 Sublime3 编辑器中设置 Babel 语法 from:
View > Syntax > Babel > Javascript
对于某些用户,Babel
在第 4 步中丢失。他们可以 另外安装 Babel
按照相同的步骤和 select这次使用 Babel
而不是步骤 3 中的 Babel-Snippets
。
检查我测试过它:
您需要安装babel-sublime
插件。
您可以从 sublime 的 package control
安装它。
这里是 link - https://github.com/babel/babel-sublime
我能够通过将语法设置为 JSX 来解决这个问题。我不需要安装这个插件。
- 第 1 步 - 转到包控制 (ctrl + shift + p)
- 步骤 2 - Select 安装包
- 第 3 步 - 搜索 JSX 插件并安装它。
- 第 4 步 - 然后在 Sublime3 编辑器中设置 JSX 语法:查看 > 语法 > JSX。
使用扩展名为 .jsx
的文件名
1- 转到包控制
2- 搜索 naomi-syntax 并安装它。
3- 然后在 Sublime3 Editor 中设置 naomi-syntax 语法
来自:视图 > 语法 > naomi-syntax.
我开始用 sublime text 编写一些基本的 React 代码。这是我的语法突出显示的样子。它部分突出显示。有什么建议的 sublime 插件可以用来查看完整的语法高亮显示吗?
import React, { Component } from 'react'
import { connect } from 'react-redux' // <-- is the glue between react and redux
import { bindActionCreators } from 'redux'
import { selectBook } from '../actions/index'
// there is no intrinsic connection between React and Redux
// they are two seperate libraries
// they are connected using a seperate library called ReactRedux
// container? its a React component that hasa direct connection to state managed by Redux
class BookList extends Component {
constructor(props) {
super(props)
//this.props = props;
}
renderList() {
return this.props.books.map((book) => {
return (
<li key={book.title} className="list-group-item">{book.title}</li>
)
})
}
render() {
return (
<ul className="list-group col-sm-4">
{this.renderList()}
</ul>
)
}
}
// function is the glue between react and redux
function mapStateToProps(state) {
// Whatever gets retrieved from here will show up as props inside
// of book-list
return {
books: state.books
}
}
// anything returned from this function will end up as props on the BookList container
function mapDispatchToProps(dispatch) {
return bindActionCreators({selectBook: selectBook}, dispatch)
}
// Promote BookList from a component to a container - it needs to know
// about this new dispatch method, selectBook. Make it available as a prop
export default connect(mapStateToProps, mapDispatchToProps)(BookList);
编辑:[修复了一些不正确的语法,添加了代码文本]
安装 babel 修复了语法高亮。
在 sublime3 上安装 babel 的步骤:
- 对于windows: 按Ctrl+Shift+P For mac: Cmd+Shift+P
- 然后键入
install
和selectPackage control: Install Package
- 然后输入
Babel
和select'Babel-Snippets'
。稍后它会安装 babel。 - 然后在 Sublime3 编辑器中设置 Babel 语法 from:
View > Syntax > Babel > Javascript
对于某些用户,Babel
在第 4 步中丢失。他们可以 另外安装 Babel
按照相同的步骤和 select这次使用 Babel
而不是步骤 3 中的 Babel-Snippets
。
检查我测试过它:
您需要安装babel-sublime
插件。
您可以从 sublime 的 package control
安装它。
这里是 link - https://github.com/babel/babel-sublime
我能够通过将语法设置为 JSX 来解决这个问题。我不需要安装这个插件。
- 第 1 步 - 转到包控制 (ctrl + shift + p)
- 步骤 2 - Select 安装包
- 第 3 步 - 搜索 JSX 插件并安装它。
- 第 4 步 - 然后在 Sublime3 编辑器中设置 JSX 语法:查看 > 语法 > JSX。
使用扩展名为 .jsx
的文件名
1- 转到包控制 2- 搜索 naomi-syntax 并安装它。 3- 然后在 Sublime3 Editor 中设置 naomi-syntax 语法 来自:视图 > 语法 > naomi-syntax.