Click here to Skip to main content
16,004,529 members
Home / Discussions / Web Development
   

Web Development

 
PinnedHow to get an answer to your question Pin
Chris Maunder4-Sep-10 2:25
cofounderChris Maunder4-Sep-10 2:25 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 22:40
cofounderChris Maunder12-Jul-09 22:40 
QuestionHow to make a site visible to specific countries or region ? Pin
Martin Adams 202314-Sep-24 4:38
Martin Adams 202314-Sep-24 4:38 
AnswerRe: How to make a site visible to specific countries or region ? Pin
Hyper01116-Sep-24 2:13
Hyper01116-Sep-24 2:13 
GeneralRe: How to make a site visible to specific countries or region ? Pin
Martin Adams 202316-Sep-24 3:20
Martin Adams 202316-Sep-24 3:20 
QuestionBuilding a Web-based Code Editor Pin
Steve Raw13-Jul-24 11:31
professionalSteve Raw13-Jul-24 11:31 
I'm currently implementing a web-based code editor into my web project (Project Chromosphere.com). I think some of you might be interested. It's a work in progress, but you can see it here: https://chromosphere.com/chromosphere/scripts/js/ui/sandbox/vsCode/[^]

I considered creating a web-based code editor from scratch. Then, I realized the amount of time and effort to embark on such a thing would be ridiculous. I don't want to spend 1000 hours developing a web-based code editor. So, I'm going with a third-party solution.

Microsoft VS Code[^] offers a good solution. The VS Code code editors are powered by the Monaco Editor[^]. That's the code editor that you are actually embedding into your web page.

To implement this web-based code editor in its most basic form is easy.
See the HTML document source code below:

HTML
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Simple Example Code Editor</title>
</head>
<body>
    <div id="container" style="width: 100%; height: 95.5vh; border: 1px solid grey;"></div>
    <script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.27.0/min/vs/loader.js"></script>
    <script type="text/javascript">
        require.config({
            paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.27.0/min/vs" }
        });
        require(["vs/editor/editor.main"], function () {
            var editor = monaco.editor.create(document.getElementById("container"), {
                value: 'function hello() {\n    alert(\'Hello World!\');\n}',
                language: 'javascript'
            });

            monaco.editor.defineTheme("jScriptTheme", {
                base: 'vs-dark',
                inherit: true,
                rules: [
                    { token: '', foreground: 'aaaaaa' },
                    { token: 'invalid', foreground: 'ff3333' },
                    { token: 'emphasis', fontStyle: 'italic' },
                    { token: 'strong', fontStyle: 'bold' },
                    { token: 'variable', foreground: 'bbbbbb' },
                    { token: 'variable.predefined', foreground: 'eeeeee' },
                    { token: 'constant', foreground: 'f08c36' },
                    { token: 'comment', foreground: '00bb00', fontStyle: 'italic' },
                    { token: 'number', foreground: 'f08c36' },
                    { token: 'number.hex', foreground: 'f08c36' },
                    { token: 'regexp', foreground: '4dbf99' },
                    { token: 'annotation', foreground: '41a6d9' },
                    { token: 'type', foreground: '41a6d9' },
                    { token: 'delimiter', foreground: 'cceeff' },
                    { token: 'delimiter.html', foreground: '5c6773' },
                    { token: 'delimiter.xml', foreground: '5c6773' },
                    { token: 'tag', foreground: 'e7c547' },
                    { token: 'tag.id.jade', foreground: 'e7c547' },
                    { token: 'tag.class.jade', foreground: 'e7c547' },
                    { token: 'meta.scss', foreground: 'e7c547' },
                    { token: 'metatag', foreground: 'e7c547' },
                    { token: 'metatag.content.html', foreground: '86b300' },
                    { token: 'metatag.html', foreground: 'e7c547' },
                    { token: 'metatag.xml', foreground: 'e7c547' },
                    { token: 'metatag.php', fontStyle: 'bold' },
                    { token: 'key', foreground: '41a6d9' },
                    { token: 'string.key.json', foreground: '41a6d9' },
                    { token: 'string.value.json', foreground: '86b300' },
                    { token: 'attribute.name', foreground: 'f08c36' },
                    { token: 'attribute.value', foreground: '0451A5' },
                    { token: 'attribute.value.number', foreground: 'abb0b6' },
                    { token: 'attribute.value.unit', foreground: '86b300' },
                    { token: 'attribute.value.html', foreground: '86b300' },
                    { token: 'attribute.value.xml', foreground: '86b300' },
                    { token: 'string', foreground: 'd88bfc' },
                    { token: 'string.html', foreground: 'd88bfc' },
                    { token: 'string.sql', foreground: 'd88bfc' },
                    { token: 'string.yaml', foreground: 'd88bfc' }
                ],
                colors: {
                    'editor.background': '#000025'
                }
            });
            monaco.editor.setTheme("jScriptTheme");
        });
    </script>
</body>
</html>


Below is the HTML document source for my Configured JavaScript code editor[^].
See the HTML document source code below:

HTML
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Configured Example Code Editor</title>
</head>
<body>
    <div id="container" style="width: 100%; height: 95.5vh; border: 1px solid grey;"></div>
    <script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.27.0/min/vs/loader.js"></script>
    <script type="text/javascript">
        require.config({
            paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.27.0/min/vs" }
        });
        require(["vs/editor/editor.main"], function () {
            var container = document.getElementById("container");
            if (container !== null) {
                container.style.width = "calc(100% - 2px)";
                container.style.height = ((window.innerHeight) - 4) + "px";
                container.style.overflowY = "hidden";
                container.style.margin = "0";
                container.style.padding = "0";
                document.body.style.margin = "0";
                document.body.style.padding = "0";
            }
            var editor = monaco.editor.create(document.getElementById("container"), {
                value: "function hello(){\nalert('Hello world!');}",
                language: "javascript",
                theme: "vs-dark",
                "autoIndent": true,
                "formatOnPaste": true,
                "formatOnType": true,
                keywords: [
                    "break", "case", "catch", "class", "continue", "const",
                    "constructor", "debugger", "default", "delete", "do", "else",
                    "export", "extends", "false", "finally", "for", "from", "function",
                    "get", "if", "import", "in", "instanceof", "let", "new", "null",
                    "return", "set", "super", "switch", "symbol", "this", "throw", "true",
                    "try", "typeof", "undefined", "var", "void", "while", "with", "yield",
                    "async", "await", "of"
                ],

                typeKeywords: [
                    "any", "boolean", "number", "object", "string", "undefined"
                ],

                operators: [
                    "<=", ">=", "==", "!=", "===", "!==", "=>", "+", "-", "**",
                    "*", "/", "%", "++", "--", "<<", "</", ">>", ">>>", "&",
                    "|", "^", "!", "~", "&&", "||", "?", ":", "=", "+=", "-=",
                    "*=", "**=", "/=", "%=", "<<=", ">>=", ">>>=", "&=", "|=",
                    "^=", "@",
                ]
            });

            setTimeout(function () {
                editor.getAction('editor.action.formatDocument').run();
                //HTTP_POST_function(editor.getValue());
            }, 200);

            monaco.editor.defineTheme('jScriptTheme', {
                base: 'vs-dark',
                inherit: true,
                rules: [
                    { token: '', foreground: 'aaaaaa' },
                    { token: 'invalid', foreground: 'ff3333' },
                    { token: 'emphasis', fontStyle: 'italic' },
                    { token: 'strong', fontStyle: 'bold' },
                    { token: 'variable', foreground: 'bbbbbb' },
                    { token: 'variable.predefined', foreground: 'eeeeee' },
                    { token: 'constant', foreground: 'f08c36' },
                    { token: 'comment', foreground: '00bb00', fontStyle: 'italic' },
                    { token: 'number', foreground: 'f08c36' },
                    { token: 'number.hex', foreground: 'f08c36' },
                    { token: 'regexp', foreground: '4dbf99' },
                    { token: 'annotation', foreground: '41a6d9' },
                    { token: 'type', foreground: '41a6d9' },
                    { token: 'delimiter', foreground: 'cceeff' },
                    { token: 'delimiter.html', foreground: '5c6773' },
                    { token: 'delimiter.xml', foreground: '5c6773' },
                    { token: 'tag', foreground: 'e7c547' },
                    { token: 'tag.id.jade', foreground: 'e7c547' },
                    { token: 'tag.class.jade', foreground: 'e7c547' },
                    { token: 'meta.scss', foreground: 'e7c547' },
                    { token: 'metatag', foreground: 'e7c547' },
                    { token: 'metatag.content.html', foreground: '86b300' },
                    { token: 'metatag.html', foreground: 'e7c547' },
                    { token: 'metatag.xml', foreground: 'e7c547' },
                    { token: 'metatag.php', fontStyle: 'bold' },
                    { token: 'key', foreground: '41a6d9' },
                    { token: 'string.key.json', foreground: '41a6d9' },
                    { token: 'string.value.json', foreground: '86b300' },
                    { token: 'attribute.name', foreground: 'f08c36' },
                    { token: 'attribute.value', foreground: '0451A5' },
                    { token: 'attribute.value.number', foreground: 'abb0b6' },
                    { token: 'attribute.value.unit', foreground: '86b300' },
                    { token: 'attribute.value.html', foreground: '86b300' },
                    { token: 'attribute.value.xml', foreground: '86b300' },
                    { token: 'string', foreground: 'd88bfc' },
                    { token: 'string.html', foreground: 'd88bfc' },
                    { token: 'string.sql', foreground: 'd88bfc' },
                    { token: 'string.yaml', foreground: 'd88bfc' }
                    /*
                    { token: 'keyword', foreground: 'f2590c' },
                    { token: 'keyword.json', foreground: 'f2590c' },
                    { token: 'keyword.flow', foreground: 'f2590c' },
                    { token: 'keyword.flow.scss', foreground: 'f2590c' },
                    { token: 'operator.scss', foreground: '666666' },
                    { token: 'operator.sql', foreground: '778899' },
                    { token: 'operator.swift', foreground: '666666' },
                    { token: 'predefined.sql', foreground: 'FF00FF' },
                    */
                ],
                colors: {
                    'editor.background': '#000025',
                    /*
                    'editor.foreground': '#5c6773',
                    'editorIndentGuide.background': '#ecebec',
                    'editorIndentGuide.activeBackground': '#e0e0e0',
                    */
                }
            });
            monaco.editor.setTheme('jScriptTheme');
        }); 
    </script>  
</body>
</html>

SuggestionRe: Building a Web-based Code Editor Pin
Richard Deeming14-Jul-24 21:44
mveRichard Deeming14-Jul-24 21:44 
QuestionCreating a Synthetic Mouse Event: Event Sequence? Pin
Steve Raw13-Jul-24 9:12
professionalSteve Raw13-Jul-24 9:12 
AnswerRe: Creating a Synthetic Mouse Event: Event Sequence? Pin
Richard Deeming14-Jul-24 21:42
mveRichard Deeming14-Jul-24 21:42 
AnswerRe: Creating a Synthetic Mouse Event: Event Sequence? Pin
Jeremy Falcon17-Jul-24 16:32
professionalJeremy Falcon17-Jul-24 16:32 
Questionfullcalendar with resourcetimeline laravel php Pin
mohammed naseralla27-Jun-24 0:43
mohammed naseralla27-Jun-24 0:43 
QuestionCan you use ApiKey and JWT in the same web API Pin
Mycroft Holmes24-Jun-24 15:29
professionalMycroft Holmes24-Jun-24 15:29 
QuestionDo I need Open API when using Azure Pin
Mycroft Holmes12-Jun-24 16:06
professionalMycroft Holmes12-Jun-24 16:06 
QuestionOpinions of WIX Pin
DerekT-P11-Jun-24 9:19
professionalDerekT-P11-Jun-24 9:19 
AnswerRe: Opinions of WIX Pin
Richard Deeming11-Jun-24 21:44
mveRichard Deeming11-Jun-24 21:44 
GeneralRe: Opinions of WIX Pin
Jeremy Falcon23-Jul-24 13:09
professionalJeremy Falcon23-Jul-24 13:09 
AnswerRe: Opinions of WIX Pin
Steve Raw17-Jun-24 14:52
professionalSteve Raw17-Jun-24 14:52 
GeneralRe: Opinions of WIX Pin
Jeremy Falcon23-Jul-24 13:07
professionalJeremy Falcon23-Jul-24 13:07 
AnswerRe: Opinions of WIX Pin
Jeremy Falcon23-Jul-24 13:06
professionalJeremy Falcon23-Jul-24 13:06 
QuestionConfiguration Error Pin
Richard Andrew x6415-May-24 10:32
professionalRichard Andrew x6415-May-24 10:32 
AnswerRe: Configuration Error Pin
Richard Deeming15-May-24 21:43
mveRichard Deeming15-May-24 21:43 
GeneralRe: Configuration Error Pin
Richard Andrew x6416-May-24 3:27
professionalRichard Andrew x6416-May-24 3:27 
QuestionIdentity Management Recommendations Pin
Richard Andrew x6414-May-24 3:45
professionalRichard Andrew x6414-May-24 3:45 
AnswerRe: Identity Management Recommendations Pin
Richard Deeming14-May-24 3:51
mveRichard Deeming14-May-24 3:51 
GeneralRe: Identity Management Recommendations Pin
Richard Andrew x6414-May-24 4:32
professionalRichard Andrew x6414-May-24 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.