Skip to main content

Convert Apple Dictionary HTML `<span>`s into semantic, readable HTML. Removes the dependency on CSS styles by converting span class names into appropriate semantic HTML tags and structural markup.

Project description

appledict2semantic

appledict2semantic is a Python tool to convert Apple Dictionary HTML files into clean, semantic HTML. It removes the dependency on the custom CSS by mapping span class names to appropriate semantic HTML tags and structural markup, making the output more readable and portable.

Screenshots

Before conversion:

Before conversion

After conversion:

After conversion

Features

  • Span-to-semantic conversion: Converts Apple Dictionary’s <span class="..."> elements into semantic HTML tags like <strong>, <em>, <u>, and more.
  • Structural transformation: Transforms sense and subsense blocks into nested lists <ul>, <li> for better readability.
  • Block conversion: Converts etymology, derivatives, and usage note blocks into more meaningful HTML structures. This paves way for further processing, e.g. to convert to Markdown.
  • Cleanup: Removes unnecessary or empty tags, and replaces bullet spans with proper list items.
  • Batch processing: Supports processing single files or entire folders, with optional in-place replacement.

Installation

Make sure that you have Python 3.10 or higher installed.

Then install the package from PyPI:

pip install appledict2semantic

Obtain and extract Apple Dictionary HTML files

How to obtain

To obtain the Apple Dictionary, first you need to have a macOS.

Then, open the Dictionary app, select Dictionary > Settings. Choose the sources you want to download.

The dictionary files are stored in /System/Library/AssetsV2/com_apple_MobileAsset_DictionaryServices_dictionaryOSX.

How to extract

Install pyglossary:

pip install pyglossary

Then use pyglossary to point to the Body.data file, and convert to AppleDict Source. This will produces a XML file.

From there, use this script to extract the XML file to HTML files.

Usage

  • Converts a single Apple Dictionary HTML file to semantic HTML:

    appledict2semantic --single input.html output.html
    
  • Processes all .html files in input_folder, saving results to output_folder:

    appledict2semantic --multiple input_folder output_folder
    
  • Processes all .html files in input_folder, replacing the original files:

    appledict2semantic --multiple input_folder --replace
    

    You will need to confirm the action.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

appledict2semantic-1.2.0.tar.gz (326.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

appledict2semantic-1.2.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file appledict2semantic-1.2.0.tar.gz.

File metadata

  • Download URL: appledict2semantic-1.2.0.tar.gz
  • Upload date:
  • Size: 326.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for appledict2semantic-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7457aa0d314a52b0df67c6051935f45439984f41126422bc7170ba045da45728
MD5 0a5351411ae250bd08a31e9b73040e7f
BLAKE2b-256 fe4e91b3b93e53f21fb02562f872f4d4ee4717c84f10a4d932ff3f57fd6ab5c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for appledict2semantic-1.2.0.tar.gz:

Publisher: build.yaml on yell0wsuit/appledict2semantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file appledict2semantic-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for appledict2semantic-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bea298cc5d70af796fa3a13e8a81d98973f4a8800b4c29170954dfd5f1f05f5
MD5 3e5d24250a45f903bcafcc053022413f
BLAKE2b-256 158266d8509efe3ccefcd7d7f68c19d15a189f8a8929d4faa754c42aa7cdfd91

See more details on using hashes here.

Provenance

The following attestation bundles were made for appledict2semantic-1.2.0-py3-none-any.whl:

Publisher: build.yaml on yell0wsuit/appledict2semantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page