본문으로 건너뛰기Skip to content
예제 첫화면Examples home

HTML 렌더러: 서식은 살리고 위험은 지우기HTML renderer: keep the markup, drop the danger

값에 든 굵게·목록 같은 서식은 그리고, 스크립트와 이벤트 속성은 지워서 글자로 안전하게 보여요.Draw markup such as bold text and lists in the value, and remove scripts and event attributes so the text is safe.

활용Intermediate
직접 써 보기Live previewHTML 렌더러: 서식은 살리고 위험은 지우기HTML renderer: keep the markup, drop the danger

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div id="grid" style="height: 300px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
const en = document.documentElement.dataset.lang === 'en';
const rows = [
  {
    id: 1,
    title: en ? 'Formatting' : '서식 글자',
    note: en
      ? '<b>bold</b>, <i>italic</i>, <mark>mark</mark>, <code>code</code>'
      : '<b>굵게</b>, <i>기울임</i>, <mark>강조</mark>, <code>code</code>',
  },
  {
    id: 2,
    title: en ? 'List' : '목록',
    note: en ? '<ul><li>one</li><li>two</li></ul>' : '<ul><li>하나</li><li>둘</li></ul>',
  },
  {
    id: 3,
    title: en ? 'Unsafe value 1' : '위험한 값 1',
    note: en
      ? '<img src=x onerror="alert(1)">The image is removed'
      : '<img src=x onerror="alert(1)">그림은 지워져요',
  },
  {
    id: 4,
    title: en ? 'Unsafe value 2' : '위험한 값 2',
    note: '<script>alert(2)<' +
      '/script><b onclick="alert(3)">' +
      (en ? 'attributes are removed' : '속성은 지워져요') +
      '</b>',
  },
  { id: 5, title: en ? 'Text only' : '글자만', note: 'a < b && c > d' },
];
export const options = {
  columns: [
    { id: 'title', title: en ? 'Kind' : '구분', width: 140 },
    { id: 'note', title: en ? 'Content (HTML)' : '내용 (HTML)', width: 420, cellRenderer: 'html' },
  ],
  rows,
  rowKey: 'id',
  ariaLabel: en ? 'HTML renderer' : 'HTML 렌더러',
  saveMode: 'none',
};
export function setup(_api, log) {
  log({
    ko: '3·4행의 스크립트와 이벤트 속성은 그려지지 않아요(경고창이 뜨지 않아요).',
    en: 'The script and event attributes in rows 3 and 4 are not drawn (no alert appears).',
  });
}

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div id="grid" style="height: 300px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
const rows = [
  {
    id: 1,
    title: 'Formatting',
    note: '<b>bold</b>, <i>italic</i>, <mark>mark</mark>, <code>code</code>',
  },
  {
    id: 2,
    title: 'List',
    note: '<ul><li>one</li><li>two</li></ul>',
  },
  {
    id: 3,
    title: 'Unsafe value 1',
    note: '<img src=x onerror="alert(1)">The image is removed',
  },
  {
    id: 4,
    title: 'Unsafe value 2',
    note: '<script>alert(2)<' + '/script><b onclick="alert(3)">' + 'attributes are removed' + '</b>',
  },
  { id: 5, title: 'Text only', note: 'a < b && c > d' },
];
export const options = {
  columns: [
    { id: 'title', title: 'Kind', width: 140 },
    { id: 'note', title: 'Content (HTML)', width: 420, cellRenderer: 'html' },
  ],
  rows,
  rowKey: 'id',
  ariaLabel: 'HTML renderer',
  saveMode: 'none',
};
export function setup(_api, log) {
  log('The script and event attributes in rows 3 and 4 are not drawn (no alert appears).');
}