본문으로 건너뛰기

DocumentProcessor

Markdown / HTML 렌더링, RichEditor 보안 정화, 문서 메타 처리

상태

항목
Layerfoundation
TierL0
Statuswip
Version0.9.0
가격Free (free)
**카�
�고리**Content

개요

개요

DocumentProcessor 는 multi-saas-kit 의 Layer 0 Foundation Plugin � 니다. 여러 프로젝트(academy.how, exam.how, edutech.how 등)에서 공통으로 필요한 문서 저장과 변환 기능을 제공합니다.

주요 기능

1. Markdown → HTML 변환

  • league/commonmark v2.8 기반
  • GitHub Flavored Markdown(GFM) 지원
  • inline HTML 보존 (AI 추출본 호환)
  • javascript: / data: URL 등 unsafe link 자동 차단

2. HTML 섹�

� 추출 + Anchor 보강

  • DOMDocument 기반 p / h1~h6 / li � �드에 unique id 자동 부여
  • 댓글/메모/번역의 위치 기준점 (data-anchor)
  • 기존 id 보존 (사용자/추출 단계 anchor 유지)
  • 후처리 callback 옵� � (예: SVG camelCase 속성 복원)

3. RichEditor HTML Sanitizer

  • TipTap / Trix 출력 보안 정화
  • 화이트리스트 기반 태그/속성/style/class
  • 위험 태그 14� (script/style/iframe/object/embed/form/input 등) 자식 포함 통째 제거
  • on event handler 자동 제거
  • 외부 링크에 rel=noopener / target=_blank 자동 부여
  • 프로젝트별 확장: extra_allowed_tags, extra_global_attrs, extra_class_patterns, dynamic_class_resolver

4. polymorphic Document 저장소

  • plg_documents � �이블에 MD/HTML 본문 저장
  • documentable_type 으로 어떤 모델이든 owner 가능 (Lesson, Page, Question, Article 등)
  • 자동 versioning (v1 active → v2 생성 시 v1 deactivate)
  • derived_from 으로 MD → HTML 파생 추적
  • saas_product_id / tenant_id 격리 컬럼

사용 예시

use App\Plugins\DocumentProcessor\Services\MarkdownRenderer;
use App\Plugins\DocumentProcessor\Services\HtmlSectionExtractor;
use App\Plugins\DocumentProcessor\Services\RichEditorSanitizer;
use App\Plugins\DocumentProcessor\Services\DocumentRepository;
use App\Plugins\DocumentProcessor\Enums\DocumentFormat;

// MD → HTML
$html = app(MarkdownRenderer::class)->render($markdown);

// Anchor 보강 + sections 추출
[$enriched, $sections] = app(HtmlSectionExtractor::class)->annotate($html);

// Sanitize
$safe = app(RichEditorSanitizer::class)->sanitize($userHtml);

// Document 저장 (lesson 은 DocumentableInterface 구현)
$repo = app(DocumentRepository::class);
$doc = $repo->upsertMarkdown($lesson, $markdown);
$htmlDoc = $repo->upsertHtml($lesson, $html, derivedFrom: $doc);

// 활성 본 조회
$active = $repo->findActiveFor($lesson, DocumentFormat::HTML);

모델에 DocumentableInterface 구현

use App\Plugins\DocumentProcessor\Contracts\DocumentableInterface;

class Lesson extends Model implements DocumentableInterface
{
public function getSaasProductId(): ?int { return $this->saas_product_id; }
public function getTenantId(): ?int { return $this->tenant_id; }
// getMorphClass(), getKey() 는 Eloquent Model 기본 제공
}

다른 Plugin 과의 관계

다음 Plugin 들이 DocumentProcessor 에 의존합니다:

  • Annotation — 학습자 주석 (data-anchor 활용)
  • Reader — 학습자용 웹북 뷰어
  • StagePipeline — AI 콘� �츠 생성 파이프라인
  • AiSvg — AI SVG 시각 자산 생성

출처

academy.how 의 app/Modules/Content/Services/HtmlRenderer.php (796줄) 중 순수 변환 로직을 추출. Lesson 특화 메서드(renderForLesson / patchIllustrationsForLesson / injectTipsIntoHtml) 는 academy 잔류, Plugin Service 에 위임.

라이선스

MIT

데모


🛒 Plugin Store에서 보기: store.codebase.how/plugins/document-processor