분류, 패키지 및 저장소 검색

패키지 상세v1.0.0+1

html_character_entities

HTML 4.01의 모든 문자 엔티티(ASCII 및 16진수 코드 포함)의 맵과 이러한 문자 엔티티로 문자열을 인코딩/디코딩하는 메서드를 포함하는 유틸리티 클래스입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
43
좋아요
21
Pub 점수
150

패키지 설치

flutter pub add html_character_entities

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

HTML 4.01 문자 엔티티의 포괄적인 매핑(ASCII 및 16진수 코드 포함)을 제공하는 Flutter/Dart 유틸리티 패키지입니다. 이러한 엔티티를 사용하여 문자열을 인코딩하고 디코딩할 수 있는 메서드를 제공하며, 웹 콘텐츠에서 특수 문자를 정확하게 처리할 수 있도록 보장합니다. 문자 인코딩 정밀도가 중요한 HTML 텍스트 처리, 렌더링 또는 데이터 교환 작업에 종사하는 개발자에게 이상적입니다. 이 패키지는 모든 주요 플랫폼을 지원하며 명확한 소스 코드 접근이 가능하도록 유지 관리됩니다.

사용 사례

  • 특수 문자를 포함한 HTML 콘텐츠 렌더링
  • 일반 텍스트와 인코딩된 형식 간의 텍스트 변환
  • 레거시 HTML 데이터 처리
  • 웹 출력을 위한 사용자 입력 정제
  • 텍스트 내보내기에서 서식 유지

주요 기능

  • 완전한 HTML 4.01 엔티티 매핑
  • ASCII 및 16진수 코드 지원
  • 문자열 인코딩/디코딩 유틸리티
  • 크로스 플랫폼 호환성
  • 오픈소스이며 잘 문서화되어 있습니다
  • pub를 통한 간편한 통합

적합한 대상

  • Flutter를 사용하는 웹 개발자
  • 콘텐츠 렌더링 애플리케이션
  • 텍스트 처리 도구
  • 레거시 시스템 통합
  • HTML 인코딩에 관한 교육 프로젝트

고려 사항

  • HTML 4.01 기준에 제한됨
  • HTML5 전용 엔티티에 대한 지원 없음
  • 손으로 잘못된 입력을 처리해야 합니다
  • 고주파 인코딩 시나리오에 최적화되지 않음
  • 외부에서 엔티티 목록을 유지 관리하는 데 의존

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

html_character_entities

A Dart utility class containing maps of key/value pairs for every HTML 4.01 character entity, including ASCII and hex codes, and methods to encode and decode strings to and from those character entities.

Usage

import 'package:html_character_entities/html_character_entities.dart';

Decoding Strings

The decode method accepts a string as an argument and returns it after replacing every character entity with their corresponding characters.

String string = 'An ampersand can be written as & and &.';

print(HtmlCharacterEntities.decode(string)); // An ampersand can be written as & and &.

Encoding Strings

The encode() method has an argument, [characters], that accepts a string of all characters that should be encoded. It defaults to the 5 reserved characters in both HTML and XML: less-than (<), greater-than (>), ampersand (&), apostrophe or single quote ('), and double-quote (").

String string = '<, >, &, \', and " aren\'t safe to use in HTML and XML.';

print(HtmlCharacterEntities.encode(string));
// &lt;, &gt;, &amp;, &apos;, and &quot; aren&apos;t safe to use in HTML and XML.

print(HtmlCharacterEntities.encode(string, characters: 'XHTML'));
// <, >, &, ', and " aren't safe to use in &#72;&#84;&#77;&#76; and &#88;&#77;&#76;.

If [characters] is null, every character in the HtmlCharacterEntities.characters map will be encoded.

Maps

A map of every HTML 4.01 character code, as well as their ASCII and hex code entities can be referenced from HtmlCharacterEntities.characters.

Note: The hex codes in the map don't have leading 0s. I.e. the hex code &#x0000a5; is in the map as &#xa5;. When decoding hex code entities, the leading 0s will be removed by the parser before being looked up.

Map<String, String> c = HtmlCharacterEntities.characters;

String string = 'There are 4 suites of cards: ${c['&spades;']} Spades, ${c['&clubs;']} Clubs, ${c['&hearts;']} Hearts, ${c['&diams;']} Diamonds';

print(string); // There are 4 suites of cards: ♠ Spades, ♣ Clubs, ♥ Hearts, ♦ Diamonds

Maps containing the characters with their respective character codes as values can also be referenced. They are used by the encode method.

// A map with only ASCII code character entities as values.
Map<String, String> ascii = HtmlCharacterEntities.asciiCodes;

// A map with all non-ASCII code character entities as values.
Map<String, String> entity = HtmlCharacterEntities.entities;

String string = '< and > exist as both ASCII codes (${ascii['<']} and ${ascii['>']}) and character entities (${entity['<']} and ${entity['>']}).';

print(string); // < and > exist as both ASCII codes (&#60; and &#62;) and character entities (&lt; and &gt;).

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트