项目作者: MaxDesiatov

项目描述 :
CodeMirror syntax highlighting plugin for Remark and Gatsby
高级语言: TypeScript
项目地址: git://github.com/MaxDesiatov/gatsby-remark-codemirror.git
创建时间: 2018-10-05T20:30:16Z
项目社区:https://github.com/MaxDesiatov/gatsby-remark-codemirror

开源协议:MIT License

下载


gatsby-remark-codemirror

Adds syntax highlighting to code blocks in your Gatsby Markdown files using
CodeMirror Mode
Runner
. Note that this
Remark plugin
does not convert your code blocks to code editor instances, only uses
CodeMirror’s syntax highlighting engine to render static
<code><pre>...</code></pre> blocks with appropriate CSS classes for <span></span>
tags contained within.

Install

npm install --save gatsby-transformer-remark gatsby-remark-codemirror

How to use

  1. // In your gatsby-config.js
  2. plugins: [
  3. {
  4. resolve: `gatsby-transformer-remark`,
  5. options: {
  6. plugins: [
  7. {
  8. resolve: `gatsby-remark-codemirror`,
  9. options: {
  10. // CSS class suffix to be used for produced `<pre></pre>` blocks.
  11. // Default value is "default", which adds "cm-s-default" class.
  12. // This class name matches
  13. theme: "default"
  14. }
  15. }
  16. ]
  17. }
  18. }
  19. ];

Include CSS

Required: Pick a CodeMirror theme or create your own

CodeMirror ships with a number of themes (previewable on the CodeMirror
website
) that you can easily include in your Gatsby site, or you can build
your own by copying and modifying an example.

To load a theme, just require its CSS file in your gatsby-browser.js file, e.g.

  1. // gatsby-browser.js
  2. require("codemirror/lib/codemirror.css");

or for a non-default theme:

  1. // gatsby-browser.js
  2. require("codemirror/theme/ambiance.css");
  3. // don't forget to set `theme: "ambiance"` in gatsby-config.js

Usage in Markdown

This is some beautiful code:

  1. ```swift
  2. extension Never: Equatable {
  3. public static func == (lhs: Never, rhs: Never) -> Bool {
  4. switch (lhs, rhs) {
  5. }
  6. }
  7. }
  8. extension Never: Hashable {
  9. public func hash(into hasher: inout Hasher) {
  10. }
  11. }
  12. ```