코드 블럭 삽입 기능을 이용해 문서에 코드를 삽입해 보세요.

체험하기

<!-- Synap Editor -->
<script src='/se/resource/synapeditor/synapeditor.config.js'></script>
<script src='/se/resource/synapeditor/synapeditor.min.js'></script>
<link href='/se/resource/synapeditor/synapeditor.min.css' rel='stylesheet' type='text/css'>

<!-- plugins -->
<script src="/se/resource/synapeditor/plugins/codeBlockHighlighter/codeBlockHighlighter.min.js"></script>

<div style="background-color: #ffffff; width:99%; height:500px;">
        <div id="synapEditor">
			<pre class="se-code-block"><code class="hljs"><span class="hljs-keyword">function</span> <span class="hljs-title function_">foo</span>(<span class="hljs-params"></span>) {
    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">"HI"</span>);
}</code></pre>
<p style="margin: 16px 0px; display: block; overflow-wrap: break-word;">코드 하이라이트가 적용된 코드를 보려면 미리보기 버튼을 클릭해 주세요.<br></p>
<p><button id="toggleThemeBtn">코드 테마 변경</button></p>
</div>
<script>
    const LIGHT_THEME = '/se/resource/synapeditor/plugins/codeBlockHighlighter/themes/atom-one-light.min.css';
    const DARK_THEME  = '/se/resource/synapeditor/plugins/codeBlockHighlighter/themes/atom-one-dark.min.css';

    let isLightTheme = true;

    const config = Object.assign(synapEditorConfig, {
        "editor.license": "/se/resource/license.json",
        "editor.toolbar": [
            "new", "|",
            "codeBlock",
            "preview"
        ],
        "editor.menu.show": false,
        "editor.preview.style.urls": [LIGHT_THEME]
    });

    window.editor = new SynapEditor(
        "synapEditor",
        config,
        document.getElementById('synapEditor').innerHTML
    );

    document.getElementById('toggleThemeBtn').addEventListener('click', () => {
        isLightTheme = !isLightTheme;

        const themeUrl = isLightTheme ? LIGHT_THEME : DARK_THEME;

        // preview용 스타일 교체
        editor.setConfig('editor.preview.style.urls', [themeUrl]);

        // preview가 열려 있다면 다시 렌더링
        if (editor.isPreviewMode && editor.isPreviewMode()) {
            editor.togglePreview();
            editor.togglePreview();
        }
    });
</script>