UNPKG

@patternplate/client

Version:

Universal javascript client application for patternplate

78 lines (62 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _components = require("@patternplate/components"); var _highlight = _interopRequireDefault(require("./highlight")); var _toElements = _interopRequireDefault(require("./to-elements")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _default = Code; exports.default = _default; function Code(props) { const source = highlightCode(props.language, props.children); const code = _react.default.createElement(StyledCode, { className: props.className }, source); return props.block ? _react.default.createElement("pre", null, code) : code; } const themes = { dark: { mono1: "#abb2bf", mono2: "#818896", mono3: "#5c6370", hue1: "#56b6c2", hue2: "#61aeee", hue3: "#c678dd", hue4: "#98c379", hue5: "#e06c75", hue52: "#be5046", hue6: "#d19a66", hue62: "#e6c07b" }, light: { mono1: "#383a42", mono2: "#686b77", mono3: "#a0a1a7", hue1: "#0184bb", hue2: "#4078f2", hue3: "#a626a4", hue4: "#50a14f", hue5: "#e45649", hue52: "#c91243", hue6: "#986801", hue62: "#c18401" } }; const themed = key => props => themes[props.theme.name][key]; const StyledCode = _components.styled.code.withConfig({ displayName: "code__StyledCode" })(["display:block;overflow-x:auto;padding:0.5em;color:", ";font-family:", ";.hljs-comment,.hljs-quote{color:", ";font-style:italic;}.hljs-doctag,.hljs-keyword,.hljs-formula{color:", ";}.hljs-section,.hljs-name,.hljs-selector-tag,.hljs-deletion,.hljs-subst{color:", ";}.hljs-literal{color:", ";}.hljs-string,.hljs-regexp,.hljs-addition,.hljs-attribute,.hljs-meta-string{color:", ";}.hljs-built_in,.hljs-class .hljs-title{color:", ";}.hljs-attr,.hljs-variable,.hljs-template-variable,.hljs-type,.hljs-selector-class,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-number{color:", ";}.hljs-symbol,.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-title{color:", ";}.hljs-emphasis{font-style:italic;}.hljs-strong{font-weight:bold;}.hljs-link{text-decoration:underline;}"], themed("mono1"), props => props.theme.fonts.code, themed("mono3"), themed("hue3"), themed("hue5"), themed("hue1"), themed("hue4"), themed("hue62"), themed("hue6"), themed("hue2")); function highlightCode(language, source = "") { if (!language) { return source; } if (!source) { return source; } const hast = (0, _highlight.default)(language, source); return (0, _toElements.default)(hast); } //# sourceMappingURL=index.js.map