カテゴリー・パッケージ・リポジトリを検索

パッケージ詳細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コンテンツのレンダリング
  • プレーン形式とエンコード形式の間でテキストを変換する
  • レガシーハイパーテキストマークアップ言語データの処理
  • Web出力用のユーザー入力をサニタイズする
  • テキストエクスポートでのフォーマットの保持

主な機能

  • 完全な 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;).

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト