Coder Social home page Coder Social logo

crissium / python-dsl Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 32 KB

Python module for converting DSL dictionary texts into HTML

Home Page: https://pypi.org/project/dsl2html/

License: GNU General Public License v3.0

C++ 98.99% Python 1.01%
dsl lingvo lingvodsl

python-dsl's Introduction

Description

A Python package to convert DSL into HTML, written in modern C++.

The part that parses DSL into a DOM tree comes from GoldenDict-ng, and I have made a number of changes:

  • Use 8-bit std::string throughout.
  • Use standard library equivalents of Qt classes/functions.
  • Use functional programming wherever appropriate.
  • Some tags are ignored. And some other adjustments.

The part that converts the DOM tree into HTML is written by me, under influence from both pyglossary and GoldenDict-ng. Any bug here is mine :)

Installation

pip install dsl2html

Building

python3 setup.py build

Needless to say, you should have the development package of Python installed. Nothing other than Python.h is needed. Your compiler should support C++11, though.

Usage

>>> import dsl
>>> dsl.to_html(''' [m0][b]com·mu·ta·tor[/b] [p]7[/p] {{id=000008943}} [c rosybrown]\[[/c][c darkslategray][b]commutator[/b][/c] [c darkslategray][b]commutators[/b][/c][c rosybrown]\][/c] [p]BrE[/p] [c darkgray] [/c][c darkcyan]\[ˈkɒmjuteɪtə(r)\][/c] [s]z_commutator__gb_1.wav[/s] [p]NAmE[/p] [c darkgray] [/c][c darkcyan]\[ˈkɑːmjuteɪtər\][/c] [s]z_commutator__us_1.wav[/s] [c orange] noun[/c] [c darkgray] ([/c][c green]physics[/c][c darkgray])[/c]
...  [m1][c darkmagenta][b]1.[/b][/c] {{d}}a device that connects a motor to the electricity supply{{/d}}
...  [m1][c darkmagenta][b]2.[/b][/c] {{d}}a device for changing the direction in which electricity flows{{/d}}''', 'test')
(' <div style="margin-left: 0px;"><b>com·mu·ta·tor</b> <i><font color="green">7</font></i>  <span style="color: rosybrown;">[</span><span style="color: darkslategray;"><b>commutator</b></span> <span style="color: darkslategray;"><b>commutators</b></span><span style="color: rosybrown;">]</span> <i><font color="green">BrE</font></i> <span style="color: darkgray;"> </span><span style="color: darkcyan;">[ˈkɒmjuteɪtə(r)]</span> <audio controls autoplay src="/api/cache/test/z_commutator__gb_1.wav">z_commutator__gb_1.wav</audio> <i><font color="green">NAmE</font></i> <span style="color: darkgray;"> </span><span style="color: darkcyan;">[ˈkɑːmjuteɪtər]</span> <audio controls src="/api/cache/test/z_commutator__us_1.wav">z_commutator__us_1.wav</audio> <span style="color: orange;"> noun</span> <span style="color: darkgray;"> (</span><span style="color: green;">physics</span><span style="color: darkgray;">)</span> </div><div style="margin-left: 9px;"><span style="color: darkmagenta;"><b>1.</b></span> a device that connects a motor to the electricity supply </div><div style="margin-left: 9px;"><span style="color: darkmagenta;"><b>2.</b></span> a device for changing the direction in which electricity flows</div>', ['z_commutator__gb_1.wav', 'z_commutator__us_1.wav'])

The module has only one function: to_html, which takes two arguments: the DSL string and the dictionary name, and returns a tuple of two elements: the HTML string and a list of media file names.

python-dsl's People

Contributors

crissium avatar

Stargazers

 avatar

Watchers

 avatar

python-dsl's Issues

Modul don't work

Hi, how does the module work?
I stole the code: git clone ... ; cd...
Then: pip install dsl2html ; python3 setup.py build
And what else ?
My virtual environment "myenv", does not contain the executable "dsl2html"

.../myenv
├── bin
│   ├── Activate.ps1
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── pip
│   ├── pip3
│   ├── pip3.12
│   ├── pyglossary
│   ├── python -> python3.12
│   ├── python3 -> python3.12
│   └── python3.12 -> /usr/local/opt/[email protected]/bin/python3.12
├── include
│   ├── python3.12
│   │   └── Python.h
│   └── site
│   └── python3.12
│   └── pygobject
│   └── pygobject-3.0
│   └── pygobject.h
├── lib
│   └── python3.12
│   └── site-packages
│   ├── PyICU-2.13.1.dist-info
│   │  
│   ├── _distutils_hack
│   │  
│   ├── cairo
│   │  
│   ├── distutils-precedence.pth
│   ├── dsl.cpython-312-darwin.so
│   ├── dsl2html-0.1.5.dist-info
│   │   ├── INSTALLER
│   │   ├── LICENSE.txt
│   │   ├── METADATA
│   │   ├── RECORD
│   │   ├── REQUESTED
│   │   ├── WHEEL
│   │   └── top_level.txt
│   ├── gi
│   │ 
│   ├── icu
│   │  
│   ├── pip
│   │  
│   ├── pip-24.1.dist-info
│   │  
│   ├── pkg_resources
│   │  
│   ├── pycairo-1.26.0.dist-info
│   │  
│   ├── pyglossary-4.6.1.dist-info
│   │  
│   ├── pygobject-3.48.2.dist-info
│   │  
│   ├── pygtkcompat
│   │  
│   ├── setuptools
│  
├── pyvenv.cfg
└── share
└── pyglossary
├── AUTHORS
├── about
├── config.json
├── help
├── license-dialog
├── license.txt
├── plugins-meta
│   └── index.json
└── res
├── author-22.png
├── dialog-information-22.png
├── license-22.png
├── pyglossary.ico
├── pyglossary.png
├── pyglossary.svg
├── resize-16.png
├── resize.png
└── resources.xml

245 directories, 1819 files

What is the next step? Please

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.