From e618b22ab4a7de135b1cd5c0fc5bbebe62d94a61 Mon Sep 17 00:00:00 2001 From: Mahamed-Belkheir Date: Sat, 24 Oct 2020 09:39:30 +0100 Subject: [PATCH] added dotenv highlight support for prismjs --- src/components/Markdown/env.ts | 34 +++++++++++++++++++++++++++++++ src/components/Markdown/index.tsx | 1 + 2 files changed, 35 insertions(+) create mode 100644 src/components/Markdown/env.ts diff --git a/src/components/Markdown/env.ts b/src/components/Markdown/env.ts new file mode 100644 index 0000000..d769642 --- /dev/null +++ b/src/components/Markdown/env.ts @@ -0,0 +1,34 @@ +import Prism from "prismjs" + +if (supportsLookBehind()) { + Prism.languages.env = { + property: { + pattern: /(.*.)(?==)/, + }, + string: { + pattern: /(?<==)(.*.)/g, + global: true, + }, + operator: { + pattern: /=/ + } + } +} else { + Prism.languages.env = { + property: { + pattern: /(.*.)(?==)/, + }, + operator: { + pattern: /=/ + } + } +} + + +function supportsLookBehind() { + try { + return /(?<==)(.*)/.test("=hello") + } catch(e) { + return false; + } +} \ No newline at end of file diff --git a/src/components/Markdown/index.tsx b/src/components/Markdown/index.tsx index d110f87..fb14269 100644 --- a/src/components/Markdown/index.tsx +++ b/src/components/Markdown/index.tsx @@ -16,6 +16,7 @@ import "prismjs/plugins/line-numbers/prism-line-numbers.css" import React, { FC, useEffect } from "react" import { MDXRenderer } from "gatsby-plugin-mdx" import * as SC from "./styles" +import "./env"; interface IMarkdownProps { content: string