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

HTML 렌더러: 허용되는 링크 주소HTML renderer: allowed link addresses

https·mailto·상대 주소만 링크로 남기고 javascript:·data: 주소는 글자만 남기는 규칙을 보여요. allowTags로 허용 태그를 좁혀요.See how only https, mailto and relative addresses stay links while javascript: and data: addresses keep only their text. allowTags narrows the allowed tags.

활용Intermediate
직접 써 보기Live previewHTML 렌더러: 허용되는 링크 주소HTML renderer: allowed link addresses

코드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,
    label: 'https',
    html: en
      ? '<a href="https://example.com/docs">Docs</a>'
      : '<a href="https://example.com/docs">문서</a>',
  },
  {
    id: 2,
    label: 'mailto',
    html: en
      ? '<a href="mailto:help@example.com">Contact us</a>'
      : '<a href="mailto:help@example.com">문의하기</a>',
  },
  {
    id: 3,
    label: en ? 'Relative URL' : '상대 주소',
    html: en ? '<a href="/pricing">Pricing</a>' : '<a href="/pricing">가격</a>',
  },
  {
    id: 4,
    label: 'javascript:',
    html: en
      ? '<a href="javascript:alert(1)">Not a link</a>'
      : '<a href="javascript:alert(1)">링크가 아니에요</a>',
  },
  {
    id: 5,
    label: 'data:',
    html: en
      ? '<a href="data:text/html,<b>x</b>">Not a link</a>'
      : '<a href="data:text/html,<b>x</b>">링크가 아니에요</a>',
  },
];
export const options = {
  columns: [
    { id: 'label', title: en ? 'URL kind' : '주소 종류', width: 140 },
    {
      id: 'html',
      title: en ? 'Result' : '결과',
      width: 320,
      cellRenderer: 'html',
      cellRendererParams: { allowTags: ['a', 'b'] },
    },
  ],
  rows,
  rowKey: 'id',
  ariaLabel: en ? 'HTML links' : 'HTML 링크',
  saveMode: 'none',
};
export function setup(_api, log) {
  log({
    ko: 'https·mailto·상대 주소만 링크로 남고, 링크는 새 창 대신 안전한 rel이 붙어요.',
    en: 'Only https, mailto and relative addresses stay links, and every link gets a safe rel.',
  });
}

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, label: 'https', html: '<a href="https://example.com/docs">Docs</a>' },
  { id: 2, label: 'mailto', html: '<a href="mailto:help@example.com">Contact us</a>' },
  { id: 3, label: 'Relative URL', html: '<a href="/pricing">Pricing</a>' },
  { id: 4, label: 'javascript:', html: '<a href="javascript:alert(1)">Not a link</a>' },
  { id: 5, label: 'data:', html: '<a href="data:text/html,<b>x</b>">Not a link</a>' },
];
export const options = {
  columns: [
    { id: 'label', title: 'URL kind', width: 140 },
    {
      id: 'html',
      title: 'Result',
      width: 320,
      cellRenderer: 'html',
      cellRendererParams: { allowTags: ['a', 'b'] },
    },
  ],
  rows,
  rowKey: 'id',
  ariaLabel: 'HTML links',
  saveMode: 'none',
};
export function setup(_api, log) {
  log('Only https, mailto and relative addresses stay links, and every link gets a safe rel.');
}