मैं एक कोड आधारित चैट घटक विकसित कर रहा हूं। प्रत्येक चैट कुछ कोड स्निपेट है। उपयोगकर्ता इनपुट के लिए, मैं monaco-editor का उपयोग कर रहा हूं। यह बढ़िया काम करता है।

लेकिन जैसे ही उपयोगकर्ता हिट बटन भेजता है, मुझे मोनाको संपादक से कच्चा इनपुट मिलता है। मुझे इस उपयोगकर्ता इनपुट को चैट सूची में जोड़ना होगा और इस इनपुट को फिर से हाइलाइट करना होगा।

क्या ऐसा करने के लिए मैं मोनाको संपादक का उपयोग कर सकता हूं? या क्या मुझे मोनाको के साथ highlight.js का उपयोग करना होगा?

10
Harshal Patil 8 अक्टूबर 2018, 13:29

3 जवाब

सबसे बढ़िया उत्तर

मुझे भी यही समस्या थी इसलिए मैंने #1171 एक मुद्दा बनाया:

और दो समाधान प्रदान किए गए:

ए) मौजूदा एचटीएमएल तत्व को प्रारूपित करें:

monaco.editor.colorizeElement(document.getElementById("yourElement"));

B) ऐसे टेक्स्ट को फॉर्मेट करें जो किसी एलिमेंट का हिस्सा न हो। यह एक अधिक सामान्य दृष्टिकोण है जो एक वादा देता है:

const code = "source code";
monaco.editor.colorize(code, "javascript")
  .then(html => document.getElementById("yourElement").innerHTML = html);

दस्तावेज़ीकरण:

10
Petr 6 नवम्बर 2018, 00:09

यदि कोई अभी भी खोज रहा है, तो वर्तमान में मोनाको संपादक के लिए एक घोषणात्मक सिंटैक्स हाइलाइटर है, जिसे Monarch< कहा जाता है। /ए>

4
Mellervin 18 अप्रैल 2019, 19:39

मोनार्क न्यूनतम उदाहरण

https://stackoverflow.com/a/55750400/895245 ने सम्राट का उल्लेख किया है, और एक आधिकारिक न्यूनतम उदाहरण < पर पाया जा सकता है a href="https://github.com/microsoft/monaco-editor-samples/blob/6d7b03a1de53f34272e65b7b23dbf4c5dd1c575b/browser-amd-monarch/index.html" rel="nofollow noreferrer">https://github.com/microsoft /monaco-editor-samples/blob/6d7b03a1de53f34272e65b7b23dbf4c5dd1c575b/browser-amd-monarch/index.html

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>

<h2>Monarch Tokenizer Sample</h2>
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>

<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
<script>
    require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' }});

    require(['vs/editor/editor.main'], function() {

        monaco.languages.register({
            id: 'myCustomLanguage'
        });
        monaco.languages.setMonarchTokensProvider('myCustomLanguage', {
            tokenizer: {
                root: [
                    [/\[error.*/, "custom-error"],
                    [/\[notice.*/, "custom-notice"],
                    [/\[info.*/, "custom-info"],
                    [/\[[a-zA-Z 0-9:]+\]/, "custom-date"],
                ],
            }
        });

        // Define a new theme that constains only rules that match this language
        monaco.editor.defineTheme('myCoolTheme', {
            base: 'vs',
            inherit: false,
            rules: [
                { token: 'custom-info', foreground: '808080' },
                { token: 'custom-error', foreground: 'ff0000', fontStyle: 'bold' },
                { token: 'custom-notice', foreground: 'FFA500' },
                { token: 'custom-date', foreground: '008800' },
            ]
        });
        
        var editor = monaco.editor.create(document.getElementById('container'), {
            theme: 'myCoolTheme',
            value: getCode(),
            language: 'myCustomLanguage'
        });
    });

    function getCode() {
        return [
            '[Sun Mar 7 16:02:00 2004] [notice] Apache/1.3.29 (Unix) configured -- resuming normal operations',
            '[Sun Mar 7 16:02:00 2004] [info] Server built: Feb 27 2004 13:56:37',
            '[Sun Mar 7 16:02:00 2004] [notice] Accept mutex: sysvsem (Default: sysvsem)',
            '[Sun Mar 7 16:05:49 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 16:45:56 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 17:13:50 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 17:21:44 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 17:23:53 2004] statistics: Use of uninitialized value in concatenation (.) or string at /home/httpd/twiki/lib/TWiki.pm line 528.',
            '[Sun Mar 7 17:23:53 2004] statistics: Can\'t create file /home/httpd/twiki/data/Main/WebStatistics.txt - Permission denied',
            '[Sun Mar 7 17:27:37 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 17:31:39 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 17:58:00 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 18:00:09 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 18:10:09 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 18:19:01 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 18:42:29 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 18:52:30 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 18:58:52 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 19:03:58 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 19:08:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 20:04:35 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 20:11:33 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 20:12:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 20:25:31 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 20:44:48 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 20:58:27 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 21:16:17 2004] [error] [client xx.xx.xx.xx] File does not exist: /home/httpd/twiki/view/Main/WebHome',
            '[Sun Mar 7 21:20:14 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 21:31:12 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 21:39:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Sun Mar 7 21:44:10 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 01:35:13 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 01:47:06 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 01:59:13 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 02:12:24 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 02:54:54 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 03:46:27 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 03:48:18 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 03:52:17 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 03:55:09 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 04:22:55 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 04:24:47 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 04:40:32 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 04:55:40 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 04:59:13 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 05:22:57 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 05:24:29 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '[Mon Mar 8 05:31:47 2004] [info] [client xx.xx.xx.xx] (104)Connection reset by peer: client stopped connection before send body completed',
            '<11>httpd[31628]: [error] [client xx.xx.xx.xx] File does not exist: /usr/local/installed/apache/htdocs/squirrelmail/_vti_inf.html in 29-Mar 15:18:20.50 from xx.xx.xx.xx',
            '<11>httpd[25859]: [error] [client xx.xx.xx.xx] File does not exist: /usr/local/installed/apache/htdocs/squirrelmail/_vti_bin/shtml.exe/_vti_rpc in 29-Mar 15:18:20.54 from xx.xx.xx.xx',
        ].join('\n');;
    }
</script>
</body>
</html>

उस रेपो को क्लोन किए बिना एक स्टैंडअलोन संस्करण के लिए आप स्वयं को इस पर आधारित कर सकते हैं: मोनाको संपादक को सीडीएन जैसे सीडीएन से कैसे चलाएं?

2
Ciro Santilli 新疆再教育营六四事件法轮功郝海东 1 पद 2020, 19:06