forked from swagger-api/swagger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework swagger-api#5259 syntax highlighting with react-syntax-highlig…
…ht 🌈
- Loading branch information
1 parent
63f94db
commit a25aefc
Showing
8 changed files
with
412 additions
and
348 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const copyToClipboard = str => { | ||
// adapted from https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f | ||
const el = document.createElement("textarea") | ||
el.value = str | ||
el.setAttribute("readonly", "") | ||
el.style.position = "absolute" | ||
el.style.left = "-9999px" | ||
|
||
document.body.appendChild(el) | ||
// preserve selection | ||
const selected = | ||
document.getSelection().rangeCount > 0 | ||
? document.getSelection().getRangeAt(0) | ||
: false | ||
el.select() | ||
document.execCommand("copy") | ||
document.body.removeChild(el) | ||
if (selected) { | ||
document.getSelection().removeAllRanges() | ||
document.getSelection().addRange(selected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Light as SyntaxHighlighter } from "react-syntax-highlighter" | ||
|
||
import js from "react-syntax-highlighter/dist/esm/languages/hljs/javascript" | ||
import json from "react-syntax-highlighter/dist/esm/languages/hljs/json" | ||
import xml from "react-syntax-highlighter/dist/esm/languages/hljs/xml" | ||
import bash from "react-syntax-highlighter/dist/esm/languages/hljs/bash" | ||
import yaml from "react-syntax-highlighter/dist/esm/languages/hljs/yaml" | ||
import http from "react-syntax-highlighter/dist/esm/languages/hljs/http" | ||
|
||
import agate from "react-syntax-highlighter/dist/esm/styles/hljs/agate" | ||
|
||
SyntaxHighlighter.registerLanguage("json", json) | ||
SyntaxHighlighter.registerLanguage("js", js) | ||
SyntaxHighlighter.registerLanguage("xml", xml) | ||
SyntaxHighlighter.registerLanguage("yaml", yaml) | ||
SyntaxHighlighter.registerLanguage("http", http) | ||
SyntaxHighlighter.registerLanguage("bash", bash) | ||
|
||
const styles = {agate} | ||
|
||
export {SyntaxHighlighter, styles} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters