@yltrcc/vditor 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.3.1 - A markdown editor written in TypeScript.
2
+ * Vditor v0.3.2 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -25,7 +25,7 @@
25
25
  *
26
26
  */
27
27
  /*!
28
- * Vditor v0.3.1 - A markdown editor written in TypeScript.
28
+ * Vditor v0.3.2 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
@@ -1399,67 +1399,98 @@
1399
1399
  .vditor-wysiwyg__block {
1400
1400
  position: relative;
1401
1401
  }
1402
- .vditor-wysiwyg__block pre:first-child {
1403
- display: none;
1402
+ .vditor-wysiwyg__block--editing .vditor-wysiwyg__preview {
1403
+ display: none !important;
1404
+ }
1405
+ .vditor-wysiwyg__block--editing .vditor-wysiwyg__pre {
1406
+ display: block;
1404
1407
  position: relative;
1405
- margin: 0;
1406
- padding: 1em;
1407
- background-color: rgba(0, 0, 0, 0.03);
1408
- border-radius: 4px;
1408
+ margin: 12px 0;
1409
+ padding: 12px;
1410
+ background-color: #1e1e1e;
1411
+ border-radius: 8px;
1409
1412
  overflow-x: auto;
1410
1413
  cursor: text;
1411
1414
  white-space: initial;
1412
1415
  min-height: 27px;
1413
- background-size: 20px 20px;
1414
- background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8AgMAAABHkjHhAAAACVBMVEWAgIBaWlo+Pj7rTFvWAAAAA3RSTlMHCAw+VhR4AAAA+klEQVQoz4WSMW7EQAhFPxKWNh2FCx+HkaZI6RRb5DYbyVfIJXLKDCFoMbaTKSw/8ZnPAPjaH2xgZcUNUDADD7D9LtDBCLZ45fbkvo/30K8yeI64pPwl6znd/3n/Oe93P3ho9qeh72btTFzqkz0rsJle8Zr81OLEwZ1dv/713uWqvu2pl+k0fy7MWtj9r/tN5q/02z89qa/L4Dc2LvM93kezPfXlME/O86EbY/V9GB9ePX8G1/6W+/9h1dq/HGfTfzT3j/xNo7522Bfnqe5jO/fvhVthlfk434v3iO9zG/UOphyPeinPl1J8Gtaa7xPTa/Dk+RIs4deMvwGvcGsmsCvJ0AAAAABJRU5ErkJggg==);
1416
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
1415
1417
  }
1416
- .vditor-wysiwyg__block pre:first-child code {
1418
+ .vditor-wysiwyg__block--editing .vditor-wysiwyg__pre code {
1417
1419
  margin: 0;
1418
- font-family: var(--code-font-family);
1419
- font-size: var(--code-font-size);
1420
- line-height: var(--code-line-height);
1421
- padding: 0;
1422
- background-color: transparent !important;
1420
+ padding: 0 !important;
1421
+ font-family: mononoki, Consolas, "Liberation Mono", Menlo, Courier, monospace, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols";
1422
+ font-size: 14px;
1423
+ line-height: 1.6;
1424
+ color: #d4d4d4;
1425
+ background-color: transparent;
1423
1426
  border-radius: 0;
1424
- display: inline;
1427
+ display: block;
1425
1428
  overflow: visible;
1426
1429
  white-space: pre;
1427
1430
  word-break: initial;
1428
1431
  word-wrap: normal;
1429
1432
  }
1430
- .vditor-wysiwyg__block pre:first-child::before {
1433
+ .vditor-wysiwyg__block--editing .vditor-wysiwyg__pre::before {
1431
1434
  content: attr(data-language);
1432
1435
  position: absolute;
1433
1436
  top: 0;
1434
1437
  right: 0;
1435
- padding: 2px 8px;
1438
+ padding: 8px 12px;
1436
1439
  font-size: 12px;
1437
- color: var(--second-color);
1438
- background-color: var(--panel-background-color);
1439
- border-radius: 0 4px 0 4px;
1440
+ color: #4ec9b0;
1441
+ background-color: #252526;
1442
+ border-radius: 0 8px 0 0;
1443
+ border-bottom: 1px solid #3c3c3c;
1440
1444
  z-index: 1;
1445
+ font-weight: 500;
1441
1446
  }
1442
- .vditor-wysiwyg__block pre:first-child:hover {
1443
- box-shadow: 0 0 0 2px var(--blurColor);
1444
- }
1445
- .vditor-wysiwyg__block pre:first-child:focus {
1446
- outline: none;
1447
- }
1448
- .vditor-wysiwyg__block pre:last-child {
1449
- margin-bottom: 1em;
1447
+ .vditor-wysiwyg__block:not(.vditor-wysiwyg__block--editing) .vditor-wysiwyg__pre {
1448
+ display: none;
1450
1449
  }
1451
- .vditor-wysiwyg__block--editing pre:first-child {
1450
+ .vditor-wysiwyg__block:not(.vditor-wysiwyg__block--editing) .vditor-wysiwyg__preview {
1452
1451
  display: block;
1452
+ position: relative;
1453
+ margin: 12px 0;
1454
+ padding: 12px;
1455
+ background-color: #1e1e1e;
1456
+ border-radius: 8px;
1457
+ overflow-x: auto;
1458
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
1459
+ }
1460
+ .vditor-wysiwyg__block:not(.vditor-wysiwyg__block--editing) .vditor-wysiwyg__preview > code {
1453
1461
  margin: 0;
1462
+ padding: 0 !important;
1463
+ font-family: mononoki, Consolas, "Liberation Mono", Menlo, Courier, monospace, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols";
1464
+ font-size: 14px;
1465
+ line-height: 1.6;
1466
+ color: #d4d4d4;
1467
+ background: transparent;
1468
+ display: block;
1469
+ white-space: pre;
1454
1470
  }
1455
- .vditor-wysiwyg__block--editing .vditor-wysiwyg__preview {
1471
+ .vditor-wysiwyg__block:not(.vditor-wysiwyg__block--editing) .vditor-wysiwyg__preview .vditor-copy {
1456
1472
  display: none;
1457
1473
  }
1474
+ .vditor-wysiwyg__block:not(.vditor-wysiwyg__block--editing) .vditor-wysiwyg__preview::before {
1475
+ content: attr(data-language);
1476
+ position: absolute;
1477
+ top: 0;
1478
+ right: 0;
1479
+ padding: 8px 12px;
1480
+ font-size: 12px;
1481
+ color: #4ec9b0;
1482
+ background-color: #252526;
1483
+ border-radius: 0 8px 0 0;
1484
+ border-bottom: 1px solid #3c3c3c;
1485
+ z-index: 1;
1486
+ font-weight: 500;
1487
+ }
1458
1488
  .vditor-wysiwyg__preview {
1459
1489
  cursor: pointer;
1460
1490
  white-space: initial;
1461
1491
  min-height: 27px;
1462
1492
  display: block;
1493
+ margin: 0;
1463
1494
  }
1464
1495
  .vditor-wysiwyg__preview pre {
1465
1496
  margin: 0;
@@ -1467,12 +1498,16 @@
1467
1498
  background-color: var(--code-background-color);
1468
1499
  border-radius: 4px;
1469
1500
  overflow-x: auto;
1501
+ box-sizing: border-box;
1470
1502
  }
1471
1503
  .vditor-wysiwyg__preview pre code {
1472
- font-family: var(--code-font-family);
1473
- font-size: var(--code-font-size);
1474
1504
  line-height: var(--code-line-height);
1475
1505
  background-color: transparent !important;
1506
+ display: block;
1507
+ white-space: pre;
1508
+ word-break: initial;
1509
+ word-wrap: normal;
1510
+ box-sizing: border-box;
1476
1511
  }
1477
1512
  .vditor-wysiwyg__preview::before {
1478
1513
  content: attr(data-language);
@@ -1488,6 +1523,25 @@
1488
1523
  .vditor-wysiwyg__preview:hover {
1489
1524
  box-shadow: 0 0 0 2px var(--blurColor);
1490
1525
  }
1526
+ .vditor-wysiwyg__pre {
1527
+ margin: 0;
1528
+ padding: 12px;
1529
+ border-radius: 4px;
1530
+ line-height: var(--code-line-height);
1531
+ background-color: var(--panel-background-color);
1532
+ }
1533
+ .vditor-wysiwyg__pre code {
1534
+ margin: 0;
1535
+ line-height: var(--code-line-height);
1536
+ padding: 0;
1537
+ background-color: transparent !important;
1538
+ border-radius: 0;
1539
+ display: inline;
1540
+ overflow: visible;
1541
+ white-space: pre;
1542
+ word-break: initial;
1543
+ word-wrap: normal;
1544
+ }
1491
1545
  .vditor-wysiwyg > .vditor-reset > h1:before,
1492
1546
  .vditor-wysiwyg > .vditor-reset > h2:before,
1493
1547
  .vditor-wysiwyg > .vditor-reset > h3:before,
@@ -1829,6 +1883,48 @@
1829
1883
  content: none;
1830
1884
  }
1831
1885
  }
1886
+ /* 掘金风格代码块样式 */
1887
+ .vditor-ir .vditor-ir__node[data-type="code-block"] {
1888
+ background: #1e1e1e;
1889
+ border-radius: 8px;
1890
+ overflow: hidden;
1891
+ margin: 12px 0;
1892
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
1893
+ }
1894
+ .vditor-ir .vditor-ir__node[data-type="code-block"]::before,
1895
+ .vditor-ir .vditor-ir__node[data-type="code-block"]::after {
1896
+ display: none !important;
1897
+ }
1898
+ .vditor-ir .vditor-ir__node[data-type="code-block"] .vditor-ir__marker {
1899
+ display: none !important;
1900
+ }
1901
+ .vditor-ir .vditor-ir__node[data-type="code-block"] pre[data-type="code-block-info"],
1902
+ .vditor-ir .vditor-ir__node[data-type="code-block"] pre[data-type="code-block-marker"] {
1903
+ display: none !important;
1904
+ }
1905
+ .vditor-ir .vditor-ir__node[data-type="code-block"] .vditor-ir__preview {
1906
+ display: block;
1907
+ padding: 0;
1908
+ margin: 0;
1909
+ border-radius: 0;
1910
+ position: relative;
1911
+ }
1912
+ .vditor-ir .vditor-ir__node[data-type="code-block"] .vditor-ir__preview pre {
1913
+ margin: 0;
1914
+ padding: 12px;
1915
+ border-radius: 0;
1916
+ background: transparent;
1917
+ overflow-x: auto;
1918
+ }
1919
+ .vditor-ir .vditor-ir__node[data-type="code-block"] .vditor-ir__preview code {
1920
+ font-family: mononoki, Consolas, "Liberation Mono", Menlo, Courier, monospace, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols";
1921
+ font-size: 14px;
1922
+ line-height: 1.6;
1923
+ color: #d4d4d4;
1924
+ background: transparent;
1925
+ display: block;
1926
+ white-space: pre;
1927
+ }
1832
1928
  .vditor-sv {
1833
1929
  font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", "Hiragino Sans GB", "Microsoft Yahei", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", "EmojiSymbols";
1834
1930
  margin: 0 1px 0 0;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.3.1 - A markdown editor written in TypeScript.
2
+ * Vditor v0.3.2 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -1267,7 +1267,7 @@ var looseJsonParse = function (text) {
1267
1267
  /* harmony export */ Y: () => (/* binding */ Constants),
1268
1268
  /* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
1269
1269
  /* harmony export */ });
1270
- var _VDITOR_VERSION = "0.3.1";
1270
+ var _VDITOR_VERSION = "0.3.2";
1271
1271
 
1272
1272
  var Constants = /** @class */ (function () {
1273
1273
  function Constants() {
@@ -1315,7 +1315,7 @@ var Constants = /** @class */ (function () {
1315
1315
  // 别名
1316
1316
  "js", "ts", "html", "toml", "c#", "bat"
1317
1317
  ];
1318
- Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.3.1");
1318
+ Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.3.2");
1319
1319
  Constants.MARKDOWN_OPTIONS = {
1320
1320
  autoSpace: false,
1321
1321
  gfmAutoLink: true,
@@ -5460,6 +5460,9 @@ var processPasteCode = function (html, text, type) {
5460
5460
  return false;
5461
5461
  };
5462
5462
  var processCodeRender = function (previewPanel, vditor) {
5463
+ console.log("===== Lute 返回的 HTML (预览前) =====");
5464
+ console.log(previewPanel.outerHTML);
5465
+ console.log("===== 结束 =====\n");
5463
5466
  if (!previewPanel) {
5464
5467
  return;
5465
5468
  }
@@ -5514,8 +5517,100 @@ var processCodeRender = function (previewPanel, vditor) {
5514
5517
  (0,codeRender/* codeRender */.o)(previewPanel, vditor.options.preview.hljs);
5515
5518
  }
5516
5519
  }
5520
+ // 掘金风格代码块增强
5521
+ enhanceCodeBlock(previewPanel, language);
5517
5522
  previewPanel.setAttribute("data-render", "1");
5518
5523
  };
5524
+ var enhanceCodeBlock = function (previewPanel, language) {
5525
+ // 检查是否已经增强过
5526
+ if (previewPanel.getAttribute("data-enhanced") === "1") {
5527
+ return;
5528
+ }
5529
+ var preElement = previewPanel.querySelector("pre");
5530
+ if (!preElement) {
5531
+ return;
5532
+ }
5533
+ var codeElement = preElement.querySelector("code");
5534
+ if (!codeElement) {
5535
+ return;
5536
+ }
5537
+ // 保存原始代码用于复制
5538
+ var rawCode = codeElement.textContent || "";
5539
+ // 添加行号
5540
+ var codeLines = rawCode.split("\n");
5541
+ var hasLineNumbers = codeElement.querySelector(".line-numbers");
5542
+ if (!hasLineNumbers && codeLines.length > 0) {
5543
+ var lineNumbersHTML = codeLines.map(function (_, index) {
5544
+ return "<span class=\"line-number\">".concat(index + 1, "</span>");
5545
+ }).join("");
5546
+ codeElement.innerHTML = "\n <div style=\"display: table;\">\n <div class=\"line-numbers\" style=\"display: table-cell; padding: 0 12px; text-align: right; border-right: 1px solid #3c3c3c; color: #6a6a6a; font-family: mononoki, Consolas, \"Liberation Mono\", Menlo, Courier, monospace, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\", \"Segoe UI Symbol\", \"Android Emoji\", \"EmojiSymbols\";; font-size: 14px; line-height: 1.6; user-select: none; min-width: 3em; background: #252526;\">\n ".concat(codeLines.map(function (_, index) { return "<div>".concat(index + 1, "</div>"); }).join(""), "\n </div>\n <div class=\"code-content\" style=\"display: table-cell; padding: 0 12px; font-family: mononoki, Consolas, \"Liberation Mono\", Menlo, Courier, monospace, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\", \"Segoe UI Symbol\", \"Android Emoji\", \"EmojiSymbols\";; font-size: 14px; line-height: 1.6; color: #d4d4d4;\">\n ").concat(codeElement.innerHTML, "\n </div>\n </div>\n ");
5547
+ }
5548
+ // 创建标题栏
5549
+ var headerElement = document.createElement("div");
5550
+ headerElement.className = "vditor-code-header";
5551
+ headerElement.style.cssText = "\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 8px 12px;\n background: #252526;\n border-bottom: 1px solid #3c3c3c;\n ";
5552
+ // 左侧:折叠图标和标题
5553
+ var leftElement = document.createElement("div");
5554
+ leftElement.style.cssText = "\n display: flex;\n align-items: center;\n gap: 8px;\n color: #9d9d9d;\n font-size: 12px;\n ";
5555
+ var toggleIcon = document.createElement("span");
5556
+ toggleIcon.textContent = "▼";
5557
+ toggleIcon.style.cssText = "\n cursor: pointer;\n transition: transform 0.2s;\n color: #9d9d9d;\n ";
5558
+ toggleIcon.title = "折叠/展开";
5559
+ var titleElement = document.createElement("span");
5560
+ titleElement.textContent = "代码标题";
5561
+ titleElement.style.cssText = "\n color: #9d9d9d;\n font-size: 12px;\n ";
5562
+ leftElement.appendChild(toggleIcon);
5563
+ leftElement.appendChild(titleElement);
5564
+ // 右侧:语言标签和复制按钮
5565
+ var rightElement = document.createElement("div");
5566
+ rightElement.style.cssText = "\n display: flex;\n align-items: center;\n gap: 12px;\n ";
5567
+ var langElement = document.createElement("span");
5568
+ langElement.textContent = language || "text";
5569
+ langElement.style.cssText = "\n color: #4ec9b0;\n font-weight: 500;\n font-size: 12px;\n ";
5570
+ var copyButton = document.createElement("span");
5571
+ copyButton.textContent = "复制";
5572
+ copyButton.style.cssText = "\n display: flex;\n align-items: center;\n gap: 4px;\n color: #9d9d9d;\n font-size: 12px;\n cursor: pointer;\n padding: 4px 8px;\n border-radius: 4px;\n transition: all 0.2s;\n ";
5573
+ copyButton.title = "复制代码";
5574
+ copyButton.addEventListener("mouseenter", function () {
5575
+ copyButton.style.color = "#fff";
5576
+ copyButton.style.background = "#3c3c3c";
5577
+ });
5578
+ copyButton.addEventListener("mouseleave", function () {
5579
+ copyButton.style.color = "#9d9d9d";
5580
+ copyButton.style.background = "transparent";
5581
+ });
5582
+ copyButton.addEventListener("click", function () {
5583
+ navigator.clipboard.writeText(rawCode).then(function () {
5584
+ var originalText = copyButton.textContent;
5585
+ copyButton.textContent = "已复制!";
5586
+ copyButton.style.color = "#4ec9b0";
5587
+ setTimeout(function () {
5588
+ copyButton.textContent = originalText;
5589
+ copyButton.style.color = "#9d9d9d";
5590
+ }, 2000);
5591
+ }).catch(function (err) {
5592
+ console.error("复制失败:", err);
5593
+ });
5594
+ });
5595
+ // 折叠功能
5596
+ var isCollapsed = false;
5597
+ toggleIcon.addEventListener("click", function () {
5598
+ isCollapsed = !isCollapsed;
5599
+ var contentElement = preElement.querySelector("code");
5600
+ if (contentElement) {
5601
+ contentElement.style.display = isCollapsed ? "none" : "block";
5602
+ }
5603
+ toggleIcon.textContent = isCollapsed ? "▶" : "▼";
5604
+ });
5605
+ rightElement.appendChild(langElement);
5606
+ rightElement.appendChild(copyButton);
5607
+ headerElement.appendChild(leftElement);
5608
+ headerElement.appendChild(rightElement);
5609
+ // 插入标题栏
5610
+ previewPanel.insertBefore(headerElement, previewPanel.firstChild);
5611
+ // 标记已增强
5612
+ previewPanel.setAttribute("data-enhanced", "1");
5613
+ };
5519
5614
 
5520
5615
  // EXTERNAL MODULE: ./src/ts/util/selection.ts
5521
5616
  var selection = __webpack_require__(183);