浏览代码

:sparkles: #324

Liyuan Li 5 年之前
父节点
当前提交
dffe0a0f40
共有 5 个文件被更改,包括 134 次插入111 次删除
  1. 0 105
      src/assets/scss/content-theme/dark.scss
  2. 118 0
      src/css/content-theme/dark.css
  3. 3 2
      src/ts/ui/setCodeTheme.ts
  4. 12 4
      src/ts/ui/setContentTheme.ts
  5. 1 0
      webpack.config.js

+ 0 - 105
src/assets/scss/content-theme/dark.scss

@@ -1,105 +0,0 @@
-.vditor {
-  &-reset {
-    color: #d1d5da;
-
-    h1 {
-      border-bottom: 1px solid #d1d5da;
-    }
-
-    h2 {
-      border-bottom: 1px solid #d1d5da;
-    }
-
-    hr {
-      background-color: #d1d5da;
-    }
-
-    blockquote {
-      padding: 0 1em;
-      color: #b9b9b9;
-      border-left: 0.25em solid #d1d5da;
-    }
-
-    iframe {
-      border: 1px solid #141414;
-    }
-
-    table {
-
-      tr {
-        background-color: #2f363d;
-      }
-
-      td,
-      th {
-        border: 1px solid #dfe2e5;
-      }
-
-      tbody tr:nth-child(2n) {
-        background-color: #24292e;
-      }
-    }
-
-    code:not(.hljs):not(.highlight-chroma) {
-      background-color: rgba(66, 133, 244, 0.36);
-
-      &.language-mermaid,
-      &.language-math,
-      &.language-graphviz,
-      &.language-echarts {
-        background-color: rgba(120, 146, 190, 0.55);
-      }
-    }
-
-
-    kbd {
-      color: #d1d5da;
-      background-color: #2f363d;
-      border: solid 1px #141414;
-      box-shadow: inset 0 -1px 0 #141414;
-    }
-  }
-
-  &-copy {
-    svg {
-      color: #b9b9b9;
-    }
-  }
-
-  &-speech {
-    background-color: #1d2125;
-    border: 1px solid #141414;
-    color: #b9b9b9;
-
-    &:hover,
-    &--current {
-      color: #fff;
-    }
-  }
-
-  &-linkcard {
-    a {
-      background-color: #1d2125;
-
-      &:visited .vditor-linkcard__abstract {
-        color: rgba(185, 185, 185, .36);
-      }
-    }
-
-    &__title {
-      color: #d1d5da;
-    }
-
-    &__abstract {
-      color: #b9b9b9;
-    }
-
-    &__site {
-      color: #fff;
-    }
-
-    &__image {
-      background-color: rgba(185, 185, 185, .36);
-    }
-  }
-}

+ 118 - 0
src/css/content-theme/dark.css

@@ -0,0 +1,118 @@
+/*!
+ * Vditor - A markdown editor written in TypeScript.
+ *
+ * MIT License
+ *
+ * Copyright (c) 2018-present B3log 开源, b3log.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+.vditor-reset {
+    color: #d1d5da;
+    background-color: #2f363d !important;
+}
+
+.vditor-reset a, .vditor-ir__link {
+    color: #4285f4;
+}
+
+.vditor-reset h1, .vditor-reset h2 {
+    border-bottom: 1px solid #d1d5da
+}
+
+.vditor-reset hr {
+    background-color: #d1d5da
+}
+
+.vditor-reset blockquote {
+    padding: 0 1em;
+    color: #b9b9b9;
+    border-left: .25em solid #d1d5da
+}
+
+.vditor-reset iframe {
+    border: 1px solid #141414
+}
+
+.vditor-reset table tr {
+    background-color: #2f363d
+}
+
+.vditor-reset table td, .vditor-reset table th {
+    border: 1px solid #dfe2e5
+}
+
+.vditor-reset table tbody tr:nth-child(2n) {
+    background-color: #24292e
+}
+
+.vditor-reset code:not(.hljs):not(.highlight-chroma) {
+    background-color: rgba(66, 133, 244, .36)
+}
+
+.vditor-reset code:not(.hljs):not(.highlight-chroma).language-echarts, .vditor-reset code:not(.hljs):not(.highlight-chroma).language-graphviz, .vditor-reset code:not(.hljs):not(.highlight-chroma).language-math, .vditor-reset code:not(.hljs):not(.highlight-chroma).language-mermaid {
+    background-color: rgba(120, 146, 190, .55)
+}
+
+.vditor-reset kbd {
+    color: #d1d5da;
+    background-color: #2f363d;
+    border: 1px solid #141414;
+    box-shadow: inset 0 -1px 0 #141414
+}
+
+.vditor-copy svg {
+    color: #b9b9b9
+}
+
+.vditor-speech {
+    background-color: #1d2125;
+    border: 1px solid #141414;
+    color: #b9b9b9
+}
+
+.vditor-speech--current, .vditor-speech:hover {
+    color: #fff
+}
+
+.vditor-linkcard a {
+    background-color: #1d2125
+}
+
+.vditor-linkcard a:visited .vditor-linkcard__abstract {
+    color: hsla(0, 0%, 72.5%, .36)
+}
+
+.vditor-linkcard__title {
+    color: #d1d5da
+}
+
+.vditor-linkcard__abstract {
+    color: #b9b9b9
+}
+
+.vditor-linkcard__site {
+    color: #fff
+}
+
+.vditor-linkcard__image {
+    background-color: hsla(0, 0%, 72.5%, .36)
+}

+ 3 - 2
src/ts/ui/setCodeTheme.ts

@@ -7,8 +7,9 @@ export const setCodeTheme = (codeTheme: string, cdn: string) => {
     }
     const vditorHljsStyle = document.getElementById("vditorHljsStyle") as HTMLLinkElement;
     const href = `${cdn}/dist/js/highlight.js/styles/${codeTheme}.css`;
-    if (vditorHljsStyle && vditorHljsStyle.href !== href) {
+    if (!vditorHljsStyle) {
+        addStyle(href, "vditorHljsStyle");
+    } else if (vditorHljsStyle.href !== href) {
         vditorHljsStyle.remove();
     }
-    addStyle(`${cdn}/dist/js/highlight.js/styles/${codeTheme}.css`, "vditorHljsStyle");
 };

+ 12 - 4
src/ts/ui/setContentTheme.ts

@@ -2,13 +2,21 @@ import {Constants} from "../constants";
 import {addStyle} from "../util/addStyle";
 
 export const setContentTheme = (contentTheme: string, cdn: string) => {
-    if (!Constants.CONTENT_THEME.includes(contentTheme) || contentTheme === "light") {
+    if (!Constants.CONTENT_THEME.includes(contentTheme)) {
         return;
     }
     const vditorContentTheme = document.getElementById("vditorContentTheme") as HTMLLinkElement;
-    const href = `${cdn}/dist/js/highlight.js/styles/${contentTheme}.css`;
-    if (vditorContentTheme && vditorContentTheme.href !== href) {
+    const href = `${cdn}/dist/css/content-theme/${contentTheme}.css`;
+    if (contentTheme === "light") {
+        if (vditorContentTheme) {
+            vditorContentTheme.remove();
+        }
+        return;
+    }
+    if (!vditorContentTheme) {
+        addStyle(href, "vditorContentTheme");
+    } else if (vditorContentTheme.href !== href) {
         vditorContentTheme.remove();
+        addStyle(href, "vditorContentTheme");
     }
-    addStyle(`${cdn}/dist/js/highlight.js/styles/${contentTheme}.css`, "vditorContentTheme");
 };

+ 1 - 0
webpack.config.js

@@ -101,6 +101,7 @@ module.exports = [
         fs.unlinkSync('./dist/index.js')
       }),
       new CopyPlugin([
+        {from: 'src/css', to: 'css'},
         {from: 'src/images', to: 'images'},
         {from: 'src/js', to: 'js'},
         {from: 'types', to: 'types'},