| @@ -1497,8 +1497,9 @@ | ||
| 1497 | 1497 | 'json' => '📋', |
| 1498 | 1498 | 'yaml' => '📋', |
| 1499 | 1499 | 'xml' => '📄', |
| 1500 | 1500 | 'markdown' => '📝', |
| 1501 | + 'curl' => '💻', | |
| 1501 | 1502 | 'bash' => '💻', |
| 1502 | 1503 | 'shell' => '💻', |
| 1503 | 1504 | 'powershell' => '💻', |
| 1504 | 1505 | 'dockerfile' => '🐳', |
| @@ -1504,8 +1505,89 @@ | ||
| 1504 | 1505 | 'dockerfile' => '🐳', |
| 1505 | 1506 | ]; |
| 1506 | 1507 | |
| 1507 | 1508 | return isset( $icons[$language] ) ? $icons[$language] : '📄'; |
| 1509 | + } | |
| 1510 | + | |
| 1511 | + /** | |
| 1512 | + * Echo the copy-to-clipboard button used by the Code Snippet and Code | |
| 1513 | + * Snippet Tab templates. | |
| 1514 | + * | |
| 1515 | + * Both icons ship in the markup and CSS cross-fades between them on | |
| 1516 | + * `.is-copied`, so the frontend script never rewrites the SVG. The tooltip | |
| 1517 | + * carries its own strings as data attributes so the script can swap | |
| 1518 | + * "Copy" → "Copied!" without hard-coding English. | |
| 1519 | + * | |
| 1520 | + * @return void | |
| 1521 | + */ | |
| 1522 | + public static function code_snippet_copy_button() { | |
| 1523 | + ?> | |
| 1524 | + <div class="betterdocs-code-snippet-copy-container"> | |
| 1525 | + <button class="betterdocs-code-snippet-copy-button" | |
| 1526 | + type="button" | |
| 1527 | + aria-label="<?php esc_attr_e( 'Copy code to clipboard', 'betterdocs' ); ?>"> | |
| 1528 | + <span class="betterdocs-code-snippet-copy-icon" aria-hidden="true"> | |
| 1529 | + <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
| 1530 | + <rect x="9" y="9" width="12.5" height="12.5" rx="3" stroke="currentColor" stroke-width="1.7"/> | |
| 1531 | + <path d="M15.5 5.75V5A2.5 2.5 0 0 0 13 2.5H5A2.5 2.5 0 0 0 2.5 5v8A2.5 2.5 0 0 0 5 15.5h.75" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/> | |
| 1532 | + </svg> | |
| 1533 | + </span> | |
| 1534 | + <span class="betterdocs-code-snippet-copied-icon" aria-hidden="true"> | |
| 1535 | + <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
| 1536 | + <path d="M20 6.5 9.5 17 4 11.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/> | |
| 1537 | + </svg> | |
| 1538 | + </span> | |
| 1539 | + </button> | |
| 1540 | + <span class="betterdocs-code-snippet-tooltip" | |
| 1541 | + role="status" | |
| 1542 | + data-copy-label="<?php esc_attr_e( 'Copy', 'betterdocs' ); ?>" | |
| 1543 | + data-copied-label="<?php esc_attr_e( 'Copied!', 'betterdocs' ); ?>" | |
| 1544 | + data-error-label="<?php esc_attr_e( 'Copy failed', 'betterdocs' ); ?>"><?php esc_html_e( 'Copy', 'betterdocs' ); ?></span> | |
| 1545 | + </div> | |
| 1546 | + <?php | |
| 1547 | + } | |
| 1548 | + | |
| 1549 | + /** | |
| 1550 | + * Human-readable label for a programming-language identifier, used as the | |
| 1551 | + * language-dropdown label on multi-language code snippets. Mirrors the | |
| 1552 | + * block's LANGUAGE_OPTIONS; falls back to an upper-cased identifier. | |
| 1553 | + * | |
| 1554 | + * @param string $language Programming language identifier | |
| 1555 | + * @return string | |
| 1556 | + */ | |
| 1557 | + public static function get_language_label( $language ) { | |
| 1558 | + $labels = [ | |
| 1559 | + 'javascript' => 'JavaScript', | |
| 1560 | + 'typescript' => 'TypeScript', | |
| 1561 | + 'php' => 'PHP', | |
| 1562 | + 'python' => 'Python', | |
| 1563 | + 'java' => 'Java', | |
| 1564 | + 'ruby' => 'Ruby', | |
| 1565 | + 'curl' => 'cURL', | |
| 1566 | + 'bash' => 'Bash', | |
| 1567 | + 'shell' => 'Shell', | |
| 1568 | + 'json' => 'JSON', | |
| 1569 | + 'yaml' => 'YAML', | |
| 1570 | + 'html' => 'HTML', | |
| 1571 | + 'css' => 'CSS', | |
| 1572 | + 'scss' => 'SCSS', | |
| 1573 | + 'sql' => 'SQL', | |
| 1574 | + 'xml' => 'XML', | |
| 1575 | + 'cpp' => 'C++', | |
| 1576 | + 'csharp' => 'C#', | |
| 1577 | + 'c' => 'C', | |
| 1578 | + 'go' => 'Go', | |
| 1579 | + 'rust' => 'Rust', | |
| 1580 | + 'swift' => 'Swift', | |
| 1581 | + 'kotlin' => 'Kotlin', | |
| 1582 | + 'markdown' => 'Markdown' | |
| 1583 | + ]; | |
| 1584 | + | |
| 1585 | + if ( isset( $labels[ $language ] ) ) { | |
| 1586 | + return $labels[ $language ]; | |
| 1587 | + } | |
| 1588 | + | |
| 1589 | + return ucwords( str_replace( [ '-', '_' ], ' ', (string) $language ) ); | |
| 1508 | 1590 | } |
| 1509 | 1591 | |
| 1510 | 1592 | /** |
| 1511 | 1593 | * Check if AI Chatbot is enabled |